commit 90ddf985e0d10c284c0fd946af4985cd2f9d4801
parent 397d47a11a34b9e1dd15971985186591c63e6bbd
Author: Demonstrandum <moi@knutsen.co>
Date: Thu, 25 Jun 2020 14:58:04 +0100
Make juxtaposition right associative.
Diffstat:
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/parse.c b/src/parse.c
@@ -386,7 +386,13 @@ ParseNode *parse_infix(const ParseNode *left,
unary->is_postfix = true;
} else { // Function call.
unary->callee = left;
- unary->operand = parse_expr(rest, FUNCTION_PRECEDENCE);
+ // The minus one (- 1) makes function application right
+ // associative, this is unconventional, and makes applications
+ // on functions that return functions not very pretty.
+ // However, it makes for more natural syntax for multiplication
+ // by juxtaposition.
+ // e.g. 3 sin 2 => (3 (sin 2)) vs ((3 sin) 2) [<- error]
+ unary->operand = parse_expr(rest, FUNCTION_PRECEDENCE - 1);
unary->is_postfix = false;
}