Commit 9384fdc9 authored by Robert Griesemer's avatar Robert Griesemer

go/ast: add Inspect function for easy AST inspection w/o a visitor

R=rsc
CC=golang-dev
https://golang.org/cl/2770044
parent 035696c5
......@@ -321,3 +321,22 @@ func Walk(v Visitor, node interface{}) {
v.Visit(nil)
}
type inspector func(node interface{}) bool
func (f inspector) Visit(node interface{}) Visitor {
if node != nil && f(node) {
return f
}
return nil
}
// Inspect traverses an AST in depth-first order: If node != nil, it
// invokes f(node). If f returns true, inspect invokes f for all the
// non-nil children of node, recursively.
//
func Inspect(ast interface{}, f func(node interface{}) bool) {
Walk(inspector(f), ast)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment