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..0876e4103 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 {