a
    ֶa                     @   s(  d dl Z d dlZd dlZd dlZd dlmZ d dlmZmZm	Z	 e
dZG dd dZeddeeed	d
dZeddeeed	ddZeddeeed	ddZG dd dZG dd dZG dd dZG dd deZeedddZd"eee	e f eedddZeedd d!ZdS )#    N)	lru_cache)ListUnionIterable\   c                   @   sZ   e Zd ZU dZg Zee ed< g Zee ed< dZ	e
dd Ze
dd Ze
d	d Zd
S )__config_flagsz=Internal class for defining compatibility and debugging flags
_all_names_fixed_namesconfigurationc                 C   sd   || j v r6td| j|| jtt| |  d S || j	v rNt
| || ntd| j|d S )Nz'{}.{} {} is {} and cannot be overriddenzno such {} {!r})r	   warningswarnformat__name__
_type_descstrgetattrupperr   setattr
ValueError)clsZdnamevalue r   ^/Users/vegardjervell/Documents/master/model/venv/lib/python3.9/site-packages/pyparsing/util.py_set   s    

z__config_flags._setc                 C   s   |  |dS )NTr   r   namer   r   r   <lambda>$       z__config_flags.<lambda>c                 C   s   |  |dS )NFr   r   r   r   r   r   %   r   N)r   
__module____qualname____doc__r   r   r   __annotations__r	   r   classmethodr   enabledisabler   r   r   r   r      s   

r      )maxsize)locstrgreturnc                 C   sF   |}d|   k rt |k r4n n|| d  dkr4dS | |dd|  S )a  
    Returns current column within a string, counting newlines as line separators.
    The first column is number 1.

    Note: the default parsing behavior is to expand tabs in the input string
    before starting the parsing process.  See
    :class:`ParserElement.parseString` for more
    information on parsing strings containing ``<TAB>`` s, and suggested
    methods to maintain a consistent view of the parsed string, the parse
    location, and line and column positions within the parsed string.
    r      
)lenrfind)r(   r)   sr   r   r   col(   s    r0   c                 C   s   | dd| d S )a  Returns current line number within a string, counting newlines as line separators.
    The first line is number 1.

    Note - the default parsing behavior is to expand tabs in the input string
    before starting the parsing process.  See :class:`ParserElement.parseString`
    for more information on parsing strings containing ``<TAB>`` s, and
    suggested methods to maintain a consistent view of the parsed string, the
    parse location, and line and column positions within the parsed string.
    r,   r   r+   )count)r(   r)   r   r   r   lineno9   s    r2   c                 C   sB   | dd| }|d| }|dkr2||d | S ||d d S )zh
    Returns the line of text containing loc within a string, counting newlines as line separators.
    r,   r   r+   N)r.   find)r(   r)   Zlast_crZnext_crr   r   r   lineG   s    r4   c                   @   s   e Zd Zdd ZdS )_UnboundedCachec                    sp   i   j t  | _fdd} fdd} fdd}d | _t|| | _ t|| | _t|| | _d S )Nc                    s
    |S Nr   _key	cache_getnot_in_cacher   r   getW   s    z%_UnboundedCache.__init__.<locals>.getc                    s   | |< d S r6   r   r8   r9   r   cacher   r   set_Z   s    z&_UnboundedCache.__init__.<locals>.set_c                    s       d S r6   clearr8   r?   r   r   rC   ]   s    z'_UnboundedCache.__init__.<locals>.clear)r=   objectr<   sizetypes
MethodTypesetrC   )selfr=   rA   rC   r   )r@   r;   r<   r   __init__R   s    z_UnboundedCache.__init__Nr   r   r    rK   r   r   r   r   r5   Q   s   r5   c                   @   s   e Zd Zdd ZdS )
_FifoCachec                    sv   t   | _t   jfdd} fdd} fdd}| _t|| | _t|| | _t|| | _	d S )Nc                    s
    |S r6   r   r7   r:   r   r   r=   l   s    z _FifoCache.__init__.<locals>.getc                    s&   | |< t  kr" jdd qd S NF)last)r-   popitemr>   )r@   rF   r   r   rA   o   s    z!_FifoCache.__init__.<locals>.set_c                    s       d S r6   rB   rD   r?   r   r   rC   t   s    z"_FifoCache.__init__.<locals>.clear)
rE   r<   collectionsOrderedDictr=   rF   rG   rH   rI   rC   )rJ   rF   r=   rA   rC   r   )r@   r;   r<   rF   r   rK   g   s    z_FifoCache.__init__NrL   r   r   r   r   rM   f   s   rM   c                   @   s8   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d ZdS )LRUMemoz
    A memoizing mapping that retains `capacity` deleted items

    The memo tracks retained items by their access order; once `capacity` items
    are retained, the least recently used item is discarded.
    c                 C   s   || _ i | _t | _d S r6   )	_capacity_activerQ   rR   _memory)rJ   capacityr   r   r   rK      s    zLRUMemo.__init__c                 C   s:   z| j | W S  ty4   | j| | j|  Y S 0 d S r6   )rU   KeyErrorrV   move_to_endrJ   r9   r   r   r   __getitem__   s
    zLRUMemo.__getitem__c                 C   s   | j |d  || j|< d S r6   )rV   poprU   rJ   r9   r   r   r   r   __setitem__   s    zLRUMemo.__setitem__c                 C   sR   z| j |}W n ty"   Y n,0 t| j| jkrD| jjdd q$|| j|< d S rN   )rU   r\   rX   r-   rV   rT   rP   r]   r   r   r   __delitem__   s    zLRUMemo.__delitem__c                 C   s   | j   | j  d S r6   )rU   rC   rV   )rJ   r   r   r   rC      s    
zLRUMemo.clearN)	r   r   r    r!   rK   r[   r^   r_   rC   r   r   r   r   rS   }   s   
rS   c                   @   s   e Zd ZdZdd ZdS )UnboundedMemoz<
    A memoizing mapping that retains all deleted items
    c                 C   s   d S r6   r   rZ   r   r   r   r_      s    zUnboundedMemo.__delitem__N)r   r   r    r!   r_   r   r   r   r   r`      s   r`   )r/   r*   c                 C   s:   dD ]}|  |t| } q|  dd} |  dd} t| S )Nz\^-[]r,   z\n	z\t)replace_bslashr   )r/   cr   r   r   _escape_regex_range_chars   s
    re   T)r/   	re_escaper*   c           	   	      s  fddd_ t _d_dd  dd }|s:| g }d	tt| } t| d
krtj	| dD ]\}}t
| }}tjtt|g|dd }||kr| | qjt|t|d krd	nd}|d || | qjn fdd| D }d	|S )Nc                    s4   t | }| j  _}|| dkr.t j _ jS )Nr+   )ordprevnextcounterr   )rd   c_intrh   )is_consecutiver   r   rl      s
    z2_collapse_string_to_ranges.<locals>.is_consecutiver   c                 S   s   | dv rd|  S | S )Nz\^-][\r   rd   r   r   r   escape_re_range_char   s    z8_collapse_string_to_ranges.<locals>.escape_re_range_charc                 S   s   | S r6   r   ro   r   r   r   no_escape_re_range_char   s    z;_collapse_string_to_ranges.<locals>.no_escape_re_range_char    )r9   r+   )maxlen-z{}{}{}c                    s   g | ]} |qS r   r   ).0rd   )rp   r   r   
<listcomp>   r   z._collapse_string_to_ranges.<locals>.<listcomp>)rh   	itertoolsr1   rj   r   joinsortedrI   r-   groupbyri   rQ   dequechainiterr\   appendrg   r   )	r/   rf   rq   retr8   charsfirstrO   sepr   )rp   rl   r   _collapse_string_to_ranges   s4    

r   )llr*   c                 C   s6   g }| D ](}t |tr&|t| q|| q|S r6   )
isinstancelistextend_flattenr   )r   r   ir   r   r   r      s    
r   )T)r   rG   rQ   rx   	functoolsr   typingr   r   r   chrrc   r   intr   r0   r2   r4   r5   rM   rS   dictr`   re   boolr   r   r   r   r   r   r   <module>   s0   	'	
 .