Fixed bug where symbol_table::contains_fn didn't check in the BINARY_FUNCS map

This commit is contained in:
PaddiM8 2020-12-13 23:44:33 +01:00
parent ec74089faa
commit 0c7e694648
3 changed files with 6 additions and 4 deletions

View File

@ -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 {

View File

@ -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))
}
}

View File

@ -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),