Back to index

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

List of all members.

Public Member Functions

def __init__
def __repr__
def leaf_to_root
def get_linear_subpattern
def leaves

Public Attributes

 type
 name
 children
 leaf
 parent
 alternatives
 group
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Detailed Description

This class serves as an intermediate representation of the
pattern tree during the conversion to sets of leaf-to-root
subpatterns

Definition at line 16 of file btm_utils.py.


Constructor & Destructor Documentation

def lib2to3.btm_utils.MinNode.__init__ (   self,
  type = None,
  name = None 
)

Definition at line 21 of file btm_utils.py.

00021 
00022     def __init__(self, type=None, name=None):
00023         self.type = type
00024         self.name = name
00025         self.children = []
00026         self.leaf = False
00027         self.parent = None
00028         self.alternatives = []
00029         self.group = []

Here is the caller graph for this function:


Member Function Documentation

Definition at line 30 of file btm_utils.py.

00030 
00031     def __repr__(self):
00032         return str(self.type) + ' ' + str(self.name)

Drives the leaf_to_root method. The reason that
leaf_to_root must be run multiple times is because we need to
reject 'group' matches; for example the alternative form
(a | b c) creates a group [b c] that needs to be matched. Since
matching multiple linear patterns overcomes the automaton's
capabilities, leaf_to_root merges each group into a single
choice based on 'characteristic'ity,

i.e. (a|b c) -> (a|b) if b more characteristic than c

Returns: The most 'characteristic'(as defined by
  get_characteristic_subpattern) path for the compiled pattern
  tree.

Definition at line 75 of file btm_utils.py.

00075 
00076     def get_linear_subpattern(self):
00077         """Drives the leaf_to_root method. The reason that
00078         leaf_to_root must be run multiple times is because we need to
00079         reject 'group' matches; for example the alternative form
00080         (a | b c) creates a group [b c] that needs to be matched. Since
00081         matching multiple linear patterns overcomes the automaton's
00082         capabilities, leaf_to_root merges each group into a single
00083         choice based on 'characteristic'ity,
00084 
00085         i.e. (a|b c) -> (a|b) if b more characteristic than c
00086 
00087         Returns: The most 'characteristic'(as defined by
00088           get_characteristic_subpattern) path for the compiled pattern
00089           tree.
00090         """
00091 
00092         for l in self.leaves():
00093             subp = l.leaf_to_root()
00094             if subp:
00095                 return subp

Here is the call graph for this function:

Internal method. Returns a characteristic path of the
pattern tree. This method must be run for all leaves until the
linear subpatterns are merged into a single

Definition at line 33 of file btm_utils.py.

00033 
00034     def leaf_to_root(self):
00035         """Internal method. Returns a characteristic path of the
00036         pattern tree. This method must be run for all leaves until the
00037         linear subpatterns are merged into a single"""
00038         node = self
00039         subp = []
00040         while node:
00041             if node.type == TYPE_ALTERNATIVES:
00042                 node.alternatives.append(subp)
00043                 if len(node.alternatives) == len(node.children):
00044                     #last alternative
00045                     subp = [tuple(node.alternatives)]
00046                     node.alternatives = []
00047                     node = node.parent
00048                     continue
00049                 else:
00050                     node = node.parent
00051                     subp = None
00052                     break
00053 
00054             if node.type == TYPE_GROUP:
00055                 node.group.append(subp)
00056                 #probably should check the number of leaves
00057                 if len(node.group) == len(node.children):
00058                     subp = get_characteristic_subpattern(node.group)
00059                     node.group = []
00060                     node = node.parent
00061                     continue
00062                 else:
00063                     node = node.parent
00064                     subp = None
00065                     break
00066 
00067             if node.type == token_labels.NAME and node.name:
00068                 #in case of type=name, use the name instead
00069                 subp.append(node.name)
00070             else:
00071                 subp.append(node.type)
00072 
00073             node = node.parent
00074         return subp

Here is the call graph for this function:

Definition at line 96 of file btm_utils.py.

00096 
00097     def leaves(self):
00098         "Generator that returns the leaves of the tree"
00099         for child in self.children:
00100             for x in child.leaves():
00101                 yield x
00102         if not self.children:
00103             yield self

Here is the caller graph for this function:


Member Data Documentation

Definition at line 27 of file btm_utils.py.

Definition at line 24 of file btm_utils.py.

Definition at line 28 of file btm_utils.py.

Definition at line 25 of file btm_utils.py.

Definition at line 23 of file btm_utils.py.

Definition at line 107 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.

Definition at line 26 of file btm_utils.py.

Definition at line 22 of file btm_utils.py.


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