about summary refs log tree commit diff
path: root/pkg/lang/parser/exprs.go
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2022-06-14 00:07:40 +0000
committerGitHub <noreply@github.com>2022-06-14 00:07:40 +0000
commit3498876f06104515002191468fd99019d40051c2 (patch)
tree7f1c3a34fe442382c82519a94ae089f22e252f71 /pkg/lang/parser/exprs.go
parent14bdb59c24aef85f2a7c69f03ddacb7f56445e9e (diff)
downloadjinx-3498876f06104515002191468fd99019d40051c2.tar.zst
jinx-3498876f06104515002191468fd99019d40051c2.zip
Fix BinExpr precendence not being drilled down
Diffstat (limited to 'pkg/lang/parser/exprs.go')
-rw-r--r--pkg/lang/parser/exprs.go35
1 files changed, 5 insertions, 30 deletions
diff --git a/pkg/lang/parser/exprs.go b/pkg/lang/parser/exprs.go
index b08864a..ceda018 100644
--- a/pkg/lang/parser/exprs.go
+++ b/pkg/lang/parser/exprs.go
@@ -26,38 +26,13 @@ func (p *Parser) parseBinaryExpr() (ast.Expr, error) {
 			return ast.Expr{}, err
 		}
 
-		// Check precedence and associativity.
-		if right.Kind == ast.ExprKindBinary {
-			rightBin := right.Value.(ast.ExprBinary)
-
-			needsSwitch := (op.Precedence() > rightBin.Op.Precedence()) ||
-				(op.Precedence() == rightBin.Op.Precedence() && op.Associativity() == ast.AssociativityLeft)
-
-			if needsSwitch {
-				left = ast.Expr{
-					At:   left.At,
-					Kind: ast.ExprKindBinary,
-					Value: ast.ExprBinary{
-						Left:  left,
-						Op:    op,
-						Right: rightBin.Left,
-					},
-				}
-
-				right = rightBin.Right
-
-				op = rightBin.Op
-			}
-		}
+		// Adjust for precedence and associativity.
+		binary := p.mergeIntoBinary(left, op, right)
 
 		left = ast.Expr{
-			At:   left.At,
-			Kind: ast.ExprKindBinary,
-			Value: ast.ExprBinary{
-				Left:  left,
-				Op:    op,
-				Right: right,
-			},
+			At:    left.At,
+			Kind:  ast.ExprKindBinary,
+			Value: binary,
 		}
 	}