class documentation

class LeafPattern(BasePattern): (source)

View In Hierarchy

Undocumented

Method __init__ Initializer. Takes optional type, content, and name.
Method match Override match() to insist on a leaf node.
Instance Variable content Undocumented
Instance Variable name Undocumented
Instance Variable type 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_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 token type (< 256). If not given, this matches any *leaf* node; the content may still be required. The content, if given, must be a string. If a name is given, the matching node is stored in the results dict under that key.

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

Override match() to insist on a leaf node.

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.