o
    .d                  
   @   s*  d 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 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 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 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 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% ddl!m&Z& ddl!m'Z' ddl!m(Z( ddl!m)Z) dee deee  fd d!Z*dee d"e+de	ee eee  f fd#d$Z,ee,e)d%Z-ee,e$d%Z.ee,e(d%Z/ee,e%d%Z0dee d&e1defd'd(Z2d0d*e+d&e1defd+d,Z3d0d*e+d&e1defd-d.Z4d/S )1z;Functions for parsing non-standard conditional expressions.    )partial)Dict)Iterable)Iterator)List)Optional)Tuple)LiquidSyntaxError)FALSE)ConditionalExpression)
Expression)Filter)FilteredExpression)	parse_obj)parse_obj_with_parens)Token)tokenize)tokenize_with_parens)parse_from_tokens)TokenStream)TOKEN_COLON)TOKEN_COMMA)TOKEN_DPIPE)
TOKEN_ELSE)	TOKEN_EOF)TOKEN_IDENTIFIER)TOKEN_IF)
TOKEN_PIPEtokensreturnc                 c   s<    g }| D ]}|d t kr|V  g }q|| q|V  dS )z;Split tokens into lists, using TOKEN_PIPE as the delimiter.   N)r   append)r   buftoken r$   \/var/www/Matress/matenv/lib/python3.10/site-packages/liquid/expressions/conditional/parse.pysplit_at_pipe&   s   
r&   _typec                 C   s8   g }| D ]}|d |kr|| f  S | | q|d fS )Nr    )r!   )r   r'   r"   r#   r$   r$   r%   _split_at_first2   s   r(   )r'   linenumc                 C   s  | st d|dtt| }|t |jd }t| |jd tkr(t|g S |t	 t| g }i }|jd tkr{|j
d t	krY|t t|d }t| t|||< n|t| t| |jd tkrt|t t| |jd tks<t|||S )Nz&unexpected pipe or missing filter namer)      r    )r	   r   iterexpectr   currentnextr   r   r   peekr   r!   r   )r   r)   streamnameargskwargskeyr$   r$   r%   _parse_filterD   s6   





r6   r    exprc                       t |  }t|\}}tt| }|s|S t|\}}tt|\}}|r0ttt| }	nt}	|rEt	|}
|
rBtt|
 }nd}nd}|rW fddt
t|D }ng }t|||	|S )z&Parse a conditional expression string.Nc                       g | ]}t | qS r$   r6   .0_tokensr*   r$   r%   
<listcomp>       zparse.<locals>.<listcomp>)r   split_at_first_ifparse_standard_filteredr,   split_at_first_dpipesplit_at_first_elseparse_boolean_objr   r
   listr&   r   r7   r)   r   standard_tokens_conditional_tokens_exprconditional_tokens_filter_tokens_alternative_tokens	conditionalternative_tokensalternativetail_filtersr$   r*   r%   parseo   s4   


rQ   c                    r8   )zParse a conditional expression string.

    This parse function handles logical `not` and grouping terms with parentheses.
    Nc                    r9   r$   r:   r;   r*   r$   r%   r>      r?   z%parse_with_parens.<locals>.<listcomp>)r   r@   rA   r,   rB   rC   parse_boolean_obj_with_parensr   r
   rE   r&   r   rF   r$   r*   r%   parse_with_parens   s8   


rS   N)r    )5__doc__	functoolsr   typingr   r   r   r   r   r   liquid.exceptionsr	   liquid.expressionr
   r   r   r   r    liquid.expressions.boolean.parser   rD   r   rR   liquid.expressions.commonr   "liquid.expressions.conditional.lexr   r   !liquid.expressions.filtered.parser   rA   liquid.expressions.streamr   liquid.tokenr   r   r   r   r   r   r   r   r&   strr(   split_at_first_piperB   r@   rC   intr6   rQ   rS   r$   r$   r$   r%   <module>   sZ    
+0