"""
pygments.regexopt
~~~~~~~~~~~~~~~~~
An algorithm that generates optimized regexes for matching long lists of
literal strings.
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
=
=
return + +
"""Return a regex that matches any string in the sorted list of strings."""
= and or
# print strings, repr(open_paren)
# print '-> nothing left'
return
=
# print '-> only 1 string'
return + +
# print '-> first string empty'
return + \
+ +
# multiple one-char strings? make a charset
=
=
# do we have more than one oneletter string?
# print '-> 1-character + rest'
return + + \
+ +
# print '-> only 1-character'
return + +
=
=
# we have a prefix for all strings
# print '-> prefix:', prefix
return + \
+ \
+
# is there a suffix?
=
=
=
# print '-> suffix:', suffix[::-1]
return \
+ \
+ +
# recurse on common 1-string prefixes
# print '-> last resort'
return + \
\
+
"""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.
"""
=
return + +