
    Mh                         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dS )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dS )ParserSyntaxErrorz_
    Contains error information about the parser tree.

    May be raised as an exception.
    c                 "    || _         || _        d S N)message
error_leaf)selfr   r   s      L/var/www/html/test/jupyter/venv/lib/python3.11/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dS )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                               | |d|j        d|d|           || _        t          | _        || _        || _        d S )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   s]    4CCUUUII"? 	@ 	@ 	@	
"r   Nr   r   r   r   r   r   +   s-         # # # # #r   r   c                       e Zd Zd ZdS )Stackc                 <      fd}t           |                      S )Nc               3      K   t                    D ]C} | j        j        D ]%}t          |t                    r
|j        V  !|V  &| j        j        s d S Dd S r
   )reverseddfatransitions
isinstancer   r   is_final)
stack_node
transitionr   s     r   iteratez@Stack._allowed_transition_names_and_token_types.<locals>.iterate=   s      &tnn  
",."< ) )J!*n== )(.....(((((!~. EE r   )list)r   r,   s   ` r   )_allowed_transition_names_and_token_typesz/Stack._allowed_transition_names_and_token_types<   s0    
	 
	 
	 
	 
	 GGIIr   N)r   r   r   r.   r   r   r   r"   r"   ;   s#            r   r"   c                   0    e Zd Zd Zed             Zd ZdS )	StackNodec                 "    || _         g | _        d S 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    x!!r   c                 @    | 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6$***MMr   N)r   r   r   r   propertyr6   r;   r   r   r   r0   r0   L   sR           " " X"N N N N Nr   r0   c                 Z    |j         j        r	 | j        |         S # t          $ r Y nw xY w|S r
   )r   contains_syntaxreserved_syntax_stringsKeyError)grammarr    r   s      r   _token_to_transitionrB   Y   sI    {" 	2599 	 	 	D	 Ls    
((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dS )
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_map
file_inputFc                 0    || _         || _        || _        d S 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        d         }|j        j        s!t          d|j
        |j        |j                  t          | j                  dk    r|                                  n |                     |j        |j                  S )Nr   Tzincomplete input   )rI   nonterminal_to_dfasrJ   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STUV	Ii00122
 	# 	#EOOE""""	E*R.C7#  )&
EL%/   4:""		((#)DDD	Er   c                     | j         rt          d          |\  }}}}t          j        ||||          }t	          d|          )Nz!Error Recovery is not implementedzSyntaxError: invalid syntax)rK   NotImplementedErrorr   	ErrorLeafr   )r   r[   r    r   r   prefixr   s          r   rN   zBaseParser.error_recovery   sQ     	O%&IJJJ.3+E5)VuiHHJ#$A:NNNr   c                     	  | j         |         |          }n&# t          $ r |                     ||          }Y nw xY w|S r
   )rE   r@   default_node)r   r6   childrennodes       r   rX   zBaseParser.convert_node   sX    	<-4=-h77DD 	< 	< 	<$$[(;;DDD	<s     <<c                     	  | j         |         |||          S # t          $ r |                     |||          cY S w xY wr
   )rF   r@   default_leaf)r   r    r   ra   r   s        r   convert_leafzBaseParser.convert_leaf   s[    	?'4='y&AAA 	? 	? 	?$$UIv>>>>>	?s    !>>c                 J   | j         }| j        }|\  }}}}t          |||          }	 	 |d         j        j        |         }	nk# t
          $ rB |d         j        j        r|                                  n|                     |           Y dS Y nt          $ r t          d|||          w xY w|	j        |d         _        |	j        D ]$}
|                    t          |
                     %|                     ||||          }|d         j                            |           dS )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.
        TrP   Nztoo much input)rI   rS   rB   r&   r'   r@   r)   rW   rN   
IndexErrorr   next_dfa
dfa_pushesappendr0   rh   r2   )r   r[   rA   rS   r    r   r   ra   r+   planpushleafs               r   rT   zBaseParser._add_token   sX    $
*/'ui)'5%@@
	T
TRy}0<   9=) IIKKKK''...FF  K  T T T()95%SSST	T b	O 	* 	*DLL4))))  vyAAb	t$$$$$s   A AB)B)c                    | j                                         }t          |j                  dk    r|j        d         }n%|                     |j        j        |j                  }| j         d         j                            |           d S )NrQ   r   rP   )rS   poprV   r2   rX   r&   r4   rm   )r   r\   new_nodes      r   rW   zBaseParser._pop   st    jnn
 sy>>Qy|HH(():CIFFH
2##H-----r   N)rG   F)r   r   r   r   rE   r   strr   r   BaseNode__annotations__Noderc   rF   Leafrg   r   r]   rN   rX   rh   rT   rW   r   r   r   rD   rD   e   s         	 	 02Hd3T]++,1119L+-Hd3TY'(---9L. . . .
E E E,O O O  ? ? ?% % %@. . . . .r   rD   N)r   typingr   r   parsor   parso.pgen2.generatorr   r   r   r   r-   r"   r0   rB   rD   r   r   r   <module>r|      sF   "               0 0 0 0 0 0% % % % %	 % % %# # # # # # # #     D   "
N 
N 
N 
N 
N 
N 
N 
N	 	 	m. m. m. m. m. m. m. m. m. m.r   