o
    'h                     @   s   U d Z ddlZddlZddlmZ ddlmZ ddlmZ ddlm	Z	 ddlm
Z
 ejr6ddlZdd	lmZ ed
ejejZedejejZeg dZeg dZejejejejejejdZ ej!e"ej#ej$ f e%d< G dd dZ&dS )z8Parse tokens from the lexer into nodes for the compiler.    N   )nodes)TemplateAssertionError)TemplateSyntaxError)describe_token)describe_token_expr)Environment_ImportInclude
_MacroCall)forifblockextendsprintmacroincludefromimportsetwith
autoescape)eqneltlteqgtgteq)addsubmuldivfloordivmod_math_nodesc                   @   s  e Zd ZdZ			ddddedeje deje deje d	dfd
dZdefdedeje	 dej
e d	dfddZdeje dejejedf  deje	 d	dfddZ	ddedeje	 d	dfddZ		ddejejedf  deje	 d	dfddZ	ddejejedf  d	efddZddeje	 d	ejfddZd	ejejejej f fd d!Z	"ddejedf d#ed	ejej fd$d%Zd	ejejejf fd&d'Zd	ejfd(d)Zd	ejfd*d+Z d	ej!fd,d-Z"d	ej#fd.d/Z$d	ej%fd0d1Z&d	ej'fd2d3Z(d4e)d5ed	e)fd6d7Z*d	ej+fd8d9Z,d	ej-fd:d;Z.d	ej/fd<d=Z0d4e1d	dfd>d?Z2d	ej3fd@dAZ4d	ej5fdBdCZ6d	ej7fdDdEZ8d	ej9fdFdGZ:e;j<	ddHedIdJd	ej=fdKdLZ>e;j<	M	"		"ddHedIedejejedf  dNed	ejej?ej=ejf f
dOdLZ>	M	"		"ddHedIedejejedf  dNed	ejej?ej=ejf f
dPdLZ>ddQed	ej@fdRdSZAd	ej@fdTdUZBd	ej@fdVdWZCd	ej@fdXdYZDd	ej@fdZd[ZEd	ej@fd\d]ZFd	ej@fd^d_ZGd	ej@fd`daZHd	ej@fdbdcZId	ej@fdddeZJddfed	ej@fdgdhZKddNed	ej@fdidjZL	"	M		"	"ddkedQedejejedf  dledNed	ejejej@f fdmdnZMd	ejfdodpZNd	ejOfdqdrZPd4ej@d	ej@fdsdtZQd4ej@d	ej@fdudvZRd4ej@d	ejejSejTf fdwdxZUd	ej@fdydzZVd	ejejej@ ejejW ejej@ ejej@ f fd{d|ZXd4ej@d	ejYfd}d~ZZ	"dd4ejej@ ded	ejej@ fddZ[d4ej@d	ej@fddZ\	ddejejedf  d	ejej fddZ]d	ej^fddZ_dS )ParserzThis is the central parsing class Jinja uses.  It's passed to
    extensions and can be used to parse expressions or statements.
    Nenvironmentr   sourcenamefilenamestatereturnc                 C   sl   || _ |||||| _|| _|| _d| _i | _| D ]}|jD ]}|j	| j|< q!qd| _
g | _g | _d S )NFr   )r%   	_tokenizestreamr'   r(   closed
extensionsiter_extensionstagsparse_last_identifier
_tag_stack_end_token_stack)selfr%   r&   r'   r(   r)   	extensiontag r8   I/var/www/html/olx_land/venv/lib/python3.10/site-packages/jinja2/parser.py__init__5   s   

zParser.__init__msglinenoexczte.NoReturnc                 C   s$   |du r	| j jj}|||| j| j)zConvenience method that raises `exc` with the message, passed
        line number or last line number as well as the current name and
        filename.
        N)r,   currentr<   r'   r(   )r5   r;   r<   r=   r8   r8   r9   failL   s   

zParser.failend_token_stack.c                 C   s   t  }|D ]
}|tt| q|r dtttt|d }nd }|d u r*dg}nd|dg}|rN|d urE||v rE|d| d n	|d| d | jr]|d| jd d | d	|| d S )
Nz or zUnexpected end of template.zEncountered unknown tag .z\You probably made a nesting mistake. Jinja is expecting this tag, but currently looking for z*Jinja was looking for the following tags: z/The innermost block that needs to be closed is  )	r   updatemapr   joinreprappendr3   r?   )r5   r'   r@   r<   expectedexprscurrently_lookingmessager8   r8   r9   _fail_ut_eofZ   s8   
zParser._fail_ut_eofc                 C   s   |  || j| dS )zCalled if the parser encounters an unknown tag.  Tries to fail
        with a human readable error message that could help to identify
        the problem.
        N)rM   r4   )r5   r'   r<   r8   r8   r9   fail_unknown_tag   s   zParser.fail_unknown_tag
end_tokensc                 C   s.   t | j}|dur|| | d|| dS )z9Like fail_unknown_tag but for end of template situations.N)listr4   rH   rM   )r5   rO   r<   stackr8   r8   r9   fail_eof   s   

zParser.fail_eofextra_end_rulesc                 C   s,   | j jjdv r	dS |dur| j j|S dS )zAre we at the end of a tuple?)variable_end	block_endrparenTNF)r,   r>   typetest_any)r5   rS   r8   r8   r9   is_tuple_end   s
   zParser.is_tuple_endc                 C   s8   |  j d7  _ ttj}tjj|d| j  |d |S )zDReturn a new free identifier as :class:`~jinja2.nodes.InternalName`.r   fir<   )r2   object__new__r   InternalNameNoder:   )r5   r<   rvr8   r8   r9   free_identifier   s   zParser.free_identifierc                 C   s,  | j j}|jdkr| d|j | j|j d}zs|jtv r6t	| d| j jj }| W |r5| j
  S S |jdkrH|  W |rG| j
  S S |jdkrZ|  W |rY| j
  S S | j|j}|durr|| W |rq| j
  S S | j
  d}| |j|j W |r| j
  dS dS |r| j
  w w )	zParse a single statement.r'   ztag name expectedTparse_callfilterNF)r,   r>   rW   r?   r<   r3   rH   value_statement_keywordsgetattrpopparse_call_blockparse_filter_blockr.   getrN   )r5   tokenpop_tagfextr8   r8   r9   parse_statement   sH   



	
zParser.parse_statementFdrop_needlec                 C   sL   | j d | j d | |}| j jjdkr| | |r$t| j  |S )aR  Parse multiple statements into a list until one of the end tokens
        is reached.  This is used to parse the body of statements as it also
        parses template data if appropriate.  The parser checks first if the
        current token is a colon and skips it if there is one.  Then it checks
        for the block end and parses until if one of the `end_tokens` is
        reached.  Per default the active token in the stream at the end of
        the call is the matched end token.  If this is not wanted `drop_needle`
        can be set to `True` and the end token is removed.
        colonrU   eof)r,   skip_ifexpectsubparser>   rW   rR   next)r5   rO   rq   resultr8   r8   r9   parse_statements   s   


zParser.parse_statementsc                 C   sf   t | jj}| jdd}| jdr|  }tj|||dS | d}| j	ddd}tj
||||dS )zParse an assign statement.Twith_namespaceassignr[   N)zname:endsetrq   )rw   r,   r<   parse_assign_targetrt   parse_tupler   Assignparse_filterry   AssignBlock)r5   r<   targetexprfilter_nodebodyr8   r8   r9   	parse_set   s   
zParser.parse_setc              	   C   s   | j dj}| jdd}| j d | jddd}d}| j d	r&|  }| j d
}| d}t| j j	dkr<g }n| jddd}t
j|||||||dS )zParse a for loop.zname:for)name:in)rS   r   F)name:recursive)with_condexprrS   Nname:ifr   )name:endfor	name:elseendfor)r   Tr}   r[   )r,   ru   r<   r~   r   rt   parse_expressionry   rw   re   r   For)r5   r<   r   itertest	recursiver   else_r8   r8   r9   	parse_for   s   
zParser.parse_forc                 C   s   t j| jdjd }}	 | jdd|_| d|_g |_	g |_
t| j}|dr;t j| jjjd}|j	| q|drH| jd	dd
|_
	 |S )zParse an if construct.r   r[   TFr   )	name:elifr   
name:endifr   r   )r   r}   )r   Ifr,   ru   r<   r   r   ry   r   elif_r   rw   r>   rH   )r5   noderx   rl   r8   r8   r9   parse_if   s   


zParser.parse_ifc                 C   s   t jt| jjd}g }g }| jjjdkr?|r| jd |  }|	d |
| | jd |
|   | jjjdks||_||_| jddd|_|S )	Nr[   rU   commaparamr|   )zname:endwithTr}   )r   Withrw   r,   r<   r>   rW   ru   r~   set_ctxrH   r   targetsvaluesry   r   )r5   r   r   r   r   r8   r8   r9   
parse_with  s    

zParser.parse_withc                 C   sD   t jt| jjd}t d|  g|_| jddd|_	t 
|gS )Nr[   r   )zname:endautoescapeTr}   )r   ScopedEvalContextModifierrw   r,   r<   Keywordr   optionsry   r   Scoper5   r   r8   r8   r9   parse_autoescape"  s   zParser.parse_autoescapec                 C   s   t jt| jjd}| jdj|_| jd|_	| jd|_
| jjjdkr,| d | jddd	|_|j
rR|jD ]}t|t jrLtd
d |j D rQ| d q:| jd|j  |S )Nr[   r'   zname:scopedzname:requiredr   zpBlock names in Jinja have to be valid Python identifiers and may not contain hyphens, use an underscore instead.)zname:endblockTr}   c                 s   s*    | ]}t |tj p|j  V  qd S N)
isinstancer   TemplateDatadataisspace).0output_noder8   r8   r9   	<genexpr>>  s    

z%Parser.parse_block.<locals>.<genexpr>z7Required blocks can only contain comments or whitespacezname:)r   Blockrw   r,   r<   ru   re   r'   rt   scopedrequiredr>   rW   r?   ry   r   r   Outputany)r5   r   	body_noder8   r8   r9   parse_block(  s$   

zParser.parse_blockc                 C   s"   t jt| jjd}|  |_|S Nr[   )r   Extendsrw   r,   r<   r   templater   r8   r8   r9   parse_extendsH  s   
zParser.parse_extendsr   defaultc                 C   sJ   | j jddr | j  dr t| j jdk|_| j   |S ||_|S )Nz	name:withzname:withoutname:contextr   )	r,   r>   rX   lookr   rw   re   with_contextskip)r5   r   r   r8   r8   r9   parse_import_contextM  s   
zParser.parse_import_contextc                 C   sb   t jt| jjd}|  |_| jjdr(| j	 dr(d|_
| jd nd|_
| |dS )Nr[   zname:ignorezname:missingT   F)r   Includerw   r,   r<   r   r   r>   r   r   ignore_missingr   r   r   r8   r8   r9   parse_includeY  s   
zParser.parse_includec                 C   sF   t jt| jjd}|  |_| jd | jddj	|_
| |dS )Nr[   name:asT	name_onlyF)r   Importrw   r,   r<   r   r   ru   r~   r'   r   r   r   r8   r8   r9   parse_importe  s
   
zParser.parse_importc                    s  t jtjjd   _jd g  _dt	f fdd}	  jr,jd jj
jdkrv| r7nFjdd	}|jd
rLjd|jtd jdrcjdd	} j|j|jf n j|j | stjj
jdkrunnjd q#t dsd _ S )Nr[   zname:importr*   c                      sB   j jjdv rj  drtj jdk _j   dS dS )N>   r   withoutr   r   TF)r,   r>   re   r   r   rw   r   r   r8   r   r5   r8   r9   parse_contextr  s   
z(Parser.parse_from.<locals>.parse_contextTr   r'   r   _z4names starting with an underline can not be imported)r=   r   r   F)r   
FromImportrw   r,   r<   r   r   ru   namesboolr>   rW   r~   r'   
startswithr?   r   rt   rH   hasattrr   )r5   r   r   aliasr8   r   r9   
parse_froml  s<   


zParser.parse_fromc                 C   s   g  }|_ g  }|_| jd | jjjdkrK|r| jd | jdd}|d | jdr8|	| 
  n|r?| d |	| | jjjdks| jd d S )	NlparenrV   r   Tr   r   r|   z-non-default argument follows default argument)argsdefaultsr,   ru   r>   rW   r~   r   rt   rH   r   r?   )r5   r   r   r   argr8   r8   r9   parse_signature  s   





zParser.parse_signaturec                 C   sv   t jt| jjd}| jjjdkr| | ng |_g |_	| 
 }t|t js.| d|j ||_| jddd|_|S )Nr[   r   zexpected call)zname:endcallTr}   )r   	CallBlockrw   r,   r<   r>   rW   r   r   r   r   r   Callr?   rc   ry   r   )r5   r   	call_noder8   r8   r9   ri     s   zParser.parse_call_blockc                 C   s8   t jt| jjd}| jd dd|_| jddd|_|S )Nr[   T)start_inline)zname:endfilterr}   )	r   FilterBlockrw   r,   r<   r   rd   ry   r   r   r8   r8   r9   rj     s   zParser.parse_filter_blockc                 C   sB   t jt| jjd}| jddj|_| | | jddd|_	|S )Nr[   Tr   )zname:endmacror}   )
r   Macrorw   r,   r<   r~   r'   r   ry   r   r   r8   r8   r9   parse_macro  s
   
zParser.parse_macroc                 C   s\   t jt| jjd}g |_ | jjjdkr,|j r| jd |j | 	  | jjjdks|S )Nr[   rU   r   )
r   r   rw   r,   r<   r>   rW   ru   rH   r   r   r8   r8   r9   parse_print  s   zParser.parse_print
with_tupler   zte.Literal[True]c                 C      d S r   r8   )r5   r   r   r8   r8   r9   r~     s   zParser.parse_assign_targetTr{   c                 C   r   r   r8   )r5   r   r   rS   r{   r8   r8   r9   r~     s   c                 C   s|   |r| j d}tj|jd|jd}n|r| jd||d}n| j|d}|d |	 s<| 
dt|j |j |S )a  Parse an assignment target.  As Jinja allows assignments to
        tuples, this function can parse all allowed assignment targets.  Per
        default assignments to tuples are parsed, that can be disable however
        by setting `with_tuple` to `False`.  If only assignments to names are
        wanted `name_only` can be set to `True`.  The `extra_end_rules`
        parameter is forwarded to the tuple parsing function.  If
        `with_namespace` is enabled, a namespace assignment may be parsed.
        r'   storer[   T)
simplifiedrS   r{   rz   zcan't assign to )r,   ru   r   Namere   r<   r   parse_primaryr   
can_assignr?   rW   __name__lower)r5   r   r   rS   r{   rl   r   r8   r8   r9   r~     s    
r   c                 C   s   |r|   S |  S )zParse an expression.  Per default all expressions are parsed, if
        the optional `with_condexpr` parameter is set to `False` conditional
        expressions are not parsed.
        )parse_condexprparse_orr5   r   r8   r8   r9   r      s   zParser.parse_expressionc                 C   sl   | j jj}|  }| j dr4|  }| j dr|  }nd }tj||||d}| j jj}| j ds|S )Nr   r   r[   )r,   r>   r<   r   rt   r   r   CondExpr)r5   r<   expr1expr2expr3r8   r8   r9   r   	  s   


zParser.parse_condexprc                 C   P   | j jj}|  }| j dr&|  }tj|||d}| j jj}| j ds|S )Nname:orr[   )r,   r>   r<   	parse_andrt   r   Orr5   r<   leftrightr8   r8   r9   r        

zParser.parse_orc                 C   r   )Nname:andr[   )r,   r>   r<   	parse_notrt   r   Andr   r8   r8   r9   r   !  r   zParser.parse_andc                 C   s4   | j jdrt| j j}tj|  |dS |  S )Nname:notr[   )	r,   r>   r   rw   r<   r   Notr   parse_compare)r5   r<   r8   r8   r9   r   *  s   zParser.parse_notc                 C   s   | j jj}|  }g }	 | j jj}|tv r&t| j  |t	||   n4| j 
dr8|t	d|   n"| j jdrY| j  drY| j d |t	d|   nn| j jj}q|sd|S tj|||dS )NTr   inr   r   notinr[   )r,   r>   r<   parse_math1rW   _compare_operatorsrw   rH   r   Operandrt   r   r   r   Compare)r5   r<   r   ops
token_typer8   r8   r9   r  0  s*   



zParser.parse_comparec                 C   j   | j jj}|  }| j jjdv r3t| j jj }t| j  |  }||||d}| j jj}| j jjdv s|S )N)r   r   r[   )r,   r>   r<   parse_concatrW   r#   rw   r5   r<   r   clsr   r8   r8   r9   r  G     


zParser.parse_math1c                 C   sj   | j jj}|  g}| j jjdkr$t| j  ||   | j jjdkst|dkr.|d S tj	||dS )Ntilder   r   r[   )
r,   r>   r<   parse_math2rW   rw   rH   lenr   Concat)r5   r<   r   r8   r8   r9   r  R  s   


zParser.parse_concatc                 C   r
  )N)r   r    r!   r"   r[   )r,   r>   r<   	parse_powrW   r#   rw   r  r8   r8   r9   r  \  r  zParser.parse_math2c                 C   s^   | j jj}|  }| j jjdkr-t| j  |  }tj|||d}| j jj}| j jjdks|S )Npowr[   )r,   r>   r<   parse_unaryrW   rw   r   Powr   r8   r8   r9   r  g  s   


zParser.parse_powwith_filterc                 C   s   | j jj}| j jj}|dkrt| j  tj| d|d}n|dkr2t| j  tj| d|d}n| 	 }| 
|}|rB| |}|S )Nr   Fr[   r   )r,   r>   rW   r<   rw   r   Negr  Posr   parse_postfixparse_filter_expr)r5   r  r	  r<   r   r8   r8   r9   r  q  s   





zParser.parse_unaryc                 C   s  | j j}|jdkr\t| j  |jdv r tj|jdv |jd}|S |jdv r/tjd|jd}|S |rP| j jjdkrPt| j  | j d}tj	|j|j|jd}|S tj
|jd|jd}|S |jd	krt| j  |jg}|j}| j jjd	kr|| j jj t| j  | j jjd	ksttjd
||d}|S |jdv rt| j  tj|j|jd}|S |jdkrt| j  | jdd}| j d |S |jdkr|  }|S |jdkr|  }|S | dt||j |S )zParse a name or literal value. If ``with_namespace`` is enabled, also
        parse namespace attr refs, for use in assignments.r'   )truefalseTrueFalse)r  r  r[   )noneNoneNdotloadstring )integerfloatr   T)explicit_parenthesesrV   lbracketlbracezunexpected )r,   r>   rW   rw   re   r   Constr<   ru   NSRefr   rH   rF   r   
parse_list
parse_dictr?   r   )r5   r{   rl   r   attrbufr<   r8   r8   r9   r     sV   


 










zParser.parse_primaryr   r(  c           
         s    j jj}|rdtjf fdd}ndtjf fdd}g }d}		 |r+ j d  |r1n||   j jjdkrAd}	nn j jj}q#|	s^|rP|d S |s^ 	d	t
 j j tj|d
|dS )a  Works like `parse_expression` but if multiple expressions are
        delimited by a comma a :class:`~jinja2.nodes.Tuple` node is created.
        This method could also return a regular expression instead of a tuple
        if no commas where found.

        The default parsing mode is a full tuple.  If `simplified` is `True`
        only names and literals are parsed; ``with_namespace`` allows namespace
        attr refs as well. The `no_condexpr` parameter is forwarded to
        :meth:`parse_expression`.

        Because tuples do not require delimiters and may end in a bogus comma
        an extra hint is needed that marks the end of a tuple.  For example
        for loops support tuples between `for` and `in`.  In that case the
        `extra_end_rules` is set to ``['name:in']``.

        `explicit_parentheses` is true if the parsing was triggered by an
        expression in parentheses.  This is used to figure out if an empty
        tuple is a valid expression or not.
        r*   c                          j dS )Nrz   )r   r8   )r5   r{   r8   r9   r1        z!Parser.parse_tuple.<locals>.parsec                      r1  )Nr   )r   r8   r   r8   r9   r1     r2  FTr   r   zExpected an expression, got r#  r[   )r,   r>   r<   r   Exprru   rY   rH   rW   r?   r   Tuple)
r5   r   r   rS   r(  r{   r<   r1   r   is_tupler8   )r5   r   r{   r9   r     s6   



zParser.parse_tuplec                 C   sv   | j d}g }| j jjdkr-|r| j d | j jjdkrn||   | j jjdks| j d tj||jdS )Nr)  rbracketr   r[   )	r,   ru   r>   rW   rH   r   r   Listr<   )r5   rl   itemsr8   r8   r9   r-    s   zParser.parse_listc                 C   s   | j d}g }| j jjdkr@|r| j d | j jjdkrn!|  }| j d |  }|tj|||jd | j jjdks| j d tj	||jdS )Nr*  rbracer   rr   r[   )
r,   ru   r>   rW   r   rH   r   Pairr<   Dict)r5   rl   r8  keyre   r8   r8   r9   r.    s   	zParser.parse_dictc                 C   sD   	 | j jj}|dks|dkr| |}n|dkr| |}n	 |S q)NTr"  r)  r   )r,   r>   rW   parse_subscript
parse_callr5   r   r	  r8   r8   r9   r    s   
zParser.parse_postfixc                 C   s^   	 | j jj}|dkr| |}n|dkr!| j jjdkr!| |}n|dkr+| |}n	 |S q)NTpiper'   isr   )r,   r>   rW   r   re   
parse_testr>  r?  r8   r8   r9   r    s   
zParser.parse_filter_exprc                 C   s&  t | j}|jdkrB| jj}t | j |jdkr#tj||jd|jdS |jdkr/| d|j tj	|j|jd}tj
||d|jdS |jdkrg }| jjjdkrf|rX| jd	 ||   | jjjdksP| jd t|d
krw|d }n	tj|d|jd}tj
||d|jdS | d|j d S )Nr"  r'   r#  r[   r&  zexpected name or numberr)  r6  r   r   r   zexpected subscript expression)rw   r,   rW   r>   r   Getattrre   r<   r?   r+  Getitemru   rH   parse_subscribedr  r4  )r5   r   rl   
attr_tokenr   r   r8   r8   r9   r=  )  s2   






zParser.parse_subscriptc                 C   s   | j jj}| j jjdkrt| j  d g}n|  }| j jjdkr"|S t| j  |g}| j jjdkr7|d  n| j jjdvrF||   n|d  | j jjdkrlt| j  | j jjdvrf||   n|d  n|d  tj|d|iS )Nrr   )r6  r   r<   )	r,   r>   r<   rW   rw   r   rH   r   Slice)r5   r<   r   r   r8   r8   r9   rE  H  s*   





zParser.parse_subscribedc           	         s~   j dg }g }d }d }d}dtdd f fdd} j jjdkr|r3 j d  j jjdkr3n j jjd	krN||d u oB|d u  t j    }n\ j jjd
kre||d u  t j    }nE j jjdkr j  jdkr||d u   j jj} j 	d   }|
tj|||jd n||d u o|d u o|  |
   d} j jjdks# j d ||||fS )Nr   Fr   r*   c                    s   | s  dj d S d S )Nz+invalid syntax for function call expression)r?   r<   )r   r5   rl   r8   r9   ensurew  s   z&Parser.parse_call_args.<locals>.ensurerV   r   r   r  r'   r|   r   r[   T)r,   ru   r   r>   rW   rw   r   r   re   r   rH   r   r   r<   )	r5   r   kwargsdyn_args
dyn_kwargsrequire_commarI  r<  re   r8   rH  r9   parse_call_argsh  sB   




"zParser.parse_call_argsc                 C   s0   | j j}|  \}}}}tj||||||jdS r   )r,   r>   rN  r   r   r<   )r5   r   rl   r   rJ  rK  rL  r8   r8   r9   r>    s   zParser.parse_callr   c           	   	   C   s   | j jjdks	|rg|st| j  | j d}|j}| j jjdkr7t| j  |d| j dj 7 }| j jjdks | j jjdkrG|  \}}}}ng }g }d  }}tj|||||||j	d}d}| j jjdks	|s	|S )Nr@  r'   r"  rB   r   r[   F)
r,   r>   rW   rw   ru   re   rN  r   Filterr<   )	r5   r   r   rl   r'   r   rJ  rK  rL  r8   r8   r9   r     s(   

zParser.parse_filterc           
   	   C   s*  t | j}| jjdrt | j d}nd}| jdj}| jjjdkr;t | j |d| jdj 7 }| jjjdks$d  }}g }| jjjdkrQ|  \}}}}n+| jjjdv rz| jjd	d
dsz| jjdrm| 	d | 
 }	| |	}	|	g}ng }tj|||||||jd}|rtj||jd}|S )Nr   TFr'   r"  rB   r   >   r'   r'  r*  r   r$  r&  r)  r   r   r   zname:isz'You cannot chain multiple tests with isr[   )rw   r,   r>   r   ru   re   rW   rN  rX   r?   r   r  r   Testr<   r   )
r5   r   rl   negatedr'   rK  rL  rJ  r   arg_noder8   r8   r9   rB    s:   


	

zParser.parse_testc                    sh  g  g j }|d ur| j | d fdd}z| jr| jj}|jdkr:|jr4|tj|j|jd t	| j n]|jdkrSt	| j || j
dd | jd	 nD|jd
kr|  t	| j |d urx| jjj| rx W |d urw| j  S S |  }t|tr | n  | | jd ntd| js|  W |d ur| j   S |d ur| j  w w )Nr*   c                     s<   rd j }  tjd d  | d d d = d S d S )Nr   r[   )r<   rH   r   r   r[   r   data_bufferr8   r9   
flush_data  s
   
z#Parser.subparse.<locals>.flush_datar   r[   variable_beginTr   rT   block_beginrU   zinternal parsing error)r*   N)rH   r4   r,   r>   rW   re   r   r   r<   rw   r   ru   rX   rh   rp   r   rP   extendAssertionError)r5   rO   add_datarU  rl   r`   r8   rS  r9   rv     sR   







zParser.subparsec                 C   s"   t j|  dd}|| j |S )z0Parse the whole template into a `Template` node.r   r[   )r   Templaterv   set_environmentr%   )r5   rx   r8   r8   r9   r1     s   zParser.parse)NNNr   )NN)F)..)TFNF)T)FTNFF)`r   
__module____qualname____doc__strtOptionalr:   r   intTyper?   r7  r4  rM   rN   rR   r   rY   r   r^   ra   Unionr_   rp   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r	   r   r   r   r   r   r   r   r
   r   r   ri   r   rj   r   r   r   r   typingoverloadr   r~   r,  r3  r   r   r   r   r   r  r  r  r  r  r  r   r   r-  r;  r.  r  r  rC  rD  r=  rE  r   rN  r   r>  r   rB  rv   r[  r1   r8   r8   r8   r9   r$   0   s   


)



"

 
*	

'			

,
E
 




8


'

1r$   )'r_  rf  ra  r%  r   
exceptionsr   r   lexerr   r   TYPE_CHECKINGtyping_extensionster%   r   TypeVarr   r   r	   r   r   r
   	frozensetrf   r  AddSubMulDivFloorDivModr#   r;  r`  rd  r3  __annotations__r$   r8   r8   r8   r9   <module>   s2     
