fix: precedence of unary operators and expressions

Signed-off-by: Michael Hoffmann <mhoffm@posteo.de>
This commit is contained in:
Michael Hoffmann
2025-03-30 13:33:58 +02:00
parent 009def4ae3
commit 28e327cd3f
15 changed files with 7189 additions and 6812 deletions

View File

@@ -4,6 +4,8 @@
/** @param {string} dialect */
module.exports = function make_grammar(dialect) {
const PREC = {
// unary negation should not pull expressions apart
expr: 8,
unary: 7,
binary_mult: 6,
binary_add: 5,
@@ -75,9 +77,9 @@ module.exports = function make_grammar(dialect) {
$.function_call,
$.for_expr,
$.operation,
seq($._expr_term, $.index),
seq($._expr_term, $.get_attr),
seq($._expr_term, $.splat),
prec.right(PREC.expr, seq($._expr_term, $.index)),
prec.right(PREC.expr, seq($._expr_term, $.get_attr)),
prec.right(PREC.expr, seq($._expr_term, $.splat)),
seq("(", $.expression, ")"),
),