Skip to content

Commit

Permalink
Lexer: add line number tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
Ernest1338 committed Jan 25, 2025
1 parent b20b147 commit 5450ad4
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ pub fn preprocess(code: &str) -> String {
/// Converts input text into a vector of tokens
pub fn lexer(input: &str) -> Result<Vec<Token>, ErrorType> {
let mut tokens = Vec::new();
for line in input.lines() {
for (line_nr, line) in input.lines().enumerate() {
let mut remaining = line.trim();
while !remaining.is_empty() {
match Token::from_str(remaining) {
Expand All @@ -194,7 +194,7 @@ pub fn lexer(input: &str) -> Result<Vec<Token>, ErrorType> {
Err(_) => {
return Err(ErrorType::SyntaxError(ErrorInner {
message: format!("Unexpected token: {remaining}"),
line_number: None,
line_number: Some(line_nr + 1),
}))
}
}
Expand Down

0 comments on commit 5450ad4

Please sign in to comment.