From e7d45749ffd0811a3bc7e28919e2ecf5eeb853af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vytautas=20=C5=A0altenis?= Date: Tue, 5 Apr 2016 10:08:50 +0300 Subject: [PATCH] Give node visitor callback type a name and docs --- node.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/node.go b/node.go index 9bb2df4..c565d5c 100644 --- a/node.go +++ b/node.go @@ -230,7 +230,12 @@ func (n *Node) canContain(t NodeType) bool { return false } -func (root *Node) Walk(visitor func(node *Node, entering bool)) { +// NodeVisitor is a callback to be called when traversing the syntax tree. +// Called twice for every node: once with entering=true when the branch is +// first visited, then with entering=false after all the children are done. +type NodeVisitor func(node *Node, entering bool) + +func (root *Node) Walk(visitor NodeVisitor) { walker := NewNodeWalker(root) node, entering := walker.next() for node != nil {