From 17a32a8df79586f7e48d05f7329bfe424060a59f Mon Sep 17 00:00:00 2001 From: Erin Date: Thu, 29 Apr 2021 09:47:29 +0200 Subject: [PATCH] Bugfix: Peeking - Fixed `PeekableLexer` next to not-be passtrough to iterator - Made error handling depend on state of Option --- src/lexer.rs | 5 ++++- src/parser/ops.rs | 1 + src/parser/utils.rs | 12 ++++++++---- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/lexer.rs b/src/lexer.rs index dbe33a8..f3038e4 100644 --- a/src/lexer.rs +++ b/src/lexer.rs @@ -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.lexer.next() + match self.peeked.take() { + Some(v) => v, + None => self.lexer.next(), + } } } diff --git a/src/parser/ops.rs b/src/parser/ops.rs index 2b76e68..fb22c30 100644 --- a/src/parser/ops.rs +++ b/src/parser/ops.rs @@ -21,6 +21,7 @@ impl<'a> Parser<'a> { } fn fn_call(&mut self, iden: Iden) -> Result { + self.lexer.next(); self.require(Token::RightParenthesis)?; Ok(Expr::FunctionCall { iden, diff --git a/src/parser/utils.rs b/src/parser/utils.rs index 49c8b34..eddfbea 100644 --- a/src/parser/utils.rs +++ b/src/parser/utils.rs @@ -42,12 +42,16 @@ impl<'a> Parser<'a> { } pub(super) fn unexpected_token(&mut self, expected: Option) -> 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(), } }