From 0c7e694648fe9214e142337e9390ee90845a575f Mon Sep 17 00:00:00 2001 From: PaddiM8 Date: Sun, 13 Dec 2020 23:44:33 +0100 Subject: [PATCH] Fixed bug where symbol_table::contains_fn didn't check in the BINARY_FUNCS map --- kalk/src/parser.rs | 4 ++-- kalk/src/symbol_table.rs | 2 +- kalk_cli/src/output.rs | 4 +++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/kalk/src/parser.rs b/kalk/src/parser.rs index 8509b80..7f474b4 100644 --- a/kalk/src/parser.rs +++ b/kalk/src/parser.rs @@ -70,7 +70,7 @@ pub enum CalcError { InvalidNumberLiteral(String), InvalidOperator, InvalidUnit, - UnexpectedToken(TokenKind), + UnexpectedToken(TokenKind, TokenKind), UndefinedFn(String), UndefinedVar(String), UnableToInvert(String), @@ -466,7 +466,7 @@ fn consume(context: &mut Context, kind: TokenKind) -> Result<&Token, CalcError> return Ok(advance(context)); } - Err(CalcError::UnexpectedToken(kind)) + Err(CalcError::UnexpectedToken(peek(context).kind, kind)) } fn is_at_end(context: &Context) -> bool { diff --git a/kalk/src/symbol_table.rs b/kalk/src/symbol_table.rs index aead965..0d993cc 100644 --- a/kalk/src/symbol_table.rs +++ b/kalk/src/symbol_table.rs @@ -75,7 +75,7 @@ impl SymbolTable { pub fn contains_fn(&self, identifier: &str) -> bool { prelude::UNARY_FUNCS.contains_key(identifier) - || prelude::UNARY_FUNCS.contains_key(identifier) + || prelude::BINARY_FUNCS.contains_key(identifier) || self.hashmap.contains_key(&format!("fn.{}", identifier)) } } diff --git a/kalk_cli/src/output.rs b/kalk_cli/src/output.rs index 6a01999..2d5e2e4 100644 --- a/kalk_cli/src/output.rs +++ b/kalk_cli/src/output.rs @@ -39,7 +39,9 @@ fn print_calc_err(err: CalcError) { InvalidNumberLiteral(x) => format!("Invalid number literal: '{}'.", x), InvalidOperator => format!("Invalid operator."), InvalidUnit => format!("Invalid unit."), - UnexpectedToken(kind) => format!("Unexpected token: '{:?}'.", kind), + UnexpectedToken(got, expected) => { + format!("Unexpected token: '{:?}', expected '{:?}'.", got, expected) + } UnableToInvert(msg) => format!("Unable to invert: {}", msg), UndefinedFn(name) => format!("Undefined function: '{}'.", name), UndefinedVar(name) => format!("Undefined variable: '{}'.", name),