ó
MšV]c           @   se   d  d l  m Z d  d l m Z d  d l m Z e j Z e j Z e j Z d e f d „  ƒ  YZ	 d S(   iÿÿÿÿ(   t   tree(   t   PythonTokenTypes(   t
   BaseParsert   Parserc           B   så  e  Z d  Z i e j d 6e j d 6e j d 6e j d 6e j d 6e j	 d 6e j
 d 6e j
 d 6e j d	 6e j
 d
 6e j d 6e j
 d 6e j
 d 6e j d 6e j
 d 6e j
 d 6e j d 6e j d 6e j d 6e j d 6e j d 6e j d 6e j d 6e j d 6e j d 6e j d 6e j d 6e j d 6e j d 6Z e j Z i e j e j 6e j e j 6e j e j  6e j! e j" 6e j# e j$ 6e j% e j& 6e j' e j( 6Z) e* d d „ Z+ d „  Z, d  „  Z- d! „  Z. d" „  Z/ d# „  Z0 d$ „  Z1 RS(%   sÈ   
    This class is used to parse a Python file, it then divides them into a
    class structure of different scopes.

    :param pgen_grammar: The grammar object of pgen2. Loaded by load_grammar.
    t	   expr_stmtt   classdeft   funcdeft
   file_inputt   import_namet   import_fromt
   break_stmtt   continue_stmtt   return_stmtt
   raise_stmtt
   yield_exprt   del_stmtt	   pass_stmtt   global_stmtt   nonlocal_stmtt
   print_stmtt   assert_stmtt   if_stmtt	   with_stmtt   for_stmtt
   while_stmtt   try_stmtt   sync_comp_fort   list_fort   gen_fort	   decoratort   lambdeft   old_lambdeft   lambdef_nocondc         C   s>   t  t |  ƒ j | | d | ƒg  |  _ g  |  _ d |  _ d  S(   Nt   error_recoveryi    (   t   superR   t   __init__t   syntax_errorst   _omit_dedent_listt   _indent_counter(   t   selft   pgen_grammarR!   t   start_nonterminal(    (    s2   lib/python2.7/site-packages/parso/python/parser.pyR#   C   s
    		c         C   sI   |  j  r3 |  j d k r! t ‚ n  |  j | ƒ } n  t t |  ƒ j | ƒ S(   NR   (   t   _error_recoveryt   _start_nonterminalt   NotImplementedErrort   _recovery_tokenizeR"   R   t   parse(   R'   t   tokens(    (    s2   lib/python2.7/site-packages/parso/python/parser.pyR.   K   s
    		c         C   s¬   y |  j  | | ƒ } Wnt t k
 r | d k rN | d g | d d !} n* | d k rc d } n | d k rx d } n  |  j | | ƒ } n Xx | D] } | | _ q• W| S(	   s  
        Convert raw node information to a PythonBaseNode 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.
        t   suitei    i   iÿÿÿÿt   list_ift   comp_ift	   listmakert   testlist_comp(   t   node_mapt   KeyErrort   default_nodet   parent(   R'   t   nonterminalt   childrent   nodet   c(    (    s2   lib/python2.7/site-packages/parso/python/parser.pyt   convert_nodeT   s    		c         C   si   | t  k rG | |  j j k r1 t j | | | ƒ St j | | | ƒ Sn  |  j j | t j ƒ | | | ƒ S(   N(	   t   NAMEt   _pgen_grammart   reserved_syntax_stringsR    t   Keywordt   Namet	   _leaf_mapt   gett   Operator(   R'   t   typet   valuet   prefixt	   start_pos(    (    s2   lib/python2.7/site-packages/parso/python/parser.pyt   convert_leafp   s
    c         C   s  |  j  d j } | r) | d j ƒ  } n d  } |  j d k r| j t j k s} | j t k rd | j	 k rd | j	 k r|  j  d j
 j d k ry |  j  d j
 j t j } Wn t k
 rÇ qX| j j r| j r| j |  j  d _
 |  j | ƒ d  Sqn  |  j s't t |  ƒ j | ƒ Sd „  } | |  j  ƒ } |  j | d ƒ rb|  j | ƒ nf | \ } } }	 }
 | t k r–|  j j |  j ƒ n  t j | j | |	 |
 ƒ } |  j  d j j | ƒ |  j  d } | j d k ry | j
 j  d	 | _
 Wqt k
 rqXn  d  S(
   NiÿÿÿÿR   s   
s   t   simple_stmtc         S   sk   xd t  t t |  ƒ ƒ ƒ D]J \ } } | j d k r8 Pq | j d k r t | j ƒ d k rc Pqc q q W| S(   NR   R0   i   (   t   reversedt   listt	   enumerateR9   t   lent   nodes(   t   stackt   until_indext
   stack_node(    (    s2   lib/python2.7/site-packages/parso/python/parser.pyt   current_suite™   s    %i   R0   t   stmt(!   RQ   RP   t   get_last_leaft   NoneR+   RF   R   t	   ENDMARKERt   DEDENTRG   t   dfat	   from_rulet   transitionst   NEWLINER6   t   next_dfat   is_finalt
   dfa_pushest
   _add_tokenR*   R"   R   R!   t   _stack_removalt   INDENTR%   t   appendR&   R    t   PythonErrorLeaft   nameR9   t   arcs(   R'   t   tokent	   tos_nodest	   last_leaft   planRT   RR   t   typRG   RI   RH   t
   error_leaft   tos(    (    s2   lib/python2.7/site-packages/parso/python/parser.pyR!   z   sD    
		c         C   s”   g  |  j  | D] } | j D] } | ^ q q } | r} t j | ƒ } x | D] } | | _ qL W|  j  | d j j | ƒ n  g  |  j  | )t | ƒ S(   Ni   (   RQ   RP   R    t   PythonErrorNodeR8   Rd   t   bool(   R'   t   start_indexRS   R;   t	   all_nodest   n(    (    s2   lib/python2.7/site-packages/parso/python/parser.pyRb   À   s    0c         c   s’   x‹ | D]ƒ } | d } | t  k rg |  j } | rU | d |  j k rU | j ƒ  q n  |  j d 8_ n | t k r… |  j d 7_ n  | Vq Wd  S(   Ni    iÿÿÿÿi   (   RY   R%   R&   t   popRc   (   R'   R/   Rh   Rl   t   o(    (    s2   lib/python2.7/site-packages/parso/python/parser.pyR-   Ì   s    
	
(2   t   __name__t
   __module__t   __doc__R    t   ExprStmtt   Classt   Functiont   Modulet
   ImportNamet
   ImportFromt   KeywordStatementt
   ReturnStmtt	   YieldExprt
   GlobalStmtt
   AssertStmtt   IfStmtt   WithStmtt   ForStmtt	   WhileStmtt   TryStmtt   SyncCompFort	   Decoratort   LambdaR5   t
   PythonNodeR7   t   StringR   t   STRINGt   Numbert   NUMBERt   NewlineR]   t	   EndMarkerRX   t   FStringStringt   FSTRING_STRINGt   FStringStartt   FSTRING_STARTt
   FStringEndt   FSTRING_ENDRC   t   TrueR#   R.   R=   RJ   R!   Rb   R-   (    (    (    s2   lib/python2.7/site-packages/parso/python/parser.pyR      s^   



























					
	F	N(
   t   parso.pythonR    t   parso.python.tokenR   t   parso.parserR   R>   Rc   RY   R   (    (    (    s2   lib/python2.7/site-packages/parso/python/parser.pyt   <module>   s   			