a
    lc                     @   sJ   d dl mZ d dlmZ d dlmZ ejZejZejZG dd deZ	dS )    )tree)PythonTokenTypes)
BaseParserc                       s  e Zd ZdZejejejejej	ej
ejejejejejejejejejejejejejejejejejejejejejdZejZejejejej ej!ej"ej#ej$ej%ej&ej'ej(ej)ej*iZ+d fdd	Z, fddZ-d	d
 Z.dd Z/ fddZ0dd Z1dd Z2  Z3S )Parserz
    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.
    )Z	expr_stmtZclassdefZfuncdef
file_inputimport_nameZimport_fromZ
break_stmtZcontinue_stmtZreturn_stmtZ
raise_stmtZ
yield_exprZdel_stmtZ	pass_stmtZglobal_stmtZnonlocal_stmtZ
print_stmtZassert_stmtZif_stmtZ	with_stmtZfor_stmtZ
while_stmtZtry_stmtZsync_comp_for	decoratorZlambdefZlambdef_nocondZnamedexpr_testTr   c                    s(   t  j|||d g | _g | _d| _d S )N)error_recoveryr   )super__init__Zsyntax_errors_omit_dedent_list_indent_counter)selfZpgen_grammarr	   Zstart_nonterminal	__class__ O/var/www/html/django/DPS/env/lib/python3.9/site-packages/parso/python/parser.pyr   @   s    
zParser.__init__c                    s*   | j r| jdkrt| |}t |S )Nr   )_error_recovery_start_nonterminalNotImplementedError_recovery_tokenizer
   parse)r   tokensr   r   r   r   H   s
    

zParser.parsec                 C   sT   z| j | |}W n< tyN   |dkr>|d g|dd  }| ||}Y n0 |S )a  
        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.
        suiter      )node_mapKeyErrordefault_node)r   nonterminalchildrennoder   r   r   convert_nodeQ   s    zParser.convert_nodec                 C   sH   |t kr0|| jjv r"t|||S t|||S | j|tj|||S )N)	NAMEZ_pgen_grammarZreserved_syntax_stringsr   KeywordName	_leaf_mapgetOperator)r   typevalueprefix	start_posr   r   r   convert_leafe   s
    zParser.convert_leafc                    s  | j d j}|r|d  }nd }| jdkr|jtjksZ|jtkr|j	ds|j	ds| j d j
jdkrz| j d j
jtj }W n ty   Y n,0 |jjr|js|j| j d _
| | d S | jst |S dd }|| j }| |d r| | nH|\}}}	}
|tkr&| j| j t|j||	|
}| j d j| | j d }|jd	krz|j
jd
 |_
W n ty   Y n0 d S )Nr   r   
Zsimple_stmtc                 S   sJ   t tt| D ]4\}}|jdkr( qFq|jdkrt|jdkr qFq|S )Nr   r      )reversedlist	enumerater   lennodes)stackuntil_index
stack_noder   r   r   current_suite   s    

z,Parser.error_recovery.<locals>.current_suiter0   r   stmt) r6   r5   Zget_last_leafr   r)   r   	ENDMARKERDEDENTr*   endswithZdfaZ	from_ruleZtransitionsNEWLINEr   Znext_dfais_finalZ
dfa_pushesZ
_add_tokenr   r
   r	   _stack_removalINDENTr   appendr   r   ZPythonErrorLeafnamer   Zarcs)r   tokenZ	tos_nodesZ	last_leafZplanr9   r7   typr*   r,   r+   Z
error_leafZtosr   r   r   r	   o   sN    







zParser.error_recoveryc                 C   sR   dd | j |d  D }|r<t|}| j |d  j| g | j |d < t|S )Nc                 S   s   g | ]}|j D ]}|qqS r   )r5   ).0r8   r!   r   r   r   
<listcomp>       z)Parser._stack_removal.<locals>.<listcomp>r0   )r6   r   ZPythonErrorNoder5   rB   bool)r   start_indexZ	all_nodesr!   r   r   r   r@      s    
zParser._stack_removalc                 c   sz   |D ]p}|d }|t krX| j}|rH|d | jkrH|  |  jd8  _q|  jd8  _n|tkrn|  jd7  _|V  qd S )Nr   r   r0   )r<   r   r   poprA   )r   r   rD   rE   or   r   r   r      s    zParser._recovery_tokenize)Tr   )4__name__
__module____qualname____doc__r   ZExprStmtClassFunctionModuleZ
ImportName
ImportFromZKeywordStatementZ
ReturnStmtZ	YieldExprZ
GlobalStmtZ
AssertStmtZIfStmtZWithStmtZForStmtZ	WhileStmtZTryStmtZSyncCompFor	DecoratorLambda	NamedExprr   Z
PythonNoder   r   STRINGStringNUMBERNumberr>   ZNewliner;   Z	EndMarkerZFSTRING_STRINGZFStringStringZFSTRING_STARTZFStringStartZFSTRING_ENDZ
FStringEndr&   r   r   r"   r-   r	   r@   r   __classcell__r   r   r   r   r      sZ    
	
F
r   N)
Zparso.pythonr   Zparso.python.tokenr   Zparso.parserr   r#   rA   r<   r   r   r   r   r   <module>   s   