Ñò
–à"Ic        
   @   s¨   d  Z  d Z d d g Z d d k Z d d k Z d d k Z d d k l Z l Z l	 Z	 l
 Z
 l Z d e f d „  ƒ  YZ d	 „  Z d
 d e e d d „ Z d „  Z d S(   sZ   Parser driver.

This provides a high-level interface to parse a file into a syntax tree.

s#   Guido van Rossum <guido@python.org>t   Drivert   load_grammariÿÿÿÿNi   (   t   grammart   parset   tokent   tokenizet   pgenc           B   sS   e  Z d d d  „ Z e d „ Z e d „ Z e d „ Z e d „ Z e d „ Z	 RS(   c         C   s<   | |  _  | d  j o t i ƒ  } n | |  _ | |  _ d  S(   N(   R   t   Nonet   loggingt	   getLoggert   loggert   convert(   t   selfR   R   R
   (    (    s1   /mit/python/lib/python2.6/lib2to3/pgen2/driver.pyt   __init__   s
    		c         C   s!  t  i |  i |  i ƒ } | i ƒ  d } d } d } } } }	 }
 d } xÍ| D]­} | \ } } } }	 }
 | | | f j og | \ } } | | j  o" | d | | 7} | } d } n | | j  o | |
 | | !7} | } qæ n | t i t i f j oA | | 7} |	 \ } } | i	 d ƒ o | d 7} d } qQ qQ n | t
 i j o t i | } n | o$ |  i i d t
 i | | | ƒ n | i | | | | f ƒ o  | o |  i i d ƒ n Pn d } |	 \ } } | i	 d ƒ o | d 7} d } qQ qQ Wt  i d t t t ƒ ‚ | i S(	   s4   Parse a series of tokens and return the syntax tree.i   i    t    s   
s   %s %r (prefix=%r)s   Stop.s   incomplete inputN(   R   t   ParserR   R   t   setupR   R   t   COMMENTt   NLt   endswithR   t   OPt   opmapR
   t   debugt   tok_namet   addtokent
   ParseErrort   tt   vt   xt   rootnode(   R   t   tokensR   t   pt   linenot   columnt   typet   valuet   startt   endt	   line_textt   prefixt	   quintuplet   s_linenot   s_column(    (    s1   /mit/python/lib/python2.6/lib2to3/pgen2/driver.pyt   parse_tokens$   sR    
 




c         C   s"   t  i | i ƒ } |  i | | ƒ S(   s*   Parse a stream and return the syntax tree.(   R   t   generate_tokenst   readlineR+   (   R   t   streamR   R   (    (    s1   /mit/python/lib/python2.6/lib2to3/pgen2/driver.pyt   parse_stream_rawS   s    c         C   s   |  i  | | ƒ S(   s*   Parse a stream and return the syntax tree.(   R/   (   R   R.   R   (    (    s1   /mit/python/lib/python2.6/lib2to3/pgen2/driver.pyt   parse_streamX   s    c         C   s2   t  | ƒ } z |  i | | ƒ SWd | i ƒ  Xd S(   s(   Parse a file and return the syntax tree.N(   t   openR0   t   close(   R   t   filenameR   R.   (    (    s1   /mit/python/lib/python2.6/lib2to3/pgen2/driver.pyt
   parse_file\   s    c         C   s(   t  i t | ƒ i ƒ } |  i | | ƒ S(   s*   Parse a string and return the syntax tree.(   R   R,   t   generate_linest   nextR+   (   R   t   textR   R   (    (    s1   /mit/python/lib/python2.6/lib2to3/pgen2/driver.pyt   parse_stringd   s    N(
   t   __name__t
   __module__R   R   t   FalseR+   R/   R0   R4   R8   (    (    (    s1   /mit/python/lib/python2.6/lib2to3/pgen2/driver.pyR       s   /c         c   s7   x |  i  t ƒ D] } | Vq Wx t o	 d Vq" Wd S(   s<   Generator that behaves like readline without using StringIO.R   N(   t
   splitlinest   True(   R7   t   line(    (    s1   /mit/python/lib/python2.6/lib2to3/pgen2/driver.pyR5   j   s     	 s   Grammar.txtc   	      C   s7  | d j o t i ƒ  } n | d j oZ t i i |  ƒ \ } } | d j o
 d } n | | d i t t t	 i
 ƒ ƒ d } n | p t | |  ƒ o~ | i d |  ƒ t i |  ƒ } | oT | i d | ƒ y | i | ƒ Wqt j
 o  } | i d t | ƒ ƒ qXq3n t i ƒ  } | i | ƒ | S(	   s'   Load the grammar (maybe from a pickle).s   .txtR   t   .s   .pickles!   Generating grammar tables from %ss   Writing grammar tables to %ss   Writing failed:N(   R   R   R	   t   ost   patht   splitextt   joint   mapt   strt   syst   version_infot   _newert   infoR   t   generate_grammart   dumpt   IOErrorR   t   Grammart   load(	   t   gtt   gpt   savet   forceR
   t   headt   tailt   gt   e(    (    s1   /mit/python/lib/python2.6/lib2to3/pgen2/driver.pyR   r   s&    
+$c         C   sR   t  i i |  ƒ p t St  i i | ƒ p t St  i i |  ƒ t  i i | ƒ j S(   s0   Inquire whether file a was written since file b.(   R@   RA   t   existsR;   R=   t   getmtime(   t   at   b(    (    s1   /mit/python/lib/python2.6/lib2to3/pgen2/driver.pyRH   ‹   s
    (   t   __doc__t
   __author__t   __all__R@   R   RF   R   R   R   R   R   R   t   objectR    R5   R   R=   R;   R   RH   (    (    (    s1   /mit/python/lib/python2.6/lib2to3/pgen2/driver.pyt   <module>   s   (O	