@@ -32,7 +32,7 @@ type Expr interface {
3232// BinaryExpr represents a binary expression (e.g., a && b, x == y).
3333type BinaryExpr struct {
3434 Left Expr // Left-hand side expression
35- Op string // Operator (e.g., &&, ||, ==, <)
35+ Op string // Binary operator (e.g., &&, ||, ==, <)
3636 Right Expr // Right-hand side expression
3737}
3838
@@ -48,7 +48,7 @@ func (e BinaryExpr) Text() string {
4848
4949// UnaryExpr represents a unary expression (e.g., !x).
5050type UnaryExpr struct {
51- Op string // Operator (e.g., !)
51+ Op string // Unary operator (e.g., !)
5252 Expr Expr // Operand expression
5353}
5454
@@ -59,10 +59,10 @@ func (e UnaryExpr) Text() string {
5959 return fmt .Sprintf ("%s%s" , e .Op , e .Expr .Text ())
6060}
6161
62- // PrimaryExpr represents an atomic expression, which can be a literal,
63- // identifier, function call, or parenthesized expression.
62+ // PrimaryExpr represents an atomic expression:
63+ // a literal, identifier, function call, or a parenthesized expression.
6464type PrimaryExpr struct {
65- Value string // Literal value or identifier
65+ Value string // Literal or identifier text
6666 Call * FuncCall // Optional function call
6767 Inner * InnerExpr // Optional parenthesized expression
6868}
@@ -80,7 +80,7 @@ func (e PrimaryExpr) Text() string {
8080// FuncCall represents a function call expression with arguments.
8181type FuncCall struct {
8282 Name string // Function name
83- Args []Expr // Arguments
83+ Args []Expr // Function arguments
8484}
8585
8686func (f FuncCall ) Text () string {
@@ -94,7 +94,7 @@ func (f FuncCall) Text() string {
9494 return fmt .Sprintf ("%s(%s)" , f .Name , strings .Join (args , ", " ))
9595}
9696
97- // InnerExpr represents a parenthesized expression .
97+ // InnerExpr represents a parenthesized subexpression, e.g., "(a && b)" .
9898type InnerExpr struct {
9999 Expr Expr
100100}
@@ -138,9 +138,7 @@ func Parse(data string) (expr Expr, err error) {
138138 p .AddErrorListener (e )
139139
140140 // Step 3: Walk parse tree with custom listener
141- l := & ParseTreeListener {
142- Tokens : tokens ,
143- }
141+ l := & ParseTreeListener {Tokens : tokens }
144142 antlr .ParseTreeWalkerDefault .Walk (l , p .ValidateExpr ())
145143
146144 // Step 4: Return parsed expression or error
@@ -185,7 +183,7 @@ func parseValidateExpr(ctx IValidateExprContext) Expr {
185183 return parseLogicalOrExpr (ctx .LogicalOrExpr ())
186184}
187185
188- // parseLogicalOrExpr converts a LogicalOrExprContext into an Expr .
186+ // parseLogicalOrExpr handles logical OR expressions (e.g., a || b || c) .
189187func parseLogicalOrExpr (ctx ILogicalOrExprContext ) Expr {
190188 left := parseLogicalAndExpr (ctx .LogicalAndExpr (0 ))
191189 for i , o := range ctx .AllLOGICAL_OR () {
@@ -198,7 +196,7 @@ func parseLogicalOrExpr(ctx ILogicalOrExprContext) Expr {
198196 return left
199197}
200198
201- // parseLogicalAndExpr converts a LogicalAndExprContext into an Expr .
199+ // parseLogicalAndExpr handles logical AND expressions (e.g., a && b && c) .
202200func parseLogicalAndExpr (ctx ILogicalAndExprContext ) Expr {
203201 left := parseEqualityExpr (ctx .EqualityExpr (0 ))
204202 for i , o := range ctx .AllLOGICAL_AND () {
@@ -211,7 +209,7 @@ func parseLogicalAndExpr(ctx ILogicalAndExprContext) Expr {
211209 return left
212210}
213211
214- // parseEqualityExpr converts an EqualityExprContext into an Expr .
212+ // parseEqualityExpr handles equality and inequality comparisons (==, !=) .
215213func parseEqualityExpr (ctx IEqualityExprContext ) Expr {
216214 left := parseRelationalExpr (ctx .RelationalExpr (0 ))
217215
@@ -231,7 +229,7 @@ func parseEqualityExpr(ctx IEqualityExprContext) Expr {
231229 }
232230}
233231
234- // parseRelationalExpr converts a RelationalExprContext into an Expr .
232+ // parseRelationalExpr handles <, <=, >, >= expressions .
235233func parseRelationalExpr (ctx IRelationalExprContext ) Expr {
236234 left := parseUnaryExpr (ctx .UnaryExpr (0 ))
237235
@@ -255,7 +253,7 @@ func parseRelationalExpr(ctx IRelationalExprContext) Expr {
255253 }
256254}
257255
258- // parseUnaryExpr converts a UnaryExprContext into an Expr .
256+ // parseUnaryExpr handles unary operators like !expr .
259257func parseUnaryExpr (ctx IUnaryExprContext ) Expr {
260258 if ctx .LOGICAL_NOT () != nil {
261259 return UnaryExpr {
@@ -266,7 +264,8 @@ func parseUnaryExpr(ctx IUnaryExprContext) Expr {
266264 return parsePrimaryExpr (ctx .PrimaryExpr ())
267265}
268266
269- // parsePrimaryExpr converts a PrimaryExprContext into an Expr.
267+ // parsePrimaryExpr handles literals, identifiers, function calls,
268+ // and parenthesized expressions.
270269func parsePrimaryExpr (ctx IPrimaryExprContext ) Expr {
271270 if ctx == nil {
272271 return nil
0 commit comments