Skip to content

Commit

Permalink
asm: Add docs to source position struct
Browse files Browse the repository at this point in the history
  • Loading branch information
Granddave committed Jul 7, 2024
1 parent 3e31ac2 commit 2068728
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/assembler/lexer/source_position.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use std::fmt;

/// Represents a position in the source code.
///
/// The line and column are 1-based.
#[derive(Debug, Copy, Clone, PartialEq)]
pub struct SourcePosition {
pub line: usize,
Expand Down Expand Up @@ -29,10 +32,13 @@ impl Default for SourcePosition {

impl fmt::Display for SourcePosition {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}:{}", self.line, self.column)
write!(f, "[{}, {}]", self.line, self.column)
}
}

/// Represents a span of positions in the source code.
///
/// The start position is inclusive, while the end position is exclusive.
#[derive(Debug, Copy, Clone, PartialEq, Default)]
pub struct SourcePositionSpan {
pub start: SourcePosition,
Expand Down

0 comments on commit 2068728

Please sign in to comment.