ok
Direktori : /proc/self/root/proc/thread-self/root/proc/self/root/usr/lib64/python2.7/lib2to3/pgen2/ |
Current File : //proc/self/root/proc/thread-self/root/proc/self/root/usr/lib64/python2.7/lib2to3/pgen2/parse.pyc |
� _цdc @ sF d Z d d l m Z d e f d � � YZ d e f d � � YZ d S( s� Parser engine for the grammar tables generated by pgen. The grammar table must be loaded first. See Parser/parser.c in the Python distribution for additional info on how this parsing engine works. i ( t tokent ParseErrorc B s e Z d Z d � Z RS( s( Exception to signal the parser is stuck.c C sH t j | d | | | | f � | | _ | | _ | | _ | | _ d S( Ns! %s: type=%r, value=%r, context=%r( t Exceptiont __init__t msgt typet valuet context( t selfR R R R ( ( s+ /usr/lib64/python2.7/lib2to3/pgen2/parse.pyR s ( t __name__t __module__t __doc__R ( ( ( s+ /usr/lib64/python2.7/lib2to3/pgen2/parse.pyR s t Parserc B sS e Z d Z d d � Z d d � Z d � Z d � Z d � Z d � Z d � Z RS( s5 Parser engine. The proper usage sequence is: p = Parser(grammar, [converter]) # create instance p.setup([start]) # prepare for parsing <for each input token>: if p.addtoken(...): # parse a token; may raise ParseError break root = p.rootnode # root of abstract syntax tree A Parser instance may be reused by calling setup() repeatedly. A Parser instance contains state pertaining to the current token sequence, and should not be used concurrently by different threads to parse separate token sequences. See driver.py for how to get input tokens by tokenizing a file or string. Parsing is complete when addtoken() returns True; the root of the abstract syntax tree can then be retrieved from the rootnode instance variable. When a syntax error occurs, addtoken() raises the ParseError exception. There is no error recovery; the parser cannot be used after a syntax error was reported (but it can be reinitialized by calling setup()). c C s | | _ | p d � | _ d S( s� Constructor. The grammar argument is a grammar.Grammar instance; see the grammar module for more information. The parser is not ready yet for parsing; you must call the setup() method to get it started. The optional convert argument is a function mapping concrete syntax tree nodes to abstract syntax tree nodes. If not given, no conversion is done and the syntax tree produced is the concrete syntax tree. If given, it must be a function of two arguments, the first being the grammar (a grammar.Grammar instance), and the second being the concrete syntax tree node to be converted. The syntax tree is converted from the bottom up. A concrete syntax tree node is a (type, value, context, nodes) tuple, where type is the node type (a token or symbol number), value is None for symbols and a string for tokens, context is None or an opaque value used for error reporting (typically a (lineno, offset) pair), and nodes is a list of children for symbols, and None for tokens. An abstract syntax tree node may be anything; this is entirely up to the converter function. c S s | S( N( ( t grammart node( ( s+ /usr/lib64/python2.7/lib2to3/pgen2/parse.pyt <lambda>W s N( R t convert( R R R ( ( s+ /usr/lib64/python2.7/lib2to3/pgen2/parse.pyR 9 s c C sk | d k r | j j } n | d d g f } | j j | d | f } | g | _ d | _ t � | _ d S( s� Prepare for parsing. This *must* be called before starting to parse. The optional argument is an alternative start symbol; it defaults to the grammar's start symbol. You can use a Parser instance to parse any number of programs; each time you call setup() the parser is reset to an initial state determined by the (implicit or explicit) start symbol. i N( t NoneR t startt dfast stackt rootnodet sett used_names( R R t newnodet stackentry( ( s+ /usr/lib64/python2.7/lib2to3/pgen2/parse.pyt setupY s c C s� | j | | | � } x�t r�| j d \ } } } | \ } } | | } xq| D]\ } } | j j | \ } } | | k r | d k s� t � | j | | | | � | } xV | | d | f g k r| j � | j s� t S| j d \ } } } | \ } } q� Wt S| d k rQ | j j | } | \ } } | | k re| j | | j j | | | � PqeqQ qQ Wd | f | k r�| j � | j s�t d | | | � � q�q t d | | | � � q Wd S( s<