Ñò
$8Zc           @   s´   d  Z  d Z d d g Z d d k 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   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  j o t i ƒ  } n | |  _ | |  _ d  S(   N(   R   t   Nonet   loggingt	   getLoggert   loggert   convert(   t   selfR   R   R
   (    (    s*   /usr/lib/python2.6/lib2to3/pgen2/driver.pyt   __init__   s
    		c         C   sP  t  i |  i |  i ƒ } | i ƒ  d } d } d	 } } } }	 }
 d } xü| D]Ö} | \ } } } }	 }
 | | | f j o | | f | j p t | | f | f ‚ | \ } } | | 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 | | | | f ƒ ‚ | i 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   t   AssertionErrorR   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(    (    s*   /usr/lib/python2.6/lib2to3/pgen2/driver.pyt   parse_tokens%   sV    
 )




	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   (    (    s*   /usr/lib/python2.6/lib2to3/pgen2/driver.pyt   parse_stream_rawU   s    c         C   s   |  i  | | ƒ S(   s*   Parse a stream and return the syntax tree.(   R-   (   R   R,   R   (    (    s*   /usr/lib/python2.6/lib2to3/pgen2/driver.pyt   parse_streamZ   s    c         C   s;   t  i | d | ƒ } z |  i | | ƒ SWd | i ƒ  Xd S(   s(   Parse a file and return the syntax tree.t   rN(   t   codecst   openR.   t   close(   R   t   filenamet   encodingR   R,   (    (    s*   /usr/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   (    (    s*   /usr/lib/python2.6/lib2to3/pgen2/driver.pyt   parse_stringf   s    N(
   t   __name__t
   __module__R   R   t   FalseR)   R-   R.   R5   R9   (    (    (    s*   /usr/lib/python2.6/lib2to3/pgen2/driver.pyR       s   0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(   R8   t   line(    (    s*   /usr/lib/python2.6/lib2to3/pgen2/driver.pyR6   l   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(    (    s*   /usr/lib/python2.6/lib2to3/pgen2/driver.pyR   t   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.(   RA   RB   t   existsR<   R>   t   getmtime(   t   at   b(    (    s*   /usr/lib/python2.6/lib2to3/pgen2/driver.pyRI      s
    (   t   __doc__t
   __author__t   __all__R0   RA   R   RG   R   R   R   R   R   R   t   objectR    R6   R   R>   R<   R   RI   (    (    (    s*   /usr/lib/python2.6/lib2to3/pgen2/driver.pyt   <module>   s   (P	