Back to index

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

List of all members.

Public Member Functions

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

Public Attributes

 content
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Static Public Attributes

 type = None
 name = None

Detailed Description

Definition at line 827 of file pytree.py.


Constructor & Destructor Documentation

def lib2to3.pytree.NegatedPattern.__init__ (   self,
  content = None 
)
Initializer.

The argument is either a pattern or None.  If it is None, this
only matches an empty sequence (effectively '$' in regex
lingo).  If it is not None, this matches whenever the argument
pattern doesn't have any matches.

Definition at line 829 of file pytree.py.

00829 
00830     def __init__(self, content=None):
00831         """
00832         Initializer.
00833 
00834         The argument is either a pattern or None.  If it is None, this
00835         only matches an empty sequence (effectively '$' in regex
00836         lingo).  If it is not None, this matches whenever the argument
00837         pattern doesn't have any matches.
00838         """
00839         if content is not None:
00840             assert isinstance(content, BasePattern), repr(content)
00841         self.content = content

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:

Generator yielding all matches for this pattern.

Default implementation for non-wildcard patterns.

Reimplemented from lib2to3.pytree.BasePattern.

Definition at line 850 of file pytree.py.

00850 
00851     def generate_matches(self, nodes):
00852         if self.content is None:
00853             # Return a match if there is an empty sequence
00854             if len(nodes) == 0:
00855                 yield 0, {}
00856         else:
00857             # Return a match if the argument pattern has no matches
00858             for c, r in self.content.generate_matches(nodes):
00859                 return
00860             yield 0, {}
00861 

def lib2to3.pytree.BasePattern.match (   self,
  node,
  results = None 
) [inherited]
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.

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

Definition at line 488 of file pytree.py.

00488 
00489     def match(self, node, results=None):
00490         """
00491         Does this pattern exactly match a node?
00492 
00493         Returns True if it matches, False if not.
00494 
00495         If results is not None, it must be a dict which will be
00496         updated with the nodes matching named subpatterns.
00497 
00498         Default implementation for non-wildcard patterns.
00499         """
00500         if self.type is not None and node.type != self.type:
00501             return False
00502         if self.content is not None:
00503             r = None
00504             if results is not None:
00505                 r = {}
00506             if not self._submatch(node, r):
00507                 return False
00508             if r:
00509                 results.update(r)
00510         if results is not None and self.name:
00511             results[self.name] = node
00512         return True

Here is the call graph for this function:

Here is the caller graph for this function:

def lib2to3.pytree.NegatedPattern.match (   self,
  node 
)

Definition at line 842 of file pytree.py.

00842 
00843     def match(self, node):
00844         # We never match a node in its entirety
00845         return False

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.NegatedPattern.match_seq (   self,
  nodes 
)

Definition at line 846 of file pytree.py.

00846 
00847     def match_seq(self, nodes):
00848         # We only match an empty sequence of nodes in its entirety
00849         return len(nodes) == 0

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 840 of file pytree.py.

lib2to3.pytree.BasePattern.name = None [static, inherited]

Definition at line 107 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.

lib2to3.pytree.BasePattern.type = None [static, inherited]

Reimplemented in lib2to3.pytree.NodePattern, and lib2to3.pytree.LeafPattern.

Definition at line 465 of file pytree.py.


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