Skip to content

Commit a142a71

Browse files
committed
Update visitor docs
1 parent 18450eb commit a142a71

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

docs/Usage.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,14 @@ For example if you want to collect all variable names:
196196
import "github.com/antonmedv/expr/ast"
197197

198198
type visitor struct {
199-
ast.BaseVisitor
200199
identifiers []string
201200
}
202201

203-
func (v *visitor) IdentifierNode(node *ast.IdentifierNode) {
204-
v.identifiers = append(v.identifiers, node.Value)
202+
func (v *visitor) Enter(node *ast.Node) {}
203+
func (v *visitor) Exit(node *ast.Node) {
204+
if v, ok := node.(*ast.IdentifierNode); ok {
205+
v.identifiers = append(v.identifiers, node.Value)
206+
}
205207
}
206208

207209
program, err := expr.Compile("foo + bar", expr.Env(env))

0 commit comments

Comments
 (0)