Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
language: go

go:
- 1.8
- 1.14
- 1.15
- tip

install:
Expand Down
41 changes: 39 additions & 2 deletions ast/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ type Function struct {
Body []Statement // function body
Name Expr // function name
Params []*Ident // parameters
DefaultArgs []Expr // default arguments
Attr FuncAttr // function attributes
EndFunction *EndFunction // :endfunction
}
Expand Down Expand Up @@ -119,6 +120,7 @@ func (f *ExCall) Pos() Pos { return f.ExCall }
func (f *ExCall) Cmd() Cmd { return *f.ExArg.Cmd }

// vimlparser: LET .ea .op .left .list .rest .right
// vimlparser: CONST .ea .op .left .list .rest .right
type Let struct {
Let Pos // position of starting the :let
ExArg ExArg // Ex command arg
Expand Down Expand Up @@ -341,6 +343,17 @@ type Throw struct {
func (f *Throw) Pos() Pos { return f.Throw }
func (f *Throw) Cmd() Cmd { return *f.ExArg.Cmd }

// vimlparser: EVAL .ea .left
// :eval {Expr}
type Eval struct {
Eval Pos // position of starting the :eval
ExArg ExArg // Ex command arg
Expr Expr
}

func (f *Eval) Pos() Pos { return f.Eval }
func (f *Eval) Cmd() Cmd { return *f.ExArg.Cmd }

// vimlparser: ECHO .ea .list
// vimlparser: ECHON .ea .list
// vimlparser: ECHOMSG .ea .list
Expand Down Expand Up @@ -426,6 +439,16 @@ type SliceExpr struct {

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

// vimlparser: METHOD .left .right
type MethodExpr struct {
Left Expr // this object
Method Expr // method
Lparen Pos // position of "("
Args []Expr // function arguments; or nil
}

func (c *MethodExpr) Pos() Pos { return c.Lparen }

// vimlparser: CALL .left .rlist
type CallExpr struct {
Fun Expr // function expression
Expand Down Expand Up @@ -516,7 +539,7 @@ type Ident struct {
func (i *Ident) Pos() Pos { return i.NamePos }

// LambdaExpr node represents lambda.
// vimlparsr: LAMBDA .rlist .left
// vimlparser: LAMBDA .rlist .left
// { Params -> Expr }
type LambdaExpr struct {
Lcurlybrace Pos // position of "{"
Expand All @@ -527,14 +550,25 @@ type LambdaExpr struct {
func (i *LambdaExpr) Pos() Pos { return i.Lcurlybrace }

// ParenExpr node represents a parenthesized expression.
// vimlparsr: PARENEXPR .value
// vimlparser: PARENEXPR .value
type ParenExpr struct {
Lparen Pos // position of "("
X Expr // parenthesized expression
}

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

// HeredocExpr node represents a heredoc expression.
// vimlparser: HEREDOC .rlist .op .body
type HeredocExpr struct {
OpPos Pos // position of "=<<"
Flags []Expr // modifiers [trim]; or nil
EndMarker string // {endmarker}
Body []Expr // body
}

func (i *HeredocExpr) Pos() Pos { return i.OpPos }

// stmtNode() ensures that only ExComamnd and Comment nodes can be assigned to
// an Statement.
//
Expand Down Expand Up @@ -562,6 +596,7 @@ func (*Let) stmtNode() {}
func (*LockVar) stmtNode() {}
func (*Return) stmtNode() {}
func (*Throw) stmtNode() {}
func (*Eval) stmtNode() {}
func (*Try) stmtNode() {}
func (*UnLet) stmtNode() {}
func (*UnLockVar) stmtNode() {}
Expand All @@ -576,6 +611,7 @@ func (*BinaryExpr) exprNode() {}
func (*UnaryExpr) exprNode() {}
func (*SubscriptExpr) exprNode() {}
func (*SliceExpr) exprNode() {}
func (*MethodExpr) exprNode() {}
func (*CallExpr) exprNode() {}
func (*DotExpr) exprNode() {}
func (*BasicLit) exprNode() {}
Expand All @@ -587,3 +623,4 @@ func (*CurlyNameExpr) exprNode() {}
func (*Ident) exprNode() {}
func (*LambdaExpr) exprNode() {}
func (*ParenExpr) exprNode() {}
func (*HeredocExpr) exprNode() {}
12 changes: 12 additions & 0 deletions ast/walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ func Walk(v Visitor, node Node) {
case *Throw:
Walk(v, n.Expr)

case *Eval:
Walk(v, n.Expr)

case *EchoCmd:
walkExprList(v, n.Exprs)

Expand Down Expand Up @@ -164,6 +167,11 @@ func Walk(v Visitor, node Node) {
Walk(v, n.Low)
Walk(v, n.High)

case *MethodExpr:
Walk(v, n.Left)
Walk(v, n.Method)
walkExprList(v, n.Args)

case *CallExpr:
Walk(v, n.Fun)
walkExprList(v, n.Args)
Expand Down Expand Up @@ -201,6 +209,10 @@ func Walk(v Visitor, node Node) {
case *ParenExpr:
Walk(v, n.X)

case *HeredocExpr:
walkExprList(v, n.Flags)
walkExprList(v, n.Body)

default:
panic(fmt.Sprintf("ast.Walk: unexpected node type %T", n))
}
Expand Down
Loading