Back to index

python3.2  3.2.2
Classes | Functions | Variables
lib2to3.pytree Namespace Reference

Classes

class  Base
class  Node
class  Leaf
class  BasePattern
class  LeafPattern
class  NodePattern
class  WildcardPattern
class  NegatedPattern

Functions

def type_repr
def convert
def generate_matches

Variables

string __author__ = "Guido van Rossum <guido@python.org>"
int HUGE = 0x7FFFFFFF
dictionary _type_reprs = {}

Function Documentation

def lib2to3.pytree.convert (   gr,
  raw_node 
)
Convert raw node information to a Node or Leaf instance.

This is passed to the parser driver which calls it whenever a reduction of a
grammar rule produces a new complete node, so that the tree is build
strictly bottom-up.

Definition at line 429 of file pytree.py.

00429 
00430 def convert(gr, raw_node):
00431     """
00432     Convert raw node information to a Node or Leaf instance.
00433 
00434     This is passed to the parser driver which calls it whenever a reduction of a
00435     grammar rule produces a new complete node, so that the tree is build
00436     strictly bottom-up.
00437     """
00438     type, value, context, children = raw_node
00439     if children or type in gr.number2symbol:
00440         # If there's exactly one child, return that child instead of
00441         # creating a new node.
00442         if len(children) == 1:
00443             return children[0]
00444         return Node(type, children, context=context)
00445     else:
00446         return Leaf(type, value, context=context)
00447 

def lib2to3.pytree.generate_matches (   patterns,
  nodes 
)
Generator yielding matches for a sequence of patterns and nodes.

Args:
    patterns: a sequence of patterns
    nodes: a sequence of nodes

Yields:
    (count, results) tuples where:
    count: the entire sequence of patterns matches nodes[:count];
    results: dict containing named submatches.

Definition at line 862 of file pytree.py.

00862 
00863 def generate_matches(patterns, nodes):
00864     """
00865     Generator yielding matches for a sequence of patterns and nodes.
00866 
00867     Args:
00868         patterns: a sequence of patterns
00869         nodes: a sequence of nodes
00870 
00871     Yields:
00872         (count, results) tuples where:
00873         count: the entire sequence of patterns matches nodes[:count];
00874         results: dict containing named submatches.
00875         """
00876     if not patterns:
00877         yield 0, {}
00878     else:
00879         p, rest = patterns[0], patterns[1:]
00880         for c0, r0 in p.generate_matches(nodes):
00881             if not rest:
00882                 yield c0, r0
00883             else:
00884                 for c1, r1 in generate_matches(rest, nodes[c0:]):
00885                     r = {}
00886                     r.update(r0)
00887                     r.update(r1)
00888                     yield c0 + c1, r
def lib2to3.pytree.type_repr (   type_num)

Definition at line 22 of file pytree.py.

00022 
00023 def type_repr(type_num):
00024     global _type_reprs
00025     if not _type_reprs:
00026         from .pygram import python_symbols
00027         # printing tokens is possible but not as useful
00028         # from .pgen2 import token // token.__dict__.items():
00029         for name, val in python_symbols.__dict__.items():
00030             if type(val) == int: _type_reprs[val] = name
00031     return _type_reprs.setdefault(type_num, type_num)

Here is the caller graph for this function:


Variable Documentation

string lib2to3.pytree.__author__ = "Guido van Rossum <guido@python.org>"

Definition at line 13 of file pytree.py.

Definition at line 21 of file pytree.py.

int lib2to3.pytree.HUGE = 0x7FFFFFFF

Definition at line 19 of file pytree.py.