From 0e425fbf90e65f7dce019ad6924bd49d0b939d2d Mon Sep 17 00:00:00 2001 From: bakk Date: Sun, 23 May 2021 01:42:10 +0200 Subject: [PATCH] Allow function calls without parenthesis even with a variable as argument --- kalk/src/parser.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/kalk/src/parser.rs b/kalk/src/parser.rs index b225f69..f34e55e 100644 --- a/kalk/src/parser.rs +++ b/kalk/src/parser.rs @@ -566,6 +566,24 @@ fn parse_identifier(context: &mut Context) -> Result { let mut chars: Vec = identifier.pure_name.chars().collect(); let mut left = Expr::Var(Identifier::from_full_name(&chars[0].to_string())); + // Temporarily remove the last character and check if a function + // without that character exists. If it does, + // create a function call expression, where that last character + // is the argument. + let last_char = chars.pop().unwrap_or_default(); + let identifier_without_last: String = chars.iter().collect(); + if context.symbol_table.contains_fn(&identifier_without_last) { + return Ok(Expr::FnCall( + Identifier::from_full_name(&identifier_without_last), + vec![Expr::Var(Identifier::from_full_name( + &last_char.to_string(), + ))], + )); + } else { + // Otherwise, re-add the character. + chars.push(last_char); + } + // If there is a an infinitesimal at the end, // remove it from 'chars', since it should be separate. if let Some(_) = dx {