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
e45afeac5e
commit
17a32a8df7
|
@ -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(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue