o
    ˷e                     @   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.
    	expr_stmtclassdeffuncdef
file_inputimport_nameimport_from
break_stmtcontinue_stmtreturn_stmt
raise_stmt
yield_exprdel_stmt	pass_stmtglobal_stmtnonlocal_stmt
print_stmtassert_stmt)
if_stmt	with_stmtfor_stmt
while_stmttry_stmtsync_comp_for	decoratorlambdeflambdef_nocondnamedexpr_testTc                    s(   t  j|||d g | _g | _d| _d S )N)error_recoveryr   )super__init__syntax_errors_omit_dedent_list_indent_counter)selfpgen_grammarr!   start_nonterminal	__class__ J/var/www/ideatree/venv/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-   r2   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)	NAME_pgen_grammar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 )Nr6   r	   
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	   r4      )reversedlist	enumerater:   lennodes)stackuntil_index
stack_noder,   r,   r-   current_suite   s   

 z,Parser.error_recovery.<locals>.current_suiterN   r4   stmt) rT   rS   get_last_leafr/   rF   r   	ENDMARKERDEDENTrG   endswithdfa	from_ruletransitionsNEWLINEr8   next_dfais_final
dfa_pushes
_add_tokenr.   r"   r!   _stack_removalINDENTr%   appendr&   r   PythonErrorLeafnamer:   arcs)r'   token	tos_nodes	last_leafplanrW   rU   typrG   rI   rH   
error_leaf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,   )rS   ).0rV   r<   r,   r,   r-   
<listcomp>   s    z)Parser._stack_removal.<locals>.<listcomp>rN   )rT   r   PythonErrorNoderS   rg   bool)r'   start_index	all_nodesr<   r,   r,   r-   re      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   r6   rN   )r[   r%   r&   poprf   )r'   r3   rk   ro   or,   r,   r-   r1      s   zParser._recovery_tokenize)Tr	   )4__name__
__module____qualname____doc__r   ExprStmtClassFunctionModule
ImportName
ImportFromKeywordStatement
ReturnStmt	YieldExpr
GlobalStmt
AssertStmtIfStmtWithStmtForStmt	WhileStmtTryStmtSyncCompFor	DecoratorLambda	NamedExprr7   
PythonNoder9   r   STRINGStringNUMBERNumberr`   NewlinerZ   	EndMarkerFSTRING_STRINGFStringStringFSTRING_STARTFStringStartFSTRING_END
FStringEndrC   r#   r2   r=   rJ   r!   re   r1   __classcell__r,   r,   r*   r-   r      s    	
 
	
F
r   N)
parso.pythonr   parso.python.tokenr   parso.parserr   r>   rf   r[   r   r,   r,   r,   r-   <module>   s    