Fixed some lexer/parser bugs related to lexer errors.
This commit is contained in:
parent
6ac075ffd0
commit
4e3f1677be
@ -118,11 +118,10 @@ impl<'a> Lexer<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !terminated {
|
if !terminated {
|
||||||
return Some(Err(LexerError::new(
|
let err =
|
||||||
self.position,
|
LexerError::new(self.position, end, LexerErrorKind::UnterminatedString);
|
||||||
end,
|
self.position = end;
|
||||||
LexerErrorKind::UnterminatedString,
|
return Some(Err(err));
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
(end, TokenKind::String)
|
(end, TokenKind::String)
|
||||||
} else {
|
} else {
|
||||||
@ -137,11 +136,13 @@ impl<'a> Lexer<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if prefix.len() == 0 {
|
if prefix.len() == 0 {
|
||||||
return Some(Err(LexerError::new(
|
let err = LexerError::new(
|
||||||
self.position,
|
self.position,
|
||||||
self.position + 1,
|
self.position + 1,
|
||||||
LexerErrorKind::UnrecognizedCharacter(chunk.chars().next().unwrap()),
|
LexerErrorKind::UnrecognizedCharacter(chunk.chars().next().unwrap()),
|
||||||
)));
|
);
|
||||||
|
self.position += 1;
|
||||||
|
return Some(Err(err));
|
||||||
}
|
}
|
||||||
|
|
||||||
let token_kind = match prefix.as_str() {
|
let token_kind = match prefix.as_str() {
|
||||||
|
|||||||
@ -1166,7 +1166,20 @@ impl<'a> Parser<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn expression(&mut self) -> MaybeParseResult<Expression> {
|
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> {
|
fn bitwise_or_expression(&mut self) -> MaybeParseResult<Expression> {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user