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 eeef Zefdeeegef dedeegee f fdd„Zdededefdd„ZeeeƒZ eeeƒZ!d-dede"deeef fd d!„Z#dededefd"d#„Z$dededefd$d%„Z%ee$eƒZ&ee%eƒZ'dedefd&d'„Z(d-dede"deeee f fd(d)„Z)d-dede"deeee f fd*d+„Z*d,S ).zGeneric argument list parsers.é    )ÚAny)ÚCallable)ÚDict)ÚList)ÚOptional)ÚTuple)ÚLiquidSyntaxError)ÚNIL)Ú
Expression)Útokenize)Úparse_unchained_identifier)Ú	parse_obj)ÚTokenStream)ÚTOKEN_COLON)ÚTOKEN_COMMA)Ú	TOKEN_EOF)ÚTOKEN_EQUALS)ÚTOKEN_IDENTIFIER)ÚTOKEN_STRINGÚfuncÚseparator_tokenÚreturnc                    s    dt dtt f‡ ‡fdd„}|S )z0Return an argument list parser that uses _func_.Ústreamr   c                    s€   g }| j d tkrt| ƒ | j d tkr>| ˆ | ˆƒ¡ t| ƒ | j d tkr,|  t¡ | j d tkr7t| ƒ | j d tks|S )z2Parse arguments from a stream of tokens until EOF.é   )Úcurrentr   Únextr   ÚappendÚexpect)r   Úargs©r   r   © úZ/var/www/Matress/matenv/lib/python3.10/site-packages/liquid/expressions/arguments/parse.pyÚ_parse_arguments    s   
ø
z.make_parse_arguments.<locals>._parse_arguments)r   r   ÚArgument)r   r   r"   r    r   r!   Úmake_parse_arguments   s   r$   r   c                 C   s2   t t| ƒƒ}t| ƒ |  |¡ t| ƒ |t| ƒfS )z8Parse a single keyword argument from a stream of tokens.)Ústrr   r   r   r   ©r   r   Úkeyr    r    r!   Úparse_argument6   s
   
r(   r   ÚexprÚlinenumc                 C   s   t ttt| |ƒƒƒƒS )aê  Parse keyword or named arguments from a Liquid expression string.

    Each key/value pair is assumed to be separated by a comma. Leading and
    trailing commas are OK.

    If the same key/name appears multiple times, the last occurrence in the
    argument "list" will take priority.

    Values can be string, integer, float, true, false or nil literals, an
    identifier or a range expression. An identifier value could be chained
    using a mixture of dot and bracket notation.
    )ÚdictÚparse_colon_separated_argumentsr   r   )r)   r*   r    r    r!   Úparse_keyword_argumentsC   s   r-   c                 C   sF   t t| ƒƒ}| jd |krt| ƒ t| ƒ t| ƒ}||fS t}||fS )zËParse either a positional or keyword argument.

    If the separator token appears after an identifier, the argument is a keyword
    argument. Otherwise it is positional, with an expression of NIL.
    r   )r%   r   Úpeekr   r   r	   )r   r   r'   Úvalr    r    r!   Úparse_macro_argumentS   s   ÿr0   c                 C   s<   | j d |krtt| ƒƒ}t| ƒ t| ƒ nd}|t| ƒfS )z9Parse an argument value that could be preceded by a name.r   N)r.   r%   r   r   r   r&   r    r    r!   Úparse_call_argumente   s   
r1   c                 C   s<   | j d ttfv r| j d S td| j d › d| j d d‚)Nr   é   zinvalid macro name 'ú'r   )r*   )r   r   r   r   )r   r    r    r!   Ú_parse_macro_namew   s
   
ÿr4   c                 C   ó*   t t| |ƒƒ}t|ƒ}t|ƒ |t|ƒfS )zAParse a sequence of argument names, possibly with default values.)r   r   r4   r   Ú_parse_macro_arguments©r)   r*   r   Únamer    r    r!   Úparse_macro_arguments   ó   r9   c                 C   r5   )z8Parse a sequence of positional and/or keyword arguments.)r   r   r4   r   Ú_parse_call_argumentsr7   r    r    r!   Úparse_call_arguments‡   r:   r<   N)r   )+Ú__doc__Útypingr   r   r   r   r   r   Úliquid.exceptionsr   Úliquid.expressionr	   r
   Ú liquid.expressions.arguments.lexr   Úliquid.expressions.commonr   Ú!liquid.expressions.filtered.parser   Úliquid.expressions.streamr   Úliquid.tokenr   r   r   r   r   r   r#   r%   r$   r(   r,   Ú parse_equals_separated_argumentsÚintr-   r0   r1   r6   r;   r4   r9   r<   r    r    r    r!   Ú<module>   sP    þÿþ
ý
	
 

$(