This file defines classes for different kinds of nodes of an Abstract Syntax Tree. In general, you will have a different AST node for each kind of grammar rule.

This file has a small bit of metaprogramming to simplify specification and to perform some validation steps.

class scim2_filter_parser.ast.NodeVisitor

Class for visiting nodes of the parse tree. This is modeled after a similar class in the standard library ast.NodeVisitor. For each node, the visit(node) method calls a method visit_NodeName(node) which should be implemented in subclasses. The generic_visit() method is called for all nodes where there is no matching visit_NodeName() method.

Here is a example of a visitor that examines binary operators:

class VisitOps(NodeVisitor):
        print('Binary operator', node.op)
        print('Unary operator', node.op)

tree = parse(txt)

Method executed if no applicable visit_ method can be found. This examines the node to see if it has _fields, is a list, or can be further traversed.


Execute a method of the form visit_NodeName(node) where NodeName is the name of the class of a particular node.

class scim2_filter_parser.ast.VisitDict

Flatten the entire parse tree into a list for the purposes of debugging and testing. This returns a list of tuples of the form (depth, node) where depth is an integer representing the parse tree depth and node is the associated AST node.