From d3d6a015eca0c00efb21bdc91643621f88b76865 Mon Sep 17 00:00:00 2001 From: TcMits Date: Tue, 30 Sep 2025 12:25:20 +0700 Subject: [PATCH 1/2] fix issue 3425 --- parser/src/error.rs | 3 --- parser/src/lexer.rs | 30 ++++++++++++++++++++---------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/parser/src/error.rs b/parser/src/error.rs index 27fe46956..63d4aef78 100644 --- a/parser/src/error.rs +++ b/parser/src/error.rs @@ -14,9 +14,6 @@ pub enum Error { /// Missing `]` #[error("non-terminated bracket at {0:?}")] UnterminatedBracket(#[label("here")] miette::SourceSpan), - /// Missing `*/` - #[error("non-terminated block comment at {0:?}")] - UnterminatedBlockComment(#[label("here")] miette::SourceSpan), /// Invalid parameter name #[error("bad variable name at {0:?}")] BadVariableName(#[label("here")] miette::SourceSpan), diff --git a/parser/src/lexer.rs b/parser/src/lexer.rs index aab03f36a..f0fae60f6 100644 --- a/parser/src/lexer.rs +++ b/parser/src/lexer.rs @@ -400,6 +400,9 @@ impl<'a> Lexer<'a> { let start = self.offset; self.eat_and_assert(|b| b == b'/'); match self.peek() { + // C-style comments begin with "/*" and extend up to and + // including the next "*/" character pair or until + // the end of input, whichever comes first. Some(b'*') => { self.eat_and_assert(|b| b == b'*'); loop { @@ -412,19 +415,11 @@ impl<'a> Lexer<'a> { self.eat_and_assert(|b| b == b'/'); break; // End of block comment } - None => { - return Err(Error::UnterminatedBlockComment( - (start, self.offset - start).into(), - )) - } + None => break, _ => {} } } - None => { - return Err(Error::UnterminatedBlockComment( - (start, self.offset - start).into(), - )) - } + None => break, _ => unreachable!(), // We should not reach here } } @@ -1250,6 +1245,21 @@ mod tests { token_type: Some(TokenType::TK_FLOAT), }, ), + // issue 3425 + ( + b"/*".as_slice(), + Token { + value: b"/*".as_slice(), + token_type: None, + }, + ), + ( + b"/**".as_slice(), + Token { + value: b"/**".as_slice(), + token_type: None, + }, + ), ]; for (input, expected) in test_cases { From 4211460ef3a34c2a8fdde087e478e66226d045ab Mon Sep 17 00:00:00 2001 From: TcMits Date: Tue, 30 Sep 2025 12:28:24 +0700 Subject: [PATCH 2/2] fmt --- parser/src/lexer.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/parser/src/lexer.rs b/parser/src/lexer.rs index f0fae60f6..0876e4103 100644 --- a/parser/src/lexer.rs +++ b/parser/src/lexer.rs @@ -400,8 +400,8 @@ impl<'a> Lexer<'a> { let start = self.offset; self.eat_and_assert(|b| b == b'/'); match self.peek() { - // C-style comments begin with "/*" and extend up to and - // including the next "*/" character pair or until + // C-style comments begin with "/*" and extend up to and + // including the next "*/" character pair or until // the end of input, whichever comes first. Some(b'*') => { self.eat_and_assert(|b| b == b'*');