Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Private Member Functions
lib2to3.pytree.LeafPattern Class Reference
Inheritance diagram for lib2to3.pytree.LeafPattern:
Inheritance graph
[legend]
Collaboration diagram for lib2to3.pytree.LeafPattern:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def match
def __new__
def __repr__
def optimize
def match_seq
def generate_matches

Public Attributes

 type
 content
 name
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Private Member Functions

def _submatch

Detailed Description

Definition at line 534 of file pytree.py.


Constructor & Destructor Documentation

def lib2to3.pytree.LeafPattern.__init__ (   self,
  type = None,
  content = None,
  name = None 
)
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.

Definition at line 536 of file pytree.py.

00536 
00537     def __init__(self, type=None, content=None, name=None):
00538         """
00539         Initializer.  Takes optional type, content, and name.
00540 
00541         The type, if given must be a token type (< 256).  If not given,
00542         this matches any *leaf* node; the content may still be required.
00543 
00544         The content, if given, must be a string.
00545 
00546         If a name is given, the matching node is stored in the results
00547         dict under that key.
00548         """
00549         if type is not None:
00550             assert 0 <= type < 256, type
00551         if content is not None:
00552             assert isinstance(content, str), repr(content)
00553         self.type = type
00554         self.content = content
00555         self.name = name

Here is the caller graph for this function:


Member Function Documentation

def lib2to3.pytree.BasePattern.__new__ (   cls,
  args,
  kwds 
) [inherited]
Constructor that prevents BasePattern from being instantiated.

Definition at line 469 of file pytree.py.

00469 
00470     def __new__(cls, *args, **kwds):
00471         """Constructor that prevents BasePattern from being instantiated."""
00472         assert cls is not BasePattern, "Cannot instantiate BasePattern"
00473         return object.__new__(cls)

def lib2to3.pytree.BasePattern.__repr__ (   self) [inherited]

Definition at line 474 of file pytree.py.

00474 
00475     def __repr__(self):
00476         args = [type_repr(self.type), self.content, self.name]
00477         while args and args[-1] is None:
00478             del args[-1]
00479         return "%s(%s)" % (self.__class__.__name__, ", ".join(map(repr, args)))

Here is the call graph for this function:

def lib2to3.pytree.LeafPattern._submatch (   self,
  node,
  results = None 
) [private]
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.

Definition at line 562 of file pytree.py.

00562 
00563     def _submatch(self, node, results=None):
00564         """
00565         Match the pattern's content to the node's children.
00566 
00567         This assumes the node type matches and self.content is not None.
00568 
00569         Returns True if it matches, False if not.
00570 
00571         If results is not None, it must be a dict which will be
00572         updated with the nodes matching named subpatterns.
00573 
00574         When returning False, the results dict may still be updated.
00575         """
00576         return self.content == node.value
00577 

Here is the caller graph for this function:

def lib2to3.pytree.BasePattern.generate_matches (   self,
  nodes 
) [inherited]
Generator yielding all matches for this pattern.

Default implementation for non-wildcard patterns.

Reimplemented in lib2to3.pytree.NegatedPattern, and lib2to3.pytree.WildcardPattern.

Definition at line 523 of file pytree.py.

00523 
00524     def generate_matches(self, nodes):
00525         """
00526         Generator yielding all matches for this pattern.
00527 
00528         Default implementation for non-wildcard patterns.
00529         """
00530         r = {}
00531         if nodes and self.match(nodes[0], r):
00532             yield 1, r
00533 

Here is the call graph for this function:

Here is the caller graph for this function:

def lib2to3.pytree.LeafPattern.match (   self,
  node,
  results = None 
)
Override match() to insist on a leaf node.

Reimplemented from lib2to3.pytree.BasePattern.

Definition at line 556 of file pytree.py.

00556 
00557     def match(self, node, results=None):
00558         """Override match() to insist on a leaf node."""
00559         if not isinstance(node, Leaf):
00560             return False
00561         return BasePattern.match(self, node, results)

def lib2to3.pytree.BasePattern.match_seq (   self,
  nodes,
  results = None 
) [inherited]
Does this pattern exactly match a sequence of nodes?

Default implementation for non-wildcard patterns.

Reimplemented in lib2to3.pytree.WildcardPattern.

Definition at line 513 of file pytree.py.

00513 
00514     def match_seq(self, nodes, results=None):
00515         """
00516         Does this pattern exactly match a sequence of nodes?
00517 
00518         Default implementation for non-wildcard patterns.
00519         """
00520         if len(nodes) != 1:
00521             return False
00522         return self.match(nodes[0], results)

Here is the call graph for this function:

Here is the caller graph for this function:

def lib2to3.pytree.BasePattern.optimize (   self) [inherited]
A subclass can define this as a hook for optimizations.

Returns either self or another node with the same effect.

Reimplemented in lib2to3.pytree.WildcardPattern.

Definition at line 480 of file pytree.py.

00480 
00481     def optimize(self):
00482         """
00483         A subclass can define this as a hook for optimizations.
00484 
00485         Returns either self or another node with the same effect.
00486         """
00487         return self


Member Data Documentation

Reimplemented from lib2to3.pytree.BasePattern.

Definition at line 553 of file pytree.py.

Reimplemented from lib2to3.pytree.BasePattern.

Definition at line 554 of file pytree.py.

Definition at line 107 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.

Reimplemented from lib2to3.pytree.BasePattern.

Definition at line 552 of file pytree.py.


The documentation for this class was generated from the following file: