mirror of
https://github.com/hanzoai/expr.git
synced 2026-09-24 16:58:58 +00:00
19 lines
261 B
Go
19 lines
261 B
Go
package ast
|
|
|
|
func Find(node Node, fn func(node Node) bool) Node {
|
|
v := &finder{fn: fn}
|
|
Walk(&node, v)
|
|
return v.node
|
|
}
|
|
|
|
type finder struct {
|
|
node Node
|
|
fn func(node Node) bool
|
|
}
|
|
|
|
func (f *finder) Visit(node *Node) {
|
|
if f.fn(*node) {
|
|
f.node = *node
|
|
}
|
|
}
|