aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/ast
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/ast')
-rw-r--r--pkg/ast/walk.go11
1 files changed, 10 insertions, 1 deletions
diff --git a/pkg/ast/walk.go b/pkg/ast/walk.go
index fe9112578..1ec3a8fc6 100644
--- a/pkg/ast/walk.go
+++ b/pkg/ast/walk.go
@@ -4,7 +4,7 @@
package ast
// Walk calls callback cb for every top-level node in description.
-// Note: it's not recursive. Use Recursive helper for recursive walk.
+// Note: it's not recursive. Use Recursive/PostRecursive helpers for recursive walk.
func (desc *Description) Walk(cb func(Node)) {
for _, n := range desc.Nodes {
cb(n)
@@ -20,6 +20,15 @@ func Recursive(cb func(Node)) func(Node) {
return rec
}
+func PostRecursive(cb func(Node)) func(Node) {
+ var rec func(Node)
+ rec = func(n Node) {
+ n.Walk(rec)
+ cb(n)
+ }
+ return rec
+}
+
func (n *NewLine) Walk(cb func(Node)) {}
func (n *Comment) Walk(cb func(Node)) {}
func (n *Ident) Walk(cb func(Node)) {}