From b0954a2944b63e0384bed33c099c909a36118034 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 23 Dec 2025 19:46:48 +0000 Subject: [PATCH] Fix NOT operator precedence with parenthesized expressions When NOT is followed by a parenthesized expression, use UNARY precedence so binary operators after the group don't continue as part of the NOT operand. This ensures: - NOT (0) + 1 parses as (NOT(0)) + 1 - NOT 0 + 1 parses as NOT(0 + 1) Enables test 02920_unary_operators_functions. --- parser/expression.go | 10 +++++++++- .../02920_unary_operators_functions/metadata.json | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/parser/expression.go b/parser/expression.go index 3b3f05a72..a7e977a50 100644 --- a/parser/expression.go +++ b/parser/expression.go @@ -809,7 +809,15 @@ func (p *Parser) parseNot() ast.Expression { Op: "NOT", } p.nextToken() - expr.Operand = p.parseExpression(NOT_PREC) + // When NOT is followed by a parenthesized expression, use UNARY precedence + // so that binary operators after the group don't continue as part of the NOT operand. + // e.g., NOT (0) + 1 should parse as (NOT(0)) + 1, not NOT((0) + 1) + // But NOT 0 + 1 should parse as NOT(0 + 1) + if p.currentIs(token.LPAREN) { + expr.Operand = p.parseExpression(UNARY) + } else { + expr.Operand = p.parseExpression(NOT_PREC) + } return expr } diff --git a/parser/testdata/02920_unary_operators_functions/metadata.json b/parser/testdata/02920_unary_operators_functions/metadata.json index ef120d978..0967ef424 100644 --- a/parser/testdata/02920_unary_operators_functions/metadata.json +++ b/parser/testdata/02920_unary_operators_functions/metadata.json @@ -1 +1 @@ -{"todo": true} +{}