Bugfix: Peeking

- Fixed `PeekableLexer` next to not-be passtrough to iterator
- Made error handling depend on state of Option
This commit is contained in:
Erin 2021-04-29 09:47:29 +02:00 committed by ondra05
parent e45afeac5e
commit 17a32a8df7
3 changed files with 13 additions and 5 deletions

View file

@ -53,7 +53,10 @@ impl<'source> Iterator for PeekableLexer<'source> {
/// again may or may not eventually start returning [`Some(Item)`] again at some point. /// again may or may not eventually start returning [`Some(Item)`] again at some point.
#[inline] #[inline]
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
self.lexer.next() match self.peeked.take() {
Some(v) => v,
None => self.lexer.next(),
}
} }
} }

View file

@ -21,6 +21,7 @@ impl<'a> Parser<'a> {
} }
fn fn_call(&mut self, iden: Iden) -> Result<Expr, Error> { fn fn_call(&mut self, iden: Iden) -> Result<Expr, Error> {
self.lexer.next();
self.require(Token::RightParenthesis)?; self.require(Token::RightParenthesis)?;
Ok(Expr::FunctionCall { Ok(Expr::FunctionCall {
iden, iden,

View file

@ -42,12 +42,16 @@ impl<'a> Parser<'a> {
} }
pub(super) fn unexpected_token(&mut self, expected: Option<Token>) -> Error { pub(super) fn unexpected_token(&mut self, expected: Option<Token>) -> Error {
Error { let error_msg = match expected {
kind: ErrorKind::SyntaxError(format!( Some(s) => format!(
"Unexpected token: `{}` (required: `{:?}`)", "Unexpected token: `{}` (required: `{:?}`)",
self.lexer.slice(), self.lexer.slice(),
expected s
)), ),
None => format!("Unexpected token: `{}`)", self.lexer.slice(),),
};
Error {
kind: ErrorKind::SyntaxError(error_msg),
position: self.lexer.span(), position: self.lexer.span(),
} }
} }