
    yh                         S r SSKJrJr  SSKJr  SSKJr   " S S\5      r	 " S S\5      r
 " S	 S
\5      r " S S5      rS r " S S5      rg)a  
The ``Parser`` tries to convert the available Python code in an easy to read
format, something like an abstract syntax tree. The classes who represent this
tree, are sitting in the :mod:`parso.tree` module.

The Python module ``tokenize`` is a very important part in the ``Parser``,
because it splits the code into different words (tokens).  Sometimes it looks a
bit messy. Sorry for that! You might ask now: "Why didn't you use the ``ast``
module for this? Well, ``ast`` does a very good job understanding proper Python
code, but fails to work as soon as there's a single line of broken code.

There's one important optimization that needs to be known: Statements are not
being parsed completely. ``Statement`` is just a representation of the tokens
within the statement. This lowers memory usage and cpu time and reduces the
complexity of the ``Parser`` (there's another parser sitting inside
``Statement``, which produces ``Array`` and ``Call``).
    )DictType)tree)ReservedStringc                       \ rS rSrSrS rSrg)ParserSyntaxError    zS
Contains error information about the parser tree.

May be raised as an exception.
c                     Xl         X l        g N)message
error_leaf)selfr   r   s      dc:\Users\julio\OneDrive\Documentos\Trabajo\IdeasFrscas\Cabanna\env\Lib\site-packages\parso/parser.py__init__ParserSyntaxError.__init__&   s    $    )r   r   N__name__
__module____qualname____firstlineno____doc__r   __static_attributes__ r   r   r   r       s    
%r   r   c                       \ rS rSrSrS rSrg)InternalParseError+   z
Exception to signal the parser is stuck and error recovery didn't help.
Basically this shouldn't happen. It's a sign that something is really
wrong.
c           
          [         R                  U U< SUR                  < SU< SU< 35        Xl        [        U l        X0l        X@l        g )Nz: type=z, value=z, start_pos=)	Exceptionr   namemsgtypevalue	start_pos)r   r!   type_r#   r$   s        r   r   InternalParseError.__init__2   s;    4UI"? 	@	
"r   )r!   r$   r"   r#   Nr   r   r   r   r   r   +   s    #r   r   c                       \ rS rSrS rSrg)Stack;   c                 0   ^  U 4S jn[        U" 5       5      $ )Nc               3      >#    [        T5       Hf  n U R                  R                   H,  n[        U[        5      (       a  UR
                  v   M(  Uv   M.     U R                  R                  (       a  Mf    g    g 7fr   )reverseddfatransitions
isinstancer   r#   is_final)
stack_node
transitionr   s     r   iterate@Stack._allowed_transition_names_and_token_types.<locals>.iterate=   s\     &tn
",.."<"<J!*n==(...((	 #= "~~... -s   A.A:5A:)list)r   r3   s   ` r   )_allowed_transition_names_and_token_types/Stack._allowed_transition_names_and_token_types<   s    
	 GIr   r   N)r   r   r   r   r6   r   r   r   r   r(   r(   ;   s    r   r(   c                   0    \ rS rSrS r\S 5       rS rSrg)	StackNodeL   c                     Xl         / U l        g r   r-   nodes)r   r-   s     r   r   StackNode.__init__M   s    
r   c                 .    U R                   R                  $ r   )r-   	from_ruler   s    r   nonterminalStackNode.nonterminalQ   s    xx!!!r   c                 n    U R                   R                  < SU R                  < SU R                  < S3$ )N(z, ))	__class__r   r-   r=   rA   s    r   __repr__StackNode.__repr__U   s!    #~~66$**MMr   r<   N)	r   r   r   r   r   propertyrB   rH   r   r   r   r   r9   r9   L   s!     " "Nr   r9   c                 ~    UR                   R                  (       a   U R                  U   $ U$ ! [         a     U$ f = fr   )r#   contains_syntaxreserved_syntax_stringsKeyError)grammarr%   r#   s      r   _token_to_transitionrP   Y   sE    {{""	22599 L  	L	s   . 
<<c                       \ rS rSr% Sr0 r\\\\	R                     4   \S'   \	R                  r0 r\\\\	R                     4   \S'   \	R                  rSS jrS rS rS rS	 rS
 rS rSrg)
BaseParsere   a1  Parser engine.

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 python/tokenize.py for how to get input tokens by a string.

When a syntax error occurs, error_recovery() is called.
node_mapleaf_mapc                 (    Xl         X l        X0l        g r   )_pgen_grammar_start_nonterminal_error_recovery)r   pgen_grammarstart_nonterminalerror_recoverys       r   r   BaseParser.__init__w   s    )"3-r   c                    U R                   R                  U R                     S   n[        [	        U5      /5      U l        U H  nU R                  U5        M      U R
                  S   nUR                  R                  (       d,  [        SWR                  UR                  UR                  5      e[        U R
                  5      S:  a  U R                  5         O&U R                  UR                   UR"                  5      $ M  )Nr   zincomplete input   )rW   nonterminal_to_dfasrX   r(   r9   stack
_add_tokenr-   r0   r   r"   stringr$   len_popconvert_noderB   r=   )r   tokens	first_dfatokentoss        r   parseBaseParser.parse|   s    &&::4;R;RSTUV	Ii012
EOOE"  **R.C77## )&

ELL%//  4::"		((#))DD r   c                     U R                   (       a  [        S5      eUu  p#pE[        R                  " X#XE5      n[	        SU5      e)Nz!Error Recovery is not implementedzSyntaxError: invalid syntax)rY   NotImplementedErrorr   	ErrorLeafr   )r   rj   r%   r#   r$   prefixr   s          r   r\   BaseParser.error_recovery   s?    %&IJJ.3+E)iHJ#$A:NNr   c                 v     U R                   U   " U5      nU$ ! [         a    U R                  X5      n U$ f = fr   )rT   rN   default_node)r   rB   childrennodes       r   rg   BaseParser.convert_node   sG    	<==-h7D   	<$$[;D	<s    88c                 t     U R                   U   " X$U5      $ ! [         a    U R                  X$U5      s $ f = fr   )rU   rN   default_leaf)r   r%   r#   rq   r$   s        r   convert_leafBaseParser.convert_leaf   s?    	?=='&AA 	?$$Uv>>	?s    77c                 H   U R                   nU R                  nUu  pEpg[        X$U5      n  US   R                  R                  U   n	 U	R                  US   l        U	R                   H  n
UR                  [        U
5      5        M     U R                  XEXv5      nUS   R                   R                  U5        g! [
         aD    US   R                  R                  (       a  U R                  5          O-U R                  U5         g[         a    [        SXEU5      ef = fM  )z
This is the only core function for parsing. Here happens basically
everything. Everything is well prepared by the parser generator and we
only apply the necessary steps here.
r_   Nztoo much input)rW   rb   rP   r-   r.   rN   r0   rf   r\   
IndexErrorr   next_dfa
dfa_pushesappendr9   rz   r=   )r   rj   rO   rb   r%   r#   r$   rq   r2   planpushleafs               r   rc   BaseParser._add_token   s    $$

*/'i)'%@

TRy}}00< b	OODLL4) $   vAb	t$  9==))IIK''. T()95SST s   B; ;8D5DDc                 :   U R                   R                  5       n[        UR                  5      S:X  a  UR                  S   nO0U R	                  UR
                  R                  UR                  5      nU R                   S   R                  R                  U5        g )Nr`   r   r_   )rb   popre   r=   rg   r-   r@   r   )r   rk   new_nodes      r   rf   BaseParser._pop   sm    jjnn
 syy>Qyy|H(():):CIIFH

2##H-r   )rY   rW   rX   rb   N)
file_inputF)r   r   r   r   r   rT   r   strr   r   BaseNode__annotations__Nodert   rU   Leafry   r   rl   r\   rg   rz   rc   rf   r   r   r   r   rR   rR   e   sz    	 02Hd3T]]++,199L+-Hd3TYY'(-99L.
E,O?%@.r   rR   N)r   typingr   r   parsor   parso.pgen2.generatorr   r   r   r   r5   r(   r9   rP   rR   r   r   r   <module>r      sV   "   0%	 %# # D "
N 
N	m. m.r   