o
    Zh                     @   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                       sV  e Zd ZdZi dejdejdejdejdej	dej
dejd	ejd
ejdejdejdejdejdejdejdejd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_stmt)
Zif_stmtZ	with_stmtZfor_stmtZ
while_stmtZtry_stmtZsync_comp_for	decoratorZlambdefZlambdef_nocondZnamedexpr_testTc                    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__ J/var/www/html/lang_env/lib/python3.10/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 |S  ty)   |dkr |d g|dd  }| ||}Y |S w )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r|| 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ra|jtjks-|jtkra|j	dsa|j	dsa| j d j
jdkraz| j d j
jtj }W n	 tyK   Y nw |jjra|jsa|j| j d _
| | d S | jsjt |S dd }|| j }| |d r| | n#|\}}}	}
|tkr| j| j t|j||	|
}| j d j| | j d }|jd	krz
|j
jd
 |_
W d S  ty   Y d S w d S )Nr   r   
Zsimple_stmtc                 S   sL   t tt| D ]\}}|jdkr |S |jdkr#t|jdkr# |S q|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   sL   





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>   s    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   s|    |D ]8}|d }|t kr-| j}|r%|d | jkr%|  |  jd8  _q|  jd8  _n|tkr8|  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      s    	
 
	
F
r   N)
Zparso.pythonr   Zparso.python.tokenr   Zparso.parserr   r#   rA   r<   r   r   r   r   r   <module>   s    