| | |
- ASTVisitor
-
- ExampleASTVisitor
class ASTVisitor |
| |
Performs a depth-first walk of the AST
The ASTVisitor will walk the AST, performing either a preorder or
postorder traversal depending on which method is called.
methods:
preorder(tree, visitor)
postorder(tree, visitor)
tree: an instance of ast.Node
visitor: an instance with visitXXX methods
The ASTVisitor is responsible for walking over the tree in the
correct order. For each node, it checks the visitor argument for
a method named 'visitNodeType' where NodeType is the name of the
node's class, e.g. Class. If the method exists, it is called
with the node as its sole argument.
The visitor method for a particular node type can control how
child nodes are visited during a preorder walk. (It can't control
the order during a postorder walk, because it is called _after_
the walk has occurred.) The ASTVisitor modifies the visitor
argument by adding a visit method to the visitor; this method can
be used to visit a child node of arbitrary type. |
| |
Methods defined here:
- __init__(self)
- default(self, node, *args)
- dispatch(self, node, *args)
- preorder(self, tree, visitor, *args)
- Do preorder walk of tree using visitor
Data and other attributes defined here:
- VERBOSE = 0
|
class ExampleASTVisitor(ASTVisitor) |
| |
Prints examples of the nodes that aren't visited
This visitor-driver is only useful for development, when it's
helpful to develop a visitor incremently, and get feedback on what
you still have to do. |
| |
Methods defined here:
- dispatch(self, node, *args)
Data and other attributes defined here:
- examples = {}
Methods inherited from ASTVisitor:
- __init__(self)
- default(self, node, *args)
- preorder(self, tree, visitor, *args)
- Do preorder walk of tree using visitor
Data and other attributes inherited from ASTVisitor:
- VERBOSE = 0
| |