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.
193
193
For example if you want to collect all variable names:
194
194
195
195
``` 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
+ )
197
202
198
203
type visitor struct {
199
204
identifiers []string
@@ -206,11 +211,12 @@ func (v *visitor) Exit(node *ast.Node) {
206
211
}
207
212
}
208
213
209
- program , err := expr.Compile (" foo + bar" , expr.Env (env))
214
+ func main () {
215
+ tree , err := parser.Parse (" foo + bar" )
210
216
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)
215
219
220
+ fmt.Printf (" %v " , visitor.identifiers ) // outputs [foo bar]
221
+ }
216
222
```
You can’t perform that action at this time.
0 commit comments