Skip to content

Commit 0076eee

Browse files
authored
Fix NOT operator precedence with parenthesized expressions (#32)
1 parent 39de90f commit 0076eee

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

parser/expression.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,15 @@ func (p *Parser) parseNot() ast.Expression {
809809
Op: "NOT",
810810
}
811811
p.nextToken()
812-
expr.Operand = p.parseExpression(NOT_PREC)
812+
// When NOT is followed by a parenthesized expression, use UNARY precedence
813+
// so that binary operators after the group don't continue as part of the NOT operand.
814+
// e.g., NOT (0) + 1 should parse as (NOT(0)) + 1, not NOT((0) + 1)
815+
// But NOT 0 + 1 should parse as NOT(0 + 1)
816+
if p.currentIs(token.LPAREN) {
817+
expr.Operand = p.parseExpression(UNARY)
818+
} else {
819+
expr.Operand = p.parseExpression(NOT_PREC)
820+
}
813821
return expr
814822
}
815823

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"todo": true}
1+
{}

0 commit comments

Comments
 (0)