mirror of
https://github.com/PaddiM8/kalker.git
synced 2024-12-12 09:30:40 +01:00
Allow expressions like sin2x
This commit is contained in:
parent
7e41531b91
commit
9fff7efe7b
@ -42,6 +42,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test_case("ambiguities/comparison_in_function")]
|
||||
#[test_case("ambiguities/fn_call_no_parenthesis")]
|
||||
#[test_case("basics")]
|
||||
#[test_case("comparisons")]
|
||||
#[test_case("comprehensions")]
|
||||
|
@ -640,10 +640,18 @@ fn parse_identifier(context: &mut Context) -> Result<Expr, KalkError> {
|
||||
let identifier_pos = context.pos;
|
||||
|
||||
// Function call
|
||||
let mut arguments = match parse_primary(context)? {
|
||||
Expr::Vector(arguments) => arguments,
|
||||
Expr::Group(argument) => vec![*argument],
|
||||
argument => vec![argument],
|
||||
// If there is a parenthesis/brace, parse that as a
|
||||
// vector/group, otherwise it's an expression like sqrt4,
|
||||
// which should be parsed as a factor, to allow eg. sqrt2x.
|
||||
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
|
||||
|
5
tests/ambiguities/fn_call_no_parenthesis.kalker
Normal file
5
tests/ambiguities/fn_call_no_parenthesis.kalker
Normal file
@ -0,0 +1,5 @@
|
||||
x = 3
|
||||
|
||||
sin2deg = sin(2deg) and
|
||||
sin2x = sin(2x) and
|
||||
sin2 = sin(2)
|
Loading…
Reference in New Issue
Block a user