@@ -24,7 +24,6 @@ FLOAT_LITERAL: (NEGATIVE_DECIMAL? DECIMAL+ | NEGATIVE_DECIMAL+) "." DECIMAL+ (EX
2424 | (NEGATIVE_DECIMAL ? DECIMAL + | NEGATIVE_DECIMAL + ) (EXP_MARK )
2525
2626// Operators
27- BINARY_OP : DOUBLE_EQ | NEQ | LT | GT | LEQ | GEQ | MINUS | ASTERISK | SLASH | PERCENT | DOUBLE_AMP | DOUBLE_PIPE | PLUS
2827DOUBLE_EQ : " =="
2928NEQ : " !="
3029LT : " <"
@@ -99,16 +98,61 @@ string_part: STRING_CHARS
9998 | interpolation
10099
101100// Expressions
102- ? expression : expr_term | operation | conditional
101+ ? expression : or_expr QMARK new_line_or_comment ? expression new_line_or_comment ? COLON new_line_or_comment ? expression -> conditional
102+ | or_expr
103103interpolation : INTERP_START expression RBRACE
104- conditional : expression QMARK new_line_or_comment ? expression new_line_or_comment ? COLON new_line_or_comment ? expression
105104
106- // Operations
107- ? operation : unary_op | binary_op
105+ // Operator precedence ladder (lowest to highest)
106+ // Each level uses left recursion for left-associativity.
107+ // Rule aliases (-> binary_op, -> binary_term, -> binary_operator) maintain
108+ // transformer compatibility with BinaryOpRule / BinaryTermRule / BinaryOperatorRule.
109+
110+ // Logical OR
111+ ? or_expr : or_expr or_binary_term new_line_or_comment ? -> binary_op
112+ | and_expr
113+ or_binary_term : or_binary_operator new_line_or_comment ? and_expr -> binary_term
114+ ! or_binary_operator : DOUBLE_PIPE -> binary_operator
115+
116+ // Logical AND
117+ ? and_expr : and_expr and_binary_term new_line_or_comment ? -> binary_op
118+ | eq_expr
119+ and_binary_term : and_binary_operator new_line_or_comment ? eq_expr -> binary_term
120+ ! and_binary_operator : DOUBLE_AMP -> binary_operator
121+
122+ // Equality
123+ ? eq_expr : eq_expr eq_binary_term new_line_or_comment ? -> binary_op
124+ | rel_expr
125+ eq_binary_term : eq_binary_operator new_line_or_comment ? rel_expr -> binary_term
126+ ! eq_binary_operator : DOUBLE_EQ -> binary_operator
127+ | NEQ -> binary_operator
128+
129+ // Relational
130+ ? rel_expr : rel_expr rel_binary_term new_line_or_comment ? -> binary_op
131+ | add_expr
132+ rel_binary_term : rel_binary_operator new_line_or_comment ? add_expr -> binary_term
133+ ! rel_binary_operator : LT -> binary_operator
134+ | GT -> binary_operator
135+ | LEQ -> binary_operator
136+ | GEQ -> binary_operator
137+
138+ // Additive
139+ ? add_expr : add_expr add_binary_term new_line_or_comment ? -> binary_op
140+ | mul_expr
141+ add_binary_term : add_binary_operator new_line_or_comment ? mul_expr -> binary_term
142+ ! add_binary_operator : PLUS -> binary_operator
143+ | MINUS -> binary_operator
144+
145+ // Multiplicative
146+ ? mul_expr : mul_expr mul_binary_term new_line_or_comment ? -> binary_op
147+ | unary_expr
148+ mul_binary_term : mul_binary_operator new_line_or_comment ? unary_expr -> binary_term
149+ ! mul_binary_operator : ASTERISK -> binary_operator
150+ | SLASH -> binary_operator
151+ | PERCENT -> binary_operator
152+
153+ // Unary (highest precedence for operations)
154+ ? unary_expr : unary_op | expr_term
108155! unary_op : (MINUS | NOT ) expr_term
109- binary_op : expression binary_term new_line_or_comment ?
110- binary_term : binary_operator new_line_or_comment ? expression
111- ! binary_operator : BINARY_OP
112156
113157// Expression terms
114158expr_term : LPAR new_line_or_comment ? expression new_line_or_comment ? RPAR
0 commit comments