ó
3Y~gc @ s d Z d Z d d g Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l m
Z
m Z m Z m
Z
m Z d e f d „ ƒ YZ d „ Z d
d e e d d „ Z d „ Z d
„ Z d „ Z e d k r e j e e ƒ ƒ ƒ n d S( sZ Parser driver.
This provides a high-level interface to parse a file into a syntax tree.
s# Guido van Rossum t Drivert load_grammariÿÿÿÿNi ( t grammart parset tokent tokenizet pgenc B sV e Z d d d „ Z e d „ Z e d „ Z e d „ Z d e d „ Z e d „ Z RS( c C s: | | _ | d k r$ t j ƒ } n | | _ | | _ d S( N( R t Nonet loggingt getLoggert loggert convert( t selfR R R
( ( s9 /opt/alt/python27/lib64/python2.7/lib2to3/pgen2/driver.pyt __init__ s
c C s t j | j | j ƒ } | j ƒ d } d } d } } } } }
d } x¿| D]™} | \ } } } } }
| | | f k rà | \ }
} | |
k r· | d |
| 7} |
} d } n | | k rà | |
| | !7} | } qà n | t j t j f k r6| | 7} | \ } } | j d ƒ rQ | d 7} d } qQ qQ n | t
j k rUt j | } n | r~| j
j d t
j | | | ƒ n | j | | | | f ƒ r¶| r²| j
j d ƒ n Pn d } | \ } } | j d ƒ rQ | d 7} d } qQ qQ Wt j d | | | | f ƒ ‚ | j S(
s4 Parse a series of tokens and return the syntax tree.i i u s
s %s %r (prefix=%r)s Stop.t s incomplete inputN( R t ParserR R t setupR R t COMMENTt NLt endswithR t OPt opmapR
t debugt tok_namet addtokent
ParseErrort rootnode( R t tokensR t pt linenot columnt typet valuet startt endt line_textt prefixt quintuplet s_linenot s_column( ( s9 /opt/alt/python27/lib64/python2.7/lib2to3/pgen2/driver.pyt parse_tokens' sR
c C s" t j | j ƒ } | j | | ƒ S( s* Parse a stream and return the syntax tree.( R t generate_tokenst readlineR( ( R t streamR R ( ( s9 /opt/alt/python27/lib64/python2.7/lib2to3/pgen2/driver.pyt parse_stream_rawW s c C s | j | | ƒ S( s* Parse a stream and return the syntax tree.( R, ( R R+ R ( ( s9 /opt/alt/python27/lib64/python2.7/lib2to3/pgen2/driver.pyt parse_stream\ s c C s; t j | d | ƒ } z | j | | ƒ SWd | j ƒ Xd S( s( Parse a file and return the syntax tree.t rN( t codecst openR- t close( R t filenamet encodingR R+ ( ( s9 /opt/alt/python27/lib64/python2.7/lib2to3/pgen2/driver.pyt
parse_file` s c C s+ t j t j | ƒ j ƒ } | j | | ƒ S( s* Parse a string and return the syntax tree.( R R) t StringIOR* R( ( R t textR R ( ( s9 /opt/alt/python27/lib64/python2.7/lib2to3/pgen2/driver.pyt parse_stringh s N(
t __name__t
__module__R R
t FalseR( R, R- R4 R7 ( ( ( s9 /opt/alt/python27/lib64/python2.7/lib2to3/pgen2/driver.pyR s 0c C sR t j j | ƒ \ } } | d k r- d } n | | d j t t t j ƒ ƒ d S( Ns .txtR t .s .pickle( t ost patht splitextt joint mapt strt syst version_info( t gtt headt tail( ( s9 /opt/alt/python27/lib64/python2.7/lib2to3/pgen2/driver.pyt _generate_pickle_namen s s Grammar.txtc C sÞ | d k r t j ƒ } n | d k r3 t | ƒ n | } | sO t | | ƒ rÁ | j d | ƒ t j | ƒ } | rÚ | j d | ƒ y | j | ƒ Wq¾ t k
rº } | j d | ƒ q¾ XqÚ n t
j ƒ } | j | ƒ | S( s' Load the grammar (maybe from a pickle).s! Generating grammar tables from %ss Writing grammar tables to %ss Writing failed: %sN(
R R R RG t _newert infoR t generate_grammart dumpt IOErrorR t Grammart load( RD t gpt savet forceR
t gt e( ( s9 /opt/alt/python27/lib64/python2.7/lib2to3/pgen2/driver.pyR u s
c C sN t j j | ƒ s t St j j | ƒ s, t St j j | ƒ t j j | ƒ k S( s0 Inquire whether file a was written since file b.( R<