File tree Expand file tree Collapse file tree 1 file changed +12
-6
lines changed
Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -193,7 +193,12 @@ You can use it for traveling ast tree of compiled program.
193193For example if you want to collect all variable names:
194194
195195``` go
196- import " github.com/antonmedv/expr/ast"
196+ package main
197+ import (
198+ " fmt"
199+ " github.com/antonmedv/expr/ast"
200+ " github.com/antonmedv/expr/parser"
201+ )
197202
198203type visitor struct {
199204 identifiers []string
@@ -206,11 +211,12 @@ func (v *visitor) Exit(node *ast.Node) {
206211 }
207212}
208213
209- program , err := expr.Compile (" foo + bar" , expr.Env (env))
214+ func main () {
215+ tree , err := parser.Parse (" foo + bar" )
210216
211- visitor := &visitor{}
212- ast.Walk (node, visitor)
213-
214- fmt.Printf (" %v " , visitor.identifiers ) // outputs [foo bar]
217+ visitor := &visitor{}
218+ ast.Walk (&tree.Node , visitor)
215219
220+ fmt.Printf (" %v " , visitor.identifiers ) // outputs [foo bar]
221+ }
216222```
You can’t perform that action at this time.
0 commit comments