Skip to content

Commit 46da320

Browse files
authored
Merge pull request #48 from itchyny/update-vimlparser-20201201
update vim-vimlparser
2 parents 6c96c66 + 98f8fad commit 46da320

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+2678
-818
lines changed

.travis.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
language: go
22

33
go:
4-
- 1.8
4+
- 1.14
5+
- 1.15
56
- tip
67

78
install:

ast/node.go

+39-2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ type Function struct {
6565
Body []Statement // function body
6666
Name Expr // function name
6767
Params []*Ident // parameters
68+
DefaultArgs []Expr // default arguments
6869
Attr FuncAttr // function attributes
6970
EndFunction *EndFunction // :endfunction
7071
}
@@ -119,6 +120,7 @@ func (f *ExCall) Pos() Pos { return f.ExCall }
119120
func (f *ExCall) Cmd() Cmd { return *f.ExArg.Cmd }
120121

121122
// vimlparser: LET .ea .op .left .list .rest .right
123+
// vimlparser: CONST .ea .op .left .list .rest .right
122124
type Let struct {
123125
Let Pos // position of starting the :let
124126
ExArg ExArg // Ex command arg
@@ -341,6 +343,17 @@ type Throw struct {
341343
func (f *Throw) Pos() Pos { return f.Throw }
342344
func (f *Throw) Cmd() Cmd { return *f.ExArg.Cmd }
343345

346+
// vimlparser: EVAL .ea .left
347+
// :eval {Expr}
348+
type Eval struct {
349+
Eval Pos // position of starting the :eval
350+
ExArg ExArg // Ex command arg
351+
Expr Expr
352+
}
353+
354+
func (f *Eval) Pos() Pos { return f.Eval }
355+
func (f *Eval) Cmd() Cmd { return *f.ExArg.Cmd }
356+
344357
// vimlparser: ECHO .ea .list
345358
// vimlparser: ECHON .ea .list
346359
// vimlparser: ECHOMSG .ea .list
@@ -426,6 +439,16 @@ type SliceExpr struct {
426439

427440
func (f *SliceExpr) Pos() Pos { return f.Lbrack }
428441

442+
// vimlparser: METHOD .left .right
443+
type MethodExpr struct {
444+
Left Expr // this object
445+
Method Expr // method
446+
Lparen Pos // position of "("
447+
Args []Expr // function arguments; or nil
448+
}
449+
450+
func (c *MethodExpr) Pos() Pos { return c.Lparen }
451+
429452
// vimlparser: CALL .left .rlist
430453
type CallExpr struct {
431454
Fun Expr // function expression
@@ -516,7 +539,7 @@ type Ident struct {
516539
func (i *Ident) Pos() Pos { return i.NamePos }
517540

518541
// LambdaExpr node represents lambda.
519-
// vimlparsr: LAMBDA .rlist .left
542+
// vimlparser: LAMBDA .rlist .left
520543
// { Params -> Expr }
521544
type LambdaExpr struct {
522545
Lcurlybrace Pos // position of "{"
@@ -527,14 +550,25 @@ type LambdaExpr struct {
527550
func (i *LambdaExpr) Pos() Pos { return i.Lcurlybrace }
528551

529552
// ParenExpr node represents a parenthesized expression.
530-
// vimlparsr: PARENEXPR .value
553+
// vimlparser: PARENEXPR .value
531554
type ParenExpr struct {
532555
Lparen Pos // position of "("
533556
X Expr // parenthesized expression
534557
}
535558

536559
func (i *ParenExpr) Pos() Pos { return i.Lparen }
537560

561+
// HeredocExpr node represents a heredoc expression.
562+
// vimlparser: HEREDOC .rlist .op .body
563+
type HeredocExpr struct {
564+
OpPos Pos // position of "=<<"
565+
Flags []Expr // modifiers [trim]; or nil
566+
EndMarker string // {endmarker}
567+
Body []Expr // body
568+
}
569+
570+
func (i *HeredocExpr) Pos() Pos { return i.OpPos }
571+
538572
// stmtNode() ensures that only ExComamnd and Comment nodes can be assigned to
539573
// an Statement.
540574
//
@@ -562,6 +596,7 @@ func (*Let) stmtNode() {}
562596
func (*LockVar) stmtNode() {}
563597
func (*Return) stmtNode() {}
564598
func (*Throw) stmtNode() {}
599+
func (*Eval) stmtNode() {}
565600
func (*Try) stmtNode() {}
566601
func (*UnLet) stmtNode() {}
567602
func (*UnLockVar) stmtNode() {}
@@ -576,6 +611,7 @@ func (*BinaryExpr) exprNode() {}
576611
func (*UnaryExpr) exprNode() {}
577612
func (*SubscriptExpr) exprNode() {}
578613
func (*SliceExpr) exprNode() {}
614+
func (*MethodExpr) exprNode() {}
579615
func (*CallExpr) exprNode() {}
580616
func (*DotExpr) exprNode() {}
581617
func (*BasicLit) exprNode() {}
@@ -587,3 +623,4 @@ func (*CurlyNameExpr) exprNode() {}
587623
func (*Ident) exprNode() {}
588624
func (*LambdaExpr) exprNode() {}
589625
func (*ParenExpr) exprNode() {}
626+
func (*HeredocExpr) exprNode() {}

ast/walk.go

+12
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ func Walk(v Visitor, node Node) {
135135
case *Throw:
136136
Walk(v, n.Expr)
137137

138+
case *Eval:
139+
Walk(v, n.Expr)
140+
138141
case *EchoCmd:
139142
walkExprList(v, n.Exprs)
140143

@@ -164,6 +167,11 @@ func Walk(v Visitor, node Node) {
164167
Walk(v, n.Low)
165168
Walk(v, n.High)
166169

170+
case *MethodExpr:
171+
Walk(v, n.Left)
172+
Walk(v, n.Method)
173+
walkExprList(v, n.Args)
174+
167175
case *CallExpr:
168176
Walk(v, n.Fun)
169177
walkExprList(v, n.Args)
@@ -201,6 +209,10 @@ func Walk(v Visitor, node Node) {
201209
case *ParenExpr:
202210
Walk(v, n.X)
203211

212+
case *HeredocExpr:
213+
walkExprList(v, n.Flags)
214+
walkExprList(v, n.Body)
215+
204216
default:
205217
panic(fmt.Sprintf("ast.Walk: unexpected node type %T", n))
206218
}

0 commit comments

Comments
 (0)