Skip to content

Commit

Permalink
Add SrcPos to parsing.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
maximecb committed Nov 16, 2023
1 parent f67d1f8 commit b392a06
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion ncc/src/parsing.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
use std::fs;
use std::fmt;

#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, Default, Eq, PartialEq, Hash)]
pub struct SrcPos
{
line_no: u32,
col_no: u32,
file_id: u32,
}

impl fmt::Display for SrcPos
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// TODO: map file id to file name
write!(f, "{}:{}", self.line_no, self.col_no)
}
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -109,6 +118,15 @@ impl Input
}
}

pub fn get_pos(&self) -> SrcPos
{
SrcPos {
line_no: self.line_no,
col_no: self.col_no,
file_id: 0
}
}

/// Test if the end of the input has been reached
pub fn eof(&self) -> bool
{
Expand Down

0 comments on commit b392a06

Please sign in to comment.