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 3e019621b2
commit 27a8de70fa
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.
#[inline]
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> {
self.lexer.next();
self.require(Token::RightParenthesis)?;
Ok(Expr::FunctionCall {
iden,

View file

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