
    f                         d Z ddlmZmZ ddlmZ ddlmZ  G d de      Z	 G d de      Z
 G d	 d
e      Z G d d      Zd Z G d d      Zy)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                       e Zd ZdZd Zy)ParserSyntaxErrorz_
    Contains error information about the parser tree.

    May be raised as an exception.
    c                      || _         || _        y N)message
error_leaf)selfr   r   s      G/var/www/cvtools/html/venv/lib/python3.12/site-packages/parso/parser.py__init__zParserSyntaxError.__init__&   s    $    N__name__
__module____qualname____doc__r    r   r   r   r       s    
%r   r   c                       e Zd ZdZd Zy)InternalParseErrorz
    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           
          t         j                  | |d|j                  d|d|       || _        t        | _        || _        || _        y )Nz: type=z, value=z, start_pos=)	Exceptionr   namemsgtypevalue	start_pos)r   r   type_r   r   s        r   r   zInternalParseError.__init__2   sA    4UI"? 	@	
"r   Nr   r   r   r   r   r   +   s    #r   r   c                       e Zd Zd Zy)Stackc                 .      fd}t         |             S )Nc               3      K   t              D ]X  } | j                  j                  D ]%  }t        |t              r|j
                   "| ' | j                  j                  rX y  y wr
   )reverseddfatransitions
isinstancer   r   is_final)
stack_node
transitionr   s     r   iteratez@Stack._allowed_transition_names_and_token_types.<locals>.iterate=   sa     &tn 
",.."<"< )J!*n=(...((	) "~~..s   A#A+'A+)list)r   r,   s   ` r   )_allowed_transition_names_and_token_typesz/Stack._allowed_transition_names_and_token_types<   s    
	 GIr   N)r   r   r   r.   r   r   r   r"   r"   ;   s    r   r"   c                   (    e Zd Zd Zed        Zd Zy)	StackNodec                      || _         g | _        y r
   )r&   nodes)r   r&   s     r   r   zStackNode.__init__M   s    
r   c                 .    | j                   j                  S r
   )r&   	from_ruler   s    r   nonterminalzStackNode.nonterminalQ   s    xx!!!r   c                 h    | j                   j                  d| j                  d| j                  dS )N(z, ))	__class__r   r&   r2   r5   s    r   __repr__zStackNode.__repr__U   s!    #~~66$**MMr   N)r   r   r   r   propertyr6   r;   r   r   r   r0   r0   L   s!     " "Nr   r0   c                 r    |j                   j                  r	 | j                  |   S |S # t        $ r Y |S w xY wr
   )r   contains_syntaxreserved_syntax_stringsKeyError)grammarr    r   s      r   _token_to_transitionrB   Y   sE    {{""	22599 L  	L	s   ) 	66c                       e Zd ZU dZi Zeeeej                     f   e
d<   ej                  Zi Zeeeej                     f   e
d<   ej                  ZddZd Zd Zd Zd Zd	 Zd
 Zy)
BaseParseraI  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                 .    || _         || _        || _        y r
   )_pgen_grammar_start_nonterminal_error_recovery)r   pgen_grammarstart_nonterminalerror_recoverys       r   r   zBaseParser.__init__w   s    )"3-r   c                    | j                   j                  | j                     d   }t        t	        |      g      | _        |D ]  }| j                  |        	 | j
                  d   }|j                  j                  s,t        dj                  |j                  |j                        t        | j
                        dkD  r| j                          n&| j                  |j                   |j"                        S )Nr   zincomplete input   )rH   nonterminal_to_dfasrI   r"   r0   stack
_add_tokenr&   r)   r   r   stringr   len_popconvert_noder6   r2   )r   tokens	first_dfatokentoss        r   parsezBaseParser.parse|   s    &&::4;R;RSTUV	Ii012
 	#EOOE"	# **R.C77## )&

ELL%//  4::"		((#))DD r   c                     | j                   rt        d      |\  }}}}t        j                  ||||      }t	        d|      )Nz!Error Recovery is not implementedzSyntaxError: invalid syntax)rJ   NotImplementedErrorr   	ErrorLeafr   )r   rZ   r    r   r   prefixr   s          r   rM   zBaseParser.error_recovery   sG    %&IJJ.3+E5)VuiHJ#$A:NNr   c                 v    	  | j                   |   |      }|S # t        $ r | j                  ||      }Y |S w xY wr
   )rE   r@   default_node)r   r6   childrennodes       r   rW   zBaseParser.convert_node   sK    	<-4==-h7D   	<$$[(;D	<s    88c                 v    	  | j                   |   |||      S # t        $ r | j                  |||      cY S w xY wr
   )rF   r@   default_leaf)r   r    r   r`   r   s        r   convert_leafzBaseParser.convert_leaf   sE    	?'4=='y&AA 	?$$UIv>>	?s    88c                 B   | j                   }| j                  }|\  }}}}t        |||      }	 	 |d   j                  j                  |   }		 |	j                  |d   _        |	j                  D ]  }
|j                  t        |
              | j                  ||||      }|d   j                   j                  |       y# t
        $ r@ |d   j                  j                  r| j                          n| j                  |       Y yY nt        $ r t        d|||      w xY w)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.
        rO   Nztoo much input)rH   rR   rB   r&   r'   r@   r)   rV   rM   
IndexErrorr   next_dfa
dfa_pushesappendr0   rg   r2   )r   rZ   rA   rR   r    r   r   r`   r+   planpushleafs               r   rS   zBaseParser._add_token   s    $$

*/'ui)'5%@

TRy}}00< b	OO 	*DLL4)	*   vyAb	t$  9==))IIK''.    T()95%SST s   B> >ADDc                 8   | j                   j                         }t        |j                        dk(  r|j                  d   }n0| j	                  |j
                  j                  |j                        }| j                   d   j                  j                  |       y )NrP   r   rO   )rR   poprU   r2   rW   r&   r4   rl   )r   r[   new_nodes      r   rV   zBaseParser._pop   sm    jjnn
 syy>Qyy|H(():):CIIFH

2##H-r   N)
file_inputF)r   r   r   r   rE   r   strr   r   BaseNode__annotations__Noderb   rF   Leafrf   r   r\   rM   rW   rg   rS   rV   r   r   r   rD   rD   e   sz    	 02Hd3T]]++,199L+-Hd3TYY'(-99L.
E,O?%@.r   rD   N)r   typingr   r   parsor   parso.pgen2.generatorr   r   r   r   r-   r"   r0   rB   rD   r   r   r   <module>r|      sV   "   0%	 %# # D "
N 
N	m. m.r   