Allow expressions like sin2x

This commit is contained in:
PaddiM8 2023-07-19 23:50:22 +02:00
parent 7e41531b91
commit 9fff7efe7b
3 changed files with 18 additions and 4 deletions

View File

@ -42,6 +42,7 @@ mod tests {
} }
#[test_case("ambiguities/comparison_in_function")] #[test_case("ambiguities/comparison_in_function")]
#[test_case("ambiguities/fn_call_no_parenthesis")]
#[test_case("basics")] #[test_case("basics")]
#[test_case("comparisons")] #[test_case("comparisons")]
#[test_case("comprehensions")] #[test_case("comprehensions")]

View File

@ -640,10 +640,18 @@ fn parse_identifier(context: &mut Context) -> Result<Expr, KalkError> {
let identifier_pos = context.pos; let identifier_pos = context.pos;
// Function call // Function call
let mut arguments = match parse_primary(context)? { // If there is a parenthesis/brace, parse that as a
Expr::Vector(arguments) => arguments, // vector/group, otherwise it's an expression like sqrt4,
Expr::Group(argument) => vec![*argument], // which should be parsed as a factor, to allow eg. sqrt2x.
argument => vec![argument], let mut arguments = if match_token(context, TokenKind::OpenBrace)
|| match_token(context, TokenKind::OpenParenthesis) {
match parse_primary(context)? {
Expr::Vector(arguments) => arguments,
Expr::Group(argument) => vec![*argument],
argument => vec![argument],
}
} else {
vec![parse_factor(context)?]
}; };
// If it's a re-definition, revert and parse as a declaration // If it's a re-definition, revert and parse as a declaration

View File

@ -0,0 +1,5 @@
x = 3
sin2deg = sin(2deg) and
sin2x = sin(2x) and
sin2 = sin(2)