Fixed some lexer/parser bugs related to lexer errors.

This commit is contained in:
Jesse Brault 2026-08-21 13:50:44 -05:00
parent 6ac075ffd0
commit 4e3f1677be
2 changed files with 22 additions and 8 deletions

View File

@ -118,11 +118,10 @@ impl<'a> Lexer<'a> {
}
}
if !terminated {
return Some(Err(LexerError::new(
self.position,
end,
LexerErrorKind::UnterminatedString,
)));
let err =
LexerError::new(self.position, end, LexerErrorKind::UnterminatedString);
self.position = end;
return Some(Err(err));
}
(end, TokenKind::String)
} else {
@ -137,11 +136,13 @@ impl<'a> Lexer<'a> {
}
if prefix.len() == 0 {
return Some(Err(LexerError::new(
let err = LexerError::new(
self.position,
self.position + 1,
LexerErrorKind::UnrecognizedCharacter(chunk.chars().next().unwrap()),
)));
);
self.position += 1;
return Some(Err(err));
}
let token_kind = match prefix.as_str() {

View File

@ -1166,7 +1166,20 @@ impl<'a> Parser<'a> {
}
fn expression(&mut self) -> MaybeParseResult<Expression> {
self.bitwise_or_expression()
if self.current.is_some() {
if matches_expression_first!(self.current.as_ref().unwrap().kind()) {
self.bitwise_or_expression()
} else {
let diagnostic = Self::get_expected_but_found(
&EXPRESSION_FIRSTS,
self.current.as_ref().unwrap(),
);
MaybeParseResult::none(vec![diagnostic])
}
} else {
let diagnostic = Self::get_expected_but_found_eoi(&EXPRESSION_FIRSTS, 0);
MaybeParseResult::none(vec![diagnostic])
}
}
fn bitwise_or_expression(&mut self) -> MaybeParseResult<Expression> {