Skip to content

Commit 7b9a7fe

Browse files
committed
implement MethodExpr
1 parent 2a7254a commit 7b9a7fe

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

ast/node.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,16 @@ type SliceExpr struct {
427427

428428
func (f *SliceExpr) Pos() Pos { return f.Lbrack }
429429

430+
// vimlparser: METHOD .left .right
431+
type MethodExpr struct {
432+
Left Expr // this object
433+
Method Expr // method
434+
Lparen Pos // position of "("
435+
Args []Expr // function arguments; or nil
436+
}
437+
438+
func (c *MethodExpr) Pos() Pos { return c.Lparen }
439+
430440
// vimlparser: CALL .left .rlist
431441
type CallExpr struct {
432442
Fun Expr // function expression
@@ -588,6 +598,7 @@ func (*BinaryExpr) exprNode() {}
588598
func (*UnaryExpr) exprNode() {}
589599
func (*SubscriptExpr) exprNode() {}
590600
func (*SliceExpr) exprNode() {}
601+
func (*MethodExpr) exprNode() {}
591602
func (*CallExpr) exprNode() {}
592603
func (*DotExpr) exprNode() {}
593604
func (*BasicLit) exprNode() {}

ast/walk.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ func Walk(v Visitor, node Node) {
164164
Walk(v, n.Low)
165165
Walk(v, n.High)
166166

167+
case *MethodExpr:
168+
Walk(v, n.Left)
169+
Walk(v, n.Method)
170+
walkExprList(v, n.Args)
171+
167172
case *CallExpr:
168173
Walk(v, n.Fun)
169174
walkExprList(v, n.Args)

compiler/compiler.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,14 @@ func (c *Compiler) compileExpr(node ast.Expr) string {
387387
h = c.compileExpr(n.High)
388388
}
389389
return fmt.Sprintf("(slice %s %s %s)", x, l, h)
390+
case *ast.MethodExpr:
391+
name := c.compileExpr(n.Left)
392+
args := make([]string, 0, len(n.Args)+1)
393+
args = append(args, c.compileExpr(n.Method))
394+
for _, a := range n.Args {
395+
args = append(args, c.compileExpr(a))
396+
}
397+
return fmt.Sprintf("(method %s (%s))", name, strings.Join(args, " "))
390398
case *ast.CallExpr:
391399
name := c.compileExpr(n.Fun)
392400
if len(n.Args) > 0 {

go/export.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,14 @@ func newAstNode(n *VimNode, filename string) ast.Node {
343343
High: newExprNode(n.rlist[1], filename),
344344
}
345345

346+
case NODE_METHOD:
347+
return &ast.MethodExpr{
348+
Lparen: pos,
349+
Left: newExprNode(n.left, filename),
350+
Method: newExprNode(n.right.left, filename),
351+
Args: newRlist(*n.right, filename),
352+
}
353+
346354
case NODE_CALL:
347355
return &ast.CallExpr{
348356
Lparen: pos,

0 commit comments

Comments
 (0)