Skip to content

Commit

Permalink
made the unterminated string error to use initial string linecol inst…
Browse files Browse the repository at this point in the history
…ead of ending linecol
  • Loading branch information
nulluser0 committed Jun 18, 2024
1 parent 106aae5 commit 3ce890f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub enum LexerError {
col: usize,
},

#[error("Unterminated string literal at {line}:{col}")]
#[error("Unterminated string literal at string beginning at {line}:{col}")]
UnterminatedStringLiteral { line: usize, col: usize },

#[error("Unexpected end of file at {line}:{col}")]
Expand Down
7 changes: 5 additions & 2 deletions src/frontend/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,12 +451,15 @@ fn tokenize_string_literal(
chars: &mut CharStream,
tokens: &mut Vec<Token>,
) -> Result<(), LexerError> {
let start_line = chars.line;
let start_col = chars.col;
chars.next(); // Consume the initial quote
let mut literal = String::new();
while let Some(&ch) = chars.peek() {
match ch {
'"' => {
chars.next(); // Consume the closing quote

tokens.push(Token::StringLiteral(literal));
return Ok(());
}
Expand All @@ -481,7 +484,7 @@ fn tokenize_string_literal(
}
}
Err(LexerError::UnterminatedStringLiteral {
line: chars.line,
col: chars.col,
line: start_line,
col: start_col,
})
}

0 comments on commit 3ce890f

Please sign in to comment.