class documentation

class NodePattern(BasePattern): (source)

View In Hierarchy

Undocumented

Method __init__ Initializer. Takes optional type, content, and name.
Instance Variable content Undocumented
Instance Variable name Undocumented
Instance Variable type Undocumented
Instance Variable wildcards Undocumented
Method _submatch Match the pattern's content to the node's children.

Inherited from BasePattern:

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.
Property type_repr Get the type as a human-readable string.
def __init__(self, type=None, content=None, name=None): (source)

Initializer. Takes optional type, content, and name. The type, if given, must be a symbol type (>= 256). If the type is None this matches *any* single node (leaf or not), except if content is not None, in which it only matches non-leaf nodes that also match the content pattern. The content, if not None, must be a sequence of Patterns that must match the node's children exactly. If the content is given, the type must not be None. If a name is given, the matching node is stored in the results dict under that key.

wildcards: bool = (source)

Undocumented

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

Match the pattern's content to the node's children. This assumes the node type matches and self.content is not None. 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. When returning False, the results dict may still be updated.