a
    Š©lc  ã                   @   s„   d Z ddlmZmZ ddlmZ ddlmZ G dd„ deƒZ	G dd„ deƒZ
G d	d
„ d
eƒZG dd„ dƒZdd„ ZG d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                   @   s   e Zd ZdZdd„ ZdS )ÚParserSyntaxErrorz_
    Contains error information about the parser tree.

    May be raised as an exception.
    c                 C   s   || _ || _d S ©N)ÚmessageÚ
error_leaf)Úselfr   r	   © r   úH/var/www/html/django/DPS/env/lib/python3.9/site-packages/parso/parser.pyÚ__init__&   s    zParserSyntaxError.__init__N©Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r       s   r   c                   @   s   e Zd ZdZd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                 C   s6   t  | d||j||f ¡ || _t| _|| _|| _d S )Nz#%s: type=%r, value=%r, start_pos=%r)Ú	Exceptionr   ÚnameÚmsgÚtypeÚvalueÚ	start_pos)r
   r   Útype_r   r   r   r   r   r   2   s    ÿzInternalParseError.__init__Nr   r   r   r   r   r   +   s   r   c                   @   s   e Zd Zdd„ ZdS )ÚStackc                    s   ‡ fdd„}t |ƒ ƒS )Nc                  3   sF   t ˆ ƒD ]8} | jjD ]}t|tƒr,|jV  q|V  q| jjs qBqd S r   )ÚreversedÚdfaÚtransitionsÚ
isinstancer   r   Úis_final)Z
stack_nodeÚ
transition©r
   r   r   Úiterate=   s    

z@Stack._allowed_transition_names_and_token_types.<locals>.iterate)Úlist)r
   r#   r   r"   r   Ú)_allowed_transition_names_and_token_types<   s    z/Stack._allowed_transition_names_and_token_typesN)r   r   r   r%   r   r   r   r   r   ;   s   r   c                   @   s(   e Zd Zdd„ Zedd„ ƒZdd„ ZdS )Ú	StackNodec                 C   s   || _ g | _d S r   )r   Únodes)r
   r   r   r   r   r   M   s    zStackNode.__init__c                 C   s   | j jS r   )r   Ú	from_ruler"   r   r   r   ÚnonterminalQ   s    zStackNode.nonterminalc                 C   s   d| j j| j| jf S )Nz
%s(%s, %s))Ú	__class__r   r   r'   r"   r   r   r   Ú__repr__U   s    zStackNode.__repr__N)r   r   r   r   Úpropertyr)   r+   r   r   r   r   r&   L   s   
r&   c                 C   s,   |j jr(z| j| W S  ty&   Y n0 |S r   )r   Zcontains_syntaxZreserved_syntax_stringsÚKeyError)Úgrammarr   r   r   r   r   Ú_token_to_transitionY   s    r/   c                   @   sŒ   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d„Zdd	„ Zd
d„ Zdd„ Zdd„ Zdd„ Zd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                 C   s   || _ || _|| _d S r   )Ú_pgen_grammarÚ_start_nonterminalÚ_error_recovery)r
   Zpgen_grammarZstart_nonterminalÚerror_recoveryr   r   r   r   w   s    zBaseParser.__init__c                 C   sŠ   | j j| j d }tt|ƒgƒ| _|D ]}|  |¡ q&| jd }|jjs\t	d|j
|j|jƒ‚t| jƒdkrt|  ¡  q6|  |j|j¡S q6d S )Nr   éÿÿÿÿzincomplete inputé   )r4   Znonterminal_to_dfasr5   r   r&   ÚstackÚ
_add_tokenr   r    r   r   Ústringr   ÚlenÚ_popÚconvert_noder)   r'   )r
   ÚtokensZ	first_dfaÚtokenÚtosr   r   r   Úparse|   s    
ÿ
zBaseParser.parsec                 C   s:   | j rtdƒ‚n&|\}}}}t ||||¡}td|ƒ‚d S )Nz!Error Recovery is not implementedzSyntaxError: invalid syntax)r6   ÚNotImplementedErrorr   Z	ErrorLeafr   )r
   rA   r   r   r   Úprefixr	   r   r   r   r7   ’   s
    
zBaseParser.error_recoveryc                 C   s6   z| j | |ƒ}W n ty0   |  ||¡}Y n0 |S r   )r1   r-   Údefault_node)r
   r)   ÚchildrenÚnoder   r   r   r?   š   s
    zBaseParser.convert_nodec                 C   s:   z| j | |||ƒW S  ty4   |  |||¡ Y S 0 d S r   )r2   r-   Údefault_leaf)r
   r   r   rE   r   r   r   r   Úconvert_leaf¡   s    zBaseParser.convert_leafc                 C   sà   | j }| j}|\}}}}t|||ƒ}z|d jj| }	W q–W q$ tyt   |d jjr`|  ¡  n|  |¡ Y dS Y q$ t	y’   t
d|||ƒ‚Y q$0 q$|	j|d _|	jD ]}
| t|
ƒ¡ q¨|  ||||¡}|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.
        r8   Nztoo much input)r4   r:   r/   r   r   r-   r    r>   r7   Ú
IndexErrorr   Znext_dfaZ
dfa_pushesÚappendr&   rJ   r'   )r
   rA   r.   r:   r   r   r   rE   r!   ZplanÚpushÚleafr   r   r   r;   §   s&    



zBaseParser._add_tokenc                 C   sL   | j  ¡ }t|jƒdkr$|jd }n|  |jj|j¡}| j d j |¡ d S )Nr9   r   r8   )r:   Úpopr=   r'   r?   r   r(   rL   )r
   rB   Únew_noder   r   r   r>   Ç   s
    
zBaseParser._popN)r3   F)r   r   r   r   r1   r   Ústrr   r   ZBaseNodeÚ__annotations__ÚNoderF   r2   ZLeafrI   r   rC   r7   r?   rJ   r;   r>   r   r   r   r   r0   e   s   

 r0   N)r   Útypingr   r   Zparsor   Zparso.pgen2.generatorr   r   r   r   r$   r   r&   r/   r0   r   r   r   r   Ú<module>	   s   