Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 198314c80f
Fetching contributors…

Cannot retrieve contributors at this time

file 70 lines (41 sloc) 1.844 kb

Tree::Walker - A tool for traversing trees.

Tree::Walker and its subclasses use multi-methods to traverse trees and perform some operation on them.

Trees are represented as Captures or subclasses of Capture.

This conveniently includes PCT::Node and its subclasses PAST::Node and POST::Node.

The Tree::Walker interface is specified by a pair of multi-subs.

The default for both of these takes a Tree::Walker and a Capture. In addition, there are Tree::Walker methods of the same name as each multi-method that take a tree argument and call the appropriate multi-sub with the invocant and the tree.

By default, 'walk' simply calls 'walkChildren' with the same arguments.

Subclasses should specialize this multi-sub in order to act on the traversed nodes.

Subclasses that wish to traverse the node's children must remember fo call 'walkChildren' in their implementations of the multi-sub.

Iterates through the children of tree, calling 'walk' with the walker and each child tree.

This should not typically be overridden.

However, in some rare situations, subclasses may wish to override walkChildren (for example, in order to add support for traversing new kinds of trees).

Convenience methods are provided for Tree::Walker objects are provided to make traversing trees more convenient in code outside of the Tree::Walker namespace.

walker.walk(tree) is equivalent to Tree::Walker::walk(walker, tree).

walker.walkChildren(tree) is equivalent to Tree::Walker::walkChildren(walker, tree).

Something went wrong with that request. Please try again.