class documentation

A pattern is a tree matching pattern. It looks for a specific node type (token or symbol), and optionally for a specific content. This is an abstract base class. There are three concrete subclasses: - LeafPattern matches a single leaf node; - NodePattern matches a single node (usually non-leaf); - WildcardPattern matches a sequence of nodes of variable length.

Method __new__ Constructor that prevents BasePattern from being instantiated.
Method __repr__ Undocumented
Method generate_matches Generator yielding all matches for this pattern.
Method match Does this pattern exactly match a node?
Method match_seq Does this pattern exactly match a sequence of nodes?
Method optimize A subclass can define this as a hook for optimizations.
Class Variable content Undocumented
Class Variable name Undocumented
Class Variable type Undocumented
Property type_repr Get the type as a human-readable string.
def __new__(cls, *args, **kwds): (source)

Constructor that prevents BasePattern from being instantiated.

def __repr__(self): (source)

Undocumented

def generate_matches(self, nodes): (source)

Generator yielding all matches for this pattern. Default implementation for non-wildcard patterns.

def match(self, node, results=None): (source)

Does this pattern exactly match a node? Returns True if it matches, False if not. If results is not None, it must be a dict which will be updated with the nodes matching named subpatterns. Default implementation for non-wildcard patterns.

def match_seq(self, nodes, results=None): (source)

Does this pattern exactly match a sequence of nodes? Default implementation for non-wildcard patterns.

def optimize(self): (source)

A subclass can define this as a hook for optimizations. Returns either self or another node with the same effect.

Get the type as a human-readable string.