3

V'ícã@sldZddlZddlmZddlmZddlmZddlmZej	dƒZ
edƒZdd	„Zd
d„Z
dd
d„ZdS)a
    pygments.regexopt
    ~~~~~~~~~~~~~~~~~

    An algorithm that generates optimized regexes for matching long lists of
    literal strings.

    :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
    :license: BSD, see LICENSE for details.
éN)Úescape)Úcommonprefix)Úgroupby)Ú
itemgetterz[\[\^\\\-\]]cCsdtjdd„dj|ƒƒdS)Nú[cSsd|jƒS)Nú\)Úgroup)Úm©r
ú5/tmp/pip-build-gk9425m9/Pygments/pygments/regexopt.pyÚ<lambda>szmake_charset.<locals>.<lambda>Úú])Ú	CS_ESCAPEÚsubÚjoin)Úlettersr
r
rÚmake_charsetsrc	sž|rdp
d}|sdS|d‰t|ƒdkr8|tˆƒ|SˆsZ|t|dd…dƒd|StˆƒdkrÜg}g}x.|D]&}t|ƒdkr|j|ƒqt|j|ƒqtWt|ƒdkrÜ|rÌ|t|dƒdt|ƒ|S|t|ƒ|St|ƒ}|rt|ƒ‰|t|ƒt‡fd	d
„|Dƒdƒ|Sdd
„|Dƒ}t|ƒ}|rtt|ƒ‰|tt‡fdd
„|Dƒƒdƒt|ddd…ƒ|S|djdd
„t|‡fdd„ƒDƒƒ|S)zEReturn a regex that matches any string in the sorted list of strings.ú)r
réNz(?:ú?ú|csg|]}|ˆd…‘qS)Nr
)Ú.0Ús)Úplenr
rú
<listcomp>?sz#regex_opt_inner.<locals>.<listcomp>cSsg|]}|ddd…‘qS)Nréÿÿÿÿr
)rrr
r
rrBsc3s|]}|dˆ…VqdS)Nr
)rr)Úslenr
rú	<genexpr>Hsz"regex_opt_inner.<locals>.<genexpr>css |]}tt|dƒdƒVqdS)rr
N)Úregex_opt_innerÚlist)rrr
r
rrMscs|dˆdkS)Nrr
)r)Úfirstr
rrNsz!regex_opt_inner.<locals>.<lambda>r)	ÚlenrrÚappendrrÚsortedrr)	ÚstringsZ
open_parenZclose_parenZ	oneletterÚrestrÚprefixZstrings_revÚsuffixr
)r!rrrrs:
(6rr
cCst|ƒ}|t|dƒ|S)zíReturn a compiled regex that matches any string in the given list.

    The strings to match must be literal strings, not regexes.  They will be
    regex-escaped.

    *prefix* and *suffix* are pre- and appended to the final regex.
    ú()r$r)r%r'r(r
r
rÚ	regex_optRsr*)r
r
)Ú__doc__ÚrerÚos.pathrÚ	itertoolsrÚoperatorrÚcompilerZ
FIRST_ELEMENTrrr*r
r
r
rÚ<module>
s
8