diff options
Diffstat (limited to 'syntax')
-rw-r--r-- | syntax/parse.go | 22 | ||||
-rw-r--r-- | syntax/parse_test.go | 2 |
2 files changed, 3 insertions, 21 deletions
diff --git a/syntax/parse.go b/syntax/parse.go index e7d3106..ed8aeaf 100644 --- a/syntax/parse.go +++ b/syntax/parse.go @@ -11,7 +11,7 @@ package syntax // package. Verify that error positions are correct using the // chunkedfile mechanism. -import "log" +import log "log" // Enable this flag to print the token stream and log.Fatal on the first error. const debug = false @@ -579,7 +579,7 @@ func (p *parser) parseBinopExpr(prec int) Expr { op := p.tok pos := p.nextToken() y := p.parseTestPrec(opprec + 1) - x = makeBinaryExpr(op, pos, x, y) + x = &BinaryExpr{OpPos: pos, Op: op, X: x, Y: y} } } @@ -613,24 +613,6 @@ func init() { } } -func makeBinaryExpr(op Token, pos Position, x, y Expr) Expr { - // Concatenate literal strings during parsing. - if op == PLUS { - if x, ok := x.(*Literal); ok && x.Token == STRING { - if y, ok := y.(*Literal); ok && y.Token == STRING { - // The Span of this synthetic node will be wrong. - return &Literal{ - Token: STRING, - TokenPos: x.TokenPos, - Raw: x.Raw + " + " + y.Raw, // ugh - Value: x.Value.(string) + y.Value.(string), - } - } - } - } - return &BinaryExpr{OpPos: pos, Op: op, X: x, Y: y} -} - // primary_with_suffix = primary // | primary '.' IDENT // | primary slice_suffix diff --git a/syntax/parse_test.go b/syntax/parse_test.go index d511d3f..bee9388 100644 --- a/syntax/parse_test.go +++ b/syntax/parse_test.go @@ -85,7 +85,7 @@ func TestExprParseTrees(t *testing.T) { {`-1 + +2`, `(BinaryExpr X=(UnaryExpr Op=- X=1) Op=+ Y=(UnaryExpr Op=+ X=2))`}, {`"foo" + "bar"`, - `"foobar"`}, // concatenated + `(BinaryExpr X="foo" Op=+ Y="bar")`}, {`-1 * 2`, // prec(unary -) > prec(binary *) `(BinaryExpr X=(UnaryExpr Op=- X=1) Op=* Y=2)`}, {`-x[i]`, // prec(unary -) < prec(x[i]) |