Skip to content

Commit 32c42a9

Browse files
committed
implement Eval
1 parent 7b9a7fe commit 32c42a9

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

ast/node.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,17 @@ type Throw struct {
342342
func (f *Throw) Pos() Pos { return f.Throw }
343343
func (f *Throw) Cmd() Cmd { return *f.ExArg.Cmd }
344344

345+
// vimlparser: EVAL .ea .left
346+
// :eval {Expr}
347+
type Eval struct {
348+
Eval Pos // position of starting the :eval
349+
ExArg ExArg // Ex command arg
350+
Expr Expr
351+
}
352+
353+
func (f *Eval) Pos() Pos { return f.Eval }
354+
func (f *Eval) Cmd() Cmd { return *f.ExArg.Cmd }
355+
345356
// vimlparser: ECHO .ea .list
346357
// vimlparser: ECHON .ea .list
347358
// vimlparser: ECHOMSG .ea .list
@@ -584,6 +595,7 @@ func (*Let) stmtNode() {}
584595
func (*LockVar) stmtNode() {}
585596
func (*Return) stmtNode() {}
586597
func (*Throw) stmtNode() {}
598+
func (*Eval) stmtNode() {}
587599
func (*Try) stmtNode() {}
588600
func (*UnLet) stmtNode() {}
589601
func (*UnLockVar) stmtNode() {}

ast/walk.go

Lines changed: 3 additions & 0 deletions
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

compiler/compiler.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ func (c *Compiler) compileExcommand(node ast.ExCommand) error {
129129
c.compileTry(n)
130130
case *ast.Throw:
131131
c.compileThrow(n)
132+
case *ast.Eval:
133+
c.compileEval(n)
132134
case *ast.EchoCmd:
133135
c.compileEchocmd(n)
134136
case *ast.Echohl:
@@ -332,6 +334,11 @@ func (c *Compiler) compileThrow(node *ast.Throw) {
332334
c.fprintln("(%s %s)", cmd, c.compileExpr(node.Expr))
333335
}
334336

337+
func (c *Compiler) compileEval(node *ast.Eval) {
338+
cmd := node.Cmd().Name
339+
c.fprintln("(%s %s)", cmd, c.compileExpr(node.Expr))
340+
}
341+
335342
func (c *Compiler) compileEchocmd(node *ast.EchoCmd) {
336343
cmd := node.Cmd().Name
337344
exprs := make([]string, 0, len(node.Exprs))

go/export.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,13 @@ func newAstNode(n *VimNode, filename string) ast.Node {
275275
Expr: newExprNode(n.left, filename),
276276
}
277277

278+
case NODE_EVAL:
279+
return &ast.Eval{
280+
Eval: pos,
281+
ExArg: newExArg(*n.ea, filename),
282+
Expr: newExprNode(n.left, filename),
283+
}
284+
278285
case NODE_ECHO, NODE_ECHON, NODE_ECHOMSG, NODE_ECHOERR:
279286
return &ast.EchoCmd{
280287
Start: pos,

0 commit comments

Comments
 (0)