3
d                 @   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               @   sR   e Zd ZU dZg Zee g Zee 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 flagsZconfigurationc          	   C   sd   || j kr6tjdj| j|| jtt| |j  d S || j	krNt
| || ntdj| j|d S )Nz'{}.{} {} is {} and cannot be overriddenzno such {} {!r})_fixed_nameswarningswarnformat__name__
_type_descstrgetattrupper
_all_namessetattr
ValueError)clsZdnamevalue r   3/tmp/pip-build-7vycvbft/pyparsing/pyparsing/util.py_set   s    

z__config_flags._setc             C   s   | j |dS )NT)r   )r   namer   r   r   <lambda>$   s    z__config_flags.<lambda>c             C   s   | j |dS )NF)r   )r   r   r   r   r   r   %   s    N)r   
__module____qualname____doc__r   r   r   r   r   classmethodr   enabledisabler   r   r   r   r      s   
r      )maxsize)locstrgreturnc             C   sF   |}d|   k ot |k n  r4|| d  dkr4dS | |j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    r+   c             C   s   |j 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    r-   c             C   sB   |j dd| }|j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    r/   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j|| | _ tj|| | _tj|| | _d S )Nc                s
    |S )Nr   )_key)	cache_getnot_in_cacher   r   getW   s    z%_UnboundedCache.__init__.<locals>.getc                s   | |< d S )Nr   )r1   r2   r   )cacher   r   set_Z   s    z&_UnboundedCache.__init__.<locals>.set_c                s    j   d S )N)clear)r1   )r6   r   r   r8   ]   s    z'_UnboundedCache.__init__.<locals>.clear)r5   objectr4   sizetypes
MethodTypesetr8   )selfr5   r7   r8   r   )r6   r3   r4   r   __init__R   s    z_UnboundedCache.__init__N)r   r   r   r?   r   r   r   r   r0   Q   s   r0   c               @   s   e Zd Zdd ZdS )
_FifoCachec                sv   t   | _tj   jfdd} fdd} fdd}| _tj|| | _tj|| | _tj|| | _	d S )Nc                s
    |S )Nr   )r1   r2   )r3   r4   r   r   r5   l   s    z _FifoCache.__init__.<locals>.getc                s*   | |< xt  kr$ jdd q
W d S )NF)last)r(   popitem)r1   r2   r   )r6   r:   r   r   r7   o   s    z!_FifoCache.__init__.<locals>.set_c                s    j   d S )N)r8   )r1   )r6   r   r   r8   t   s    z"_FifoCache.__init__.<locals>.clear)
r9   r4   collectionsOrderedDictr5   r:   r;   r<   r=   r8   )r>   r:   r5   r7   r8   r   )r6   r3   r4   r:   r   r?   g   s    z_FifoCache.__init__N)r   r   r   r?   r   r   r   r   r@   f   s   r@   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j | _d S )N)	_capacity_activerC   rD   _memory)r>   capacityr   r   r   r?      s    zLRUMemo.__init__c             C   s6   y
| j | S  tk
r0   | jj| | j| S X d S )N)rG   KeyErrorrH   move_to_end)r>   r2   r   r   r   __getitem__   s
    
zLRUMemo.__getitem__c             C   s   | j j|d  || j|< d S )N)rH   poprG   )r>   r2   r   r   r   r   __setitem__   s    zLRUMemo.__setitem__c             C   sX   y| j j|}W n tk
r$   Y n0X x"t| j| jkrH| jjdd q(W || j|< d S )NF)rA   )rG   rM   rJ   r(   rH   rF   rB   )r>   r2   r   r   r   r   __delitem__   s    zLRUMemo.__delitem__c             C   s   | j j  | jj  d S )N)rG   r8   rH   )r>   r   r   r   r8      s    
zLRUMemo.clearN)	r   r   r   r   r?   rL   rN   rO   r8   r   r   r   r   rE   }   s   
rE   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 )Nr   )r>   r2   r   r   r   rO      s    zUnboundedMemo.__delitem__N)r   r   r   r   rO   r   r   r   r   rP      s   rP   )r*   r%   c             C   s>   xdD ]}| j |t| } qW | j dd} | j dd} t| S )Nz\^-[]r'   z\n	z\t)replace_bslashr   )r*   cr   r   r   _escape_regex_range_chars   s
    
rU   T)r*   	re_escaper%   c       	         s  fddd_ tj _d_dd  dd }|s:| g }d	jtt| } t| d
krxtj	| dD ]\}}t
| }}tjtjt|g|ddj }||kr|j | qlt|t|d krd	nd}|jdj || | qlW n fdd| D }d	j|S )Nc                s4   t | }| j  _}|| dkr.t j _ jS )Nr&   )ordprevnextcounterr   )rT   c_intrX   )is_consecutiver   r   r\      s
    z2_collapse_string_to_ranges.<locals>.is_consecutiver   r&   c             S   s   | dkrd|  S | S )Nz\^-][\r   )rT   r   r   r   escape_re_range_char   s    z8_collapse_string_to_ranges.<locals>.escape_re_range_charc             S   s   | S )Nr   )rT   r   r   r   no_escape_re_range_char   s    z;_collapse_string_to_ranges.<locals>.no_escape_re_range_char    )r2   )maxlen-z{}{}{}c                s   g | ]} |qS r   r   ).0rT   )r^   r   r   
<listcomp>   s    z._collapse_string_to_ranges.<locals>.<listcomp>)rX   	itertoolsr,   rZ   r   joinsortedr=   r(   groupbyrY   rC   dequechainiterrM   appendrW   r   )	r*   rV   r_   retr1   charsfirstrA   sepr   )r^   r\   r   _collapse_string_to_ranges   s.    
rs   )llr%   c             C   s:   g }x0| D ](}t |tr(|jt| q
|j| q
W |S )N)
isinstancelistextend_flattenrn   )rt   ro   ir   r   r   rx      s    

rx   )T)r	   r;   rC   rg   	functoolsr   typingr   r   r   chrrS   r   intr   r+   r-   r/   r0   r@   rE   dictrP   rU   boolrs   rv   rx   r   r   r   r   <module>   s*   	'	
,