
    f                         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e      Z	y)    )tree)PythonTokenTypes)
BaseParserc                   @    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j0                  d
Zej4                  Zej:                  ej<                  ej>                  ej@                  ejB                  ejD                  ejF                  ejH                  ejJ                  ejL                  ejN                  ejP                  ejR                  ejT                  iZ+d fd	Z, fdZ-d Z.d Z/ fdZ0d Z1d Z2 x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_testc                 T    t         |   |||       g | _        g | _        d| _        y )N)error_recoveryr   )super__init__syntax_errors_omit_dedent_list_indent_counter)selfpgen_grammarr$   start_nonterminal	__class__s       N/var/www/cvtools/html/venv/lib/python3.12/site-packages/parso/python/parser.pyr&   zParser.__init__@   s7    '8(6 	 	8  !#     c                     | j                   r&| j                  dk7  rt        | j                  |      }t        |   |      S )Nr   )_error_recovery_start_nonterminalNotImplementedError_recovery_tokenizer%   parse)r*   tokensr-   s     r.   r5   zParser.parseH   s?    &&,6)),,V4Fw}V$$r/   c                     	  | j                   |   |      }|S # t        $ r' |dk(  r|d   g|dd z   }| j                  ||      }Y |S w xY 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nodes       r.   convert_nodezParser.convert_nodeQ   sk    		<-4==-h7D   	<g%
 %QK=8Ab>9$$[(;D	<s    ,A	A	c                    |t         k(  rF|| j                  j                  v rt        j                  |||      S t        j
                  |||      S  | j                  j                  |t        j                        |||      S )N)	NAME_pgen_grammarreserved_syntax_stringsr   KeywordName	_leaf_mapgetOperator)r*   typevalueprefix	start_poss        r.   convert_leafzParser.convert_leafe   si    4<**BBB||E9f==yy	6::6t~~!!$6uiPPr/   c                    | j                   d   j                  }|r|d   j                         }nd }| j                  dk(  r|j                  t
        j                  k(  sI|j                  t        k(  r|j                  j                  d      s|j                  j                  d      s| j                   d   j                  j                  dk(  r	 | j                   d   j                  j                  t
        j                     }|j                  j                  r<|j                   s0|j                  | j                   d   _
        | j#                  |       y | j&                  st(        | U  |      S d } || j                         }| j-                  |dz         r| j#                  |       n|\  }}}	}
|t.        k(  r%| j0                  j3                  | j4                         t7        j8                  |j:                  ||	|
      }| j                   d   j                  j3                  |       | j                   d   }|j<                  dk(  r 	 |j                  j>                  d	   |_
        y y # t$        $ r Y  w xY w# t$        $ r Y y w xY w)
Nr:   r   
simple_stmtc                     t        t        t        |                   D ]B  \  }}|j                  dk(  r |S |j                  dk(  s(t	        |j
                        dk7  sA |S  S )Nr   r8      )reversedlist	enumerater>   lennodes)stackuntil_index
stack_nodes      r.   current_suitez,Parser.error_recovery.<locals>.current_suite   sv     ,4D59I4J+K 	'Z))\9   ++w6 :++,1	 r/   rU   r8   stmt) r[   rZ   get_last_leafr2   rK   r   	ENDMARKERDEDENTrL   endswithdfa	from_ruletransitionsNEWLINEnext_dfais_final
dfa_pushes
_add_tokenr<   r1   r%   r$   _stack_removalINDENTr(   appendr)   r   PythonErrorLeafnamer>   arcs)r*   token	tos_nodes	last_leafplanr^   r\   typrL   rN   rM   
error_leaftosr-   s                r.   r$   zParser.error_recoveryo   s   JJrN((	!"335II""l2/999JJ&(1I1I$1O"11$7
 zz"~!!++}<
::b>--99:J:R:RSD }}--doo .2]]

2*.##7)%00	 $DJJ/{Q/OOE",1)C	6f} &&--d.B.BC--chhy&QJJJrN  ''
3jjn??g%'',,v.	 &W   `  s$   4I* 
I: *	I76I7:	JJc                 $   | j                   |d  D cg c]  }|j                  D ]  }|  }}}|r@t        j                  |      }| j                   |dz
     j                  j	                  |       g | j                   |d  t        |      S c c}}w )NrU   )r[   rZ   r   PythonErrorNodern   bool)r*   start_indexr]   r@   	all_nodess        r.   rl   zParser._stack_removal   s    ,0JJ{|,DbjQ[QaQabTbTb	b''	2DJJ{Q'--44T:#%

;< I cs   Bc              #   2  K   |D ]  }|d   }|t         k(  r\| j                  }|r8|d   | j                  k(  r&|j                          | xj                  dz  c_        W| xj                  dz  c_        n|t        k(  r| xj                  dz  c_        |  y w)Nr   r:   rU   )rb   r(   r)   poprm   )r*   r6   rr   rv   os        r.   r4   zParser._recovery_tokenize   s      	E(Cf} **2$"6"66EEG((A-($$)$$$)$K	s   BB)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	NamedExprr;   
PythonNoder=   r   STRINGStringNUMBERNumberrg   Newlinera   	EndMarkerFSTRING_STRINGFStringStringFSTRING_STARTFStringStartFSTRING_END
FStringEndrH   r&   r5   rA   rO   r$   rl   r4   __classcell__)r-   s   @r.   r   r      s"   T]]DJJ 	4== 	dkk	
 	t 	t 	d++ 	.. 	t 	d++ 	dnn 	D)) 	T** 	t 	..  	d++!" 	t#$ ;;]]LLnnLL)) ^^;;++..=H@ ??L 	  $,,""DNN''););&&(9(9$$dooI!%(QDLr/   r   N)
parso.pythonr   parso.python.tokenr   parso.parserr   rC   rm   rb   r    r/   r.   <module>r      s?     / # 		 	 		 	 CZ Cr/   