Skip to content

Commit 2acac39

Browse files
committed
Update docs
1 parent 92a87de commit 2acac39

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

docs/Usage.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,12 @@ You can use it for traveling ast tree of compiled program.
193193
For 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

198203
type 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
```

0 commit comments

Comments
 (0)