a
    �Ï?e-  ã                   @   sp  U d Z ddlZddlZddlZe d¡Zejed< e d¡Zejed< e dej	¡Z
ejed< e d	¡Zejed
< ejeeeef Zeje Zeje edœdd„Zdeeedœdd„Zejeejeef f Zdeeeeeje dœdd„Zd eeeeeje dœdd„Zejeejeef f Zd!eeeeedœdd„Zejeeef Zd"eje eeeeedœdd„Z dS )#zMisc simple parsers.é    Nz^(\d|([1-9]\d+))$ÚINT_PATTERNz^\d+[\.]\d+$ÚFLOAT_PATTERNz^(true|false)$ÚBOOL_PATTERNz^['\"](.*)['\"]$ÚSTR_PATTERN)Ústr_Úreturnc                 C   s|   | du rdS |   ¡ } | sdS t | ¡dur2t| ƒS t | ¡durHt| ƒS t | ¡dur^t| ƒS t | ¡durx| dd… S | S )z,Parse an expression gives a primitive value.NÚ é   éÿÿÿÿ)	Ústripr   ÚmatchÚboolr   Úintr   Úfloatr   )r   © r   úS/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/anyconfig/parser.pyÚparse_single   s    r   ú,)r   Úsepr   c                 C   s   dd„ |   |¡D ƒS )z®Parse an expression gives a list of values.

    An expression ``str_`` might contain a list of str-es separated with
    ``sep``, represents a list of primitive values.
    c                 S   s   g | ]}|rt |ƒ‘qS r   )r   )Ú.0Úxr   r   r   Ú
<listcomp>3   ó    zparse_list.<locals>.<listcomp>)Úsplit)r   r   r   r   r   Ú
parse_list-   s    r   ú:ú;)r   Úavs_sepÚvs_sepÚas_sepr   c              
   c   s®   t | |ƒD ]ž}t t|¡}||vs
| |¡r.q
t ||ƒ^}}}|r`t d|›d|›d|› d�¡ t t|¡}|t|ƒv r’|t t t|¡|ƒfV  q
|r
|t t|¡fV  q
dS )aC  Parse a list of atrribute and value pairs.

    This is a helper function for parse_attrlist_0.

    :param str_: String represents a list of pairs of attribute and value
    :param avs_sep: char to separate attribute and values
    :param vs_sep: char to separate values
    :param as_sep: char to separate attributes
    zExtra strings z in z It should be in the form of attrzvalue.N)r   ÚtypingÚcastÚstrÚendswithÚwarningsÚwarnÚ
PrimitiveT)r   r   r   r   ÚrelZ_attrZ_valuesÚ_restr   r   r   Úattr_val_itr9   s    ÿ
r)   c                 C   s   t t| |||ƒƒS )a:  Parse a list of atrribute and value pairs.

    This is a helper function for parse_attrlist.

    The expressions to parse should be in the form of
    [ATTR1:VAL0,VAL1,...;ATTR2:VAL0,VAL2,..].

    :param str_: input string
    :param avs_sep:  char to separate attribute and values
    :param vs_sep:  char to separate values
    :param as_sep:  char to separate attributes

    :return:
        a list of tuples of (key, value | [value])
            where key = (Int | String | ...),
            value = (Int | Bool | String | ...) | [Int | Bool | String | ...]
    )Úlistr)   ©r   r   r   r   r   r   r   Úparse_attrlist_0W   s    r,   c                 C   s   t t| |||ƒƒS )aJ  Parse a list of atrribute and value pairs.

    The expressions to parse should be in the form of
    [ATTR1:VAL0,VAL1,...;ATTR2:VAL0,VAL2,..].

    :param str_: input string
    :param avs_sep:  char to separate attribute and values
    :param vs_sep:  char to separate values
    :param as_sep:  char to separate attributes
    )Údictr,   r+   r   r   r   Úparse_attrlistp   s    r.   )r   ÚlsepÚavsepÚvssepÚavssepr   c                 C   sD   | du s| st | ƒS || v r*t| |||ƒS || v r<t| |ƒS t | ƒS )zVery simple generic parser.N)r   r.   r   )r   r/   r0   r1   r2   r   r   r   Úparse†   s    
r3   )r   )r   r   r   )r   r   r   )r   r   r   )r   r   r   r   )!Ú__doc__Úrer    r$   Úcompiler   ÚPatternÚ__annotations__r   ÚIr   r   ÚUnionr"   r   r   r   r&   ÚListZPrimitivesTÚOptionalr   r   ÚTupleZ	AttrValsTÚIteratorr)   r,   ÚDictZAttrValsDictTr.   ZResultsTr3   r   r   r   r   Ú<module>   sP   
	  ÿ
ÿ  ÿ
ÿ  ÿÿþÿ  þ
þ