class documentation

The TreeWalk class can be used as a superclass in order to walk an AST or similar tree. Unlike other treewalkers, this class can walk a tree either recursively or non-recursively. Subclasses can define methods with the following signatures:: def pre_xxx(self): pass def post_xxx(self): pass def init_xxx(self): pass Where 'xxx' is one of: - A class name - An attribute member name concatenated with '_name' For example, 'pre_targets_name' will process nodes that are referenced by the name 'targets' in their parent's node. - An attribute member name concatenated with '_item' For example, 'pre_targets_item' will process nodes that are in a list that is the targets attribute of some node. pre_xxx will process a node before processing any of its subnodes. if the return value from pre_xxx evalates to true, then walk will not process any of the subnodes. Those can be manually processed, if desired, by calling self.walk(node) on the subnodes before returning True. post_xxx will process a node after processing all its subnodes. init_xxx methods can decorate the class instance with subclass-specific information. A single init_whatever method could be written, but to make it easy to keep initialization with use, any number of init_xxx methods can be written. They will be called in alphabetical order.

Method __init__ Undocumented
Method replace Replace a node after first checking integrity of node stack.
Method setup All the node-specific handlers are setup at object initialization time.
Method walk Walk the tree starting at a given node.
Instance Variable cur_name Undocumented
Instance Variable cur_node Undocumented
Instance Variable nodestack Undocumented
Instance Variable post_handlers Undocumented
Instance Variable pre_handlers Undocumented
Property parent Return the parent node of the current node.
Property parent_name Return the parent node and name.

Inherited from MetaFlatten:

Method __new__ Undocumented
def __init__(self, node=None): (source)

Undocumented

def replace(self, new_node): (source)

Replace a node after first checking integrity of node stack.

def setup(self): (source)

All the node-specific handlers are setup at object initialization time.

def walk(self, node, name='', list=list, len=len, type=type): (source)

Walk the tree starting at a given node. Maintain a stack of nodes.

cur_name = (source)

Undocumented

cur_node = (source)

Undocumented

nodestack: list = (source)

Undocumented

post_handlers: dict = (source)

Undocumented

pre_handlers: dict = (source)

Undocumented

Return the parent node of the current node.

@property
parent_name = (source)

Return the parent node and name.