diff --git a/dmc-lib/src/lexer.rs b/dmc-lib/src/lexer.rs index 5319373..1627b39 100644 --- a/dmc-lib/src/lexer.rs +++ b/dmc-lib/src/lexer.rs @@ -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() { diff --git a/dmc-lib/src/parser.rs b/dmc-lib/src/parser.rs index a1aab43..7712832 100644 --- a/dmc-lib/src/parser.rs +++ b/dmc-lib/src/parser.rs @@ -1166,7 +1166,20 @@ impl<'a> Parser<'a> { } fn expression(&mut self) -> MaybeParseResult { - 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 {