From 3ce890f0d61941b319d1607a6391215e93eb80e3 Mon Sep 17 00:00:00 2001 From: nulluser0 Date: Tue, 18 Jun 2024 18:54:12 +1000 Subject: [PATCH] made the unterminated string error to use initial string linecol instead of ending linecol --- src/errors.rs | 2 +- src/frontend/lexer.rs | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/errors.rs b/src/errors.rs index cb17169..de84673 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -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}")] diff --git a/src/frontend/lexer.rs b/src/frontend/lexer.rs index 8854c57..d753243 100644 --- a/src/frontend/lexer.rs +++ b/src/frontend/lexer.rs @@ -451,12 +451,15 @@ fn tokenize_string_literal( chars: &mut CharStream, tokens: &mut Vec, ) -> 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(()); } @@ -481,7 +484,7 @@ fn tokenize_string_literal( } } Err(LexerError::UnterminatedStringLiteral { - line: chars.line, - col: chars.col, + line: start_line, + col: start_col, }) }