Bugfix: Peeking
- Fixed `PeekableLexer` next to not-be passtrough to iterator - Made error handling depend on state of Option
This commit is contained in:
parent
3e019621b2
commit
27a8de70fa
|
@ -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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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(),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue