3

Y'íc•ã@s(ddlZddlZddlZddlZddlmZddlmZmZm	Z	e
dƒZGdd„dƒZedde
ee
d	œd
d„ƒZedde
ee
d	œdd
„ƒZedde
eed	œdd„ƒZGdd„dƒZGdd„dƒZGdd„dƒZGdd„deƒZeedœdd„Zd"eee	efeedœdd„Zeedœd d!„ZdS)#éN)Ú	lru_cache)ÚListÚUnionÚIterableé\c@sReZdZUdZgZeegZeedZe	dd„ƒZ
e	dd„ƒZe	dd„ƒZdS)	Ú__config_flagsz=Internal class for defining compatibility and debugging flagsZ
configurationc	Csd||jkr6tjdj|j||jtt||ƒƒjƒƒƒdS||j	krNt
|||ƒntdj|j|ƒƒ‚dS)Nz'{}.{} {} is {} and cannot be overriddenzno such {} {!r})Ú_fixed_namesÚwarningsÚwarnÚformatÚ__name__Ú
_type_descÚstrÚgetattrÚupperÚ
_all_namesÚsetattrÚ
ValueError)ÚclsZdnameÚvalue©rú3/tmp/pip-build-gk9425m9/pyparsing/pyparsing/util.pyÚ_sets

z__config_flags._setcCs|j|dƒS)NT)r)rÚnamerrrÚ<lambda>$sz__config_flags.<lambda>cCs|j|dƒS)NF)r)rrrrrr%sN)
rÚ
__module__Ú__qualname__Ú__doc__rrrrr
ÚclassmethodrÚenableÚdisablerrrrrs
ré€)Úmaxsize)ÚlocÚstrgÚreturncCsF|}d|kot|ƒknr4||ddkr4dS||jdd|ƒ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$ÚsrrrÚcol(s
r+cCs|jdd|ƒdS)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'rr&)Úcount)r#r$rrrÚlineno9sr-cCsB|jdd|ƒ}|jd|ƒ}|dkr2||d|…S||dd…S)zh
    Returns the line of text containing loc within a string, counting newlines as line separators.
    r'rr&N)r)Úfind)r#r$Zlast_crZnext_crrrrÚlineGsr/c@seZdZdd„ZdS)Ú_UnboundedCachecspi‰ˆj‰tƒ|_‰‡‡fdd„}‡fdd„}‡fdd„}d|_tj||ƒ|_tj||ƒ|_tj||ƒ|_dS)Ncs
ˆ|ˆƒS)Nr)Ú_Úkey)Ú	cache_getÚnot_in_cacherrÚgetWsz%_UnboundedCache.__init__.<locals>.getcs|ˆ|<dS)Nr)r1r2r)ÚcacherrÚset_Zsz&_UnboundedCache.__init__.<locals>.set_csˆjƒdS)N)Úclear)r1)r6rrr8]sz'_UnboundedCache.__init__.<locals>.clear)r5Úobjectr4ÚsizeÚtypesÚ
MethodTypeÚsetr8)Úselfr5r7r8r)r6r3r4rÚ__init__Rsz_UnboundedCache.__init__N)rrrr?rrrrr0Qsr0c@seZdZdd„ZdS)Ú
_FifoCachecsvtƒ|_‰tjƒ‰ˆj‰‡‡fdd„}‡‡fdd„}‡fdd„}ˆ|_tj||ƒ|_tj||ƒ|_tj||ƒ|_	dS)Ncs
ˆ|ˆƒS)Nr)r1r2)r3r4rrr5lsz _FifoCache.__init__.<locals>.getcs*|ˆ|<xtˆƒˆkr$ˆjddq
WdS)NF)Úlast)r(Úpopitem)r1r2r)r6r:rrr7osz!_FifoCache.__init__.<locals>.set_csˆjƒdS)N)r8)r1)r6rrr8tsz"_FifoCache.__init__.<locals>.clear)
r9r4ÚcollectionsÚOrderedDictr5r:r;r<r=r8)r>r:r5r7r8r)r6r3r4r:rr?gsz_FifoCache.__init__N)rrrr?rrrrr@fsr@c@s8eZdZdZdd„Zdd„Zdd„Zdd	„Zd
d„Zd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.
    cCs||_i|_tjƒ|_dS)N)Ú	_capacityÚ_activerCrDÚ_memory)r>Úcapacityrrrr?…szLRUMemo.__init__cCs6y
|j|Stk
r0|jj|ƒ|j|SXdS)N)rGÚKeyErrorrHÚmove_to_end)r>r2rrrÚ__getitem__Šs

zLRUMemo.__getitem__cCs|jj|dƒ||j|<dS)N)rHÚpoprG)r>r2rrrrÚ__setitem__‘szLRUMemo.__setitem__cCsXy|jj|ƒ}Wntk
r$Yn0Xx"t|jƒ|jkrH|jjddq(W||j|<dS)NF)rA)rGrMrJr(rHrFrB)r>r2rrrrÚ__delitem__•szLRUMemo.__delitem__cCs|jjƒ|jjƒdS)N)rGr8rH)r>rrrr8Ÿs
z
LRUMemo.clearN)	rrrrr?rLrNrOr8rrrrrE}s
rEc@seZdZdZdd„ZdS)Ú
UnboundedMemoz<
    A memoizing mapping that retains all deleted items
    cCsdS)Nr)r>r2rrrrO©szUnboundedMemo.__delitem__N)rrrrrOrrrrrP¤srP)r*r%cCs>xdD]}|j|t|ƒ}qW|jddƒ}|jddƒ}t|ƒS)Nz\^-[]r'z\nú	z\t)ÚreplaceÚ_bslashr)r*ÚcrrrÚ_escape_regex_range_chars­s

rUT)r*Ú	re_escaper%c	s‡fdd„‰dˆ_tjƒˆ_dˆ_dd„‰dd„}|s:|‰g}d	jtt|ƒƒƒ}t|ƒd
kröxªtj	|ˆdD]„\}}t
|ƒ}}tjtj
t|gƒ|ƒddjƒ}||kr¸|jˆ|ƒƒqlt|ƒt|ƒdkrÐd	nd
}|jdjˆ|ƒ|ˆ|ƒƒƒqlWn‡fdd„|Dƒ}d	j|ƒS)Ncs4t|ƒ}|ˆjˆ_}||dkr.tˆjƒˆ_ˆjS)Nr&)ÚordÚprevÚnextÚcounterr)rTÚc_intrX)Úis_consecutiverrr\¹s
z2_collapse_string_to_ranges.<locals>.is_consecutiverr&cSs|dkrd|S|S)Nz\^-][ú\r)rTrrrÚescape_re_range_charÄsz8_collapse_string_to_ranges.<locals>.escape_re_range_charcSs|S)Nr)rTrrrÚno_escape_re_range_charÇsz;_collapse_string_to_ranges.<locals>.no_escape_re_range_charÚé)r2)Úmaxlenú-z{}{}{}csg|]}ˆ|ƒ‘qSrr)Ú.0rT)r^rrú
<listcomp>ßsz._collapse_string_to_ranges.<locals>.<listcomp>éÿÿÿÿ)rXÚ	itertoolsr,rZrÚjoinÚsortedr=r(ÚgroupbyrYrCÚdequeÚchainÚiterrMÚappendrWr)	r*rVr_Úretr1ÚcharsÚfirstrAÚsepr)r^r\rÚ_collapse_string_to_ranges¶s.
rs)Úllr%cCs:g}x0|D](}t|tƒr(|jt|ƒƒq
|j|ƒq
W|S)N)Ú
isinstanceÚlistÚextendÚ_flattenrn)rtroÚirrrrxäs

rx)T)r	r;rCrgÚ	functoolsrÚtypingrrrÚchrrSrÚintrr+r-r/r0r@rEÚdictrPrUÚboolrsrvrxrrrrÚ<module>s*
	'	
,