Skip to content

Commit c1f9352

Browse files
committed
printer: support SubscriptExpr
1 parent 8fb9cc3 commit c1f9352

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

printer/expr.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ func (p *printer) expr1(expr ast.Expr, prec1 int) {
1818
p.binaryExpr(x, prec1)
1919
case *ast.UnaryExpr:
2020
p.unaryExpr(x, prec1)
21-
// case *ast.SubscriptExpr:
21+
case *ast.SubscriptExpr:
22+
p.expr1(x.Left, opprec(x))
23+
p.token(token.SQOPEN)
24+
p.expr(x.Right)
25+
p.token(token.SQCLOSE)
2226
// case *ast.SliceExpr:
2327
// case *ast.CallExpr:
2428
// case *ast.DotExpr:

printer/expr_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func TestFprint_expr(t *testing.T) {
2727
{in: `1+(2*3)`, want: `1 + (2 * 3)`}, // ParenExpr
2828
{in: `(((x+(1))))`, want: `(x + (1))`}, // ParenExpr
2929
{in: `x+1==14 ||-1`, want: `x + 1 == 14 || -1`}, // BinaryExpr
30+
{in: `x[ y ]`, want: `x[y]`}, // SubscriptExpr
3031
}
3132

3233
for _, tt := range tests {

0 commit comments

Comments
 (0)