diff options
author | Raymond Hettinger <python@rcn.com> | 2005-02-28 19:27:52 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2005-02-28 19:27:52 (GMT) |
commit | 049ade2997aee8cd6564e05d29dbe0b390ebf27b (patch) | |
tree | 986f3e9f04a722e98cbd8cfb3f501531834898a1 /Lib/sre_parse.py | |
parent | 9533e3402433245489bcf55adf1e134ca71b4798 (diff) | |
download | cpython-049ade2997aee8cd6564e05d29dbe0b390ebf27b.zip cpython-049ade2997aee8cd6564e05d29dbe0b390ebf27b.tar.gz cpython-049ade2997aee8cd6564e05d29dbe0b390ebf27b.tar.bz2 |
Complete the previous effort to factor out constant expressions
and improve the speed of the if/elif/else blocks.
Diffstat (limited to 'Lib/sre_parse.py')
-rw-r--r-- | Lib/sre_parse.py | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/Lib/sre_parse.py b/Lib/sre_parse.py index 5066615..33b399e 100644 --- a/Lib/sre_parse.py +++ b/Lib/sre_parse.py @@ -16,15 +16,21 @@ import sys from sre_constants import * +def set(seq): + s = {} + for elem in seq: + s[elem] = 1 + return s + SPECIAL_CHARS = ".\\[{()*+?^$|" REPEAT_CHARS = "*+?{" -DIGITS = tuple("0123456789") +DIGITS = set("0123456789") -OCTDIGITS = tuple("01234567") -HEXDIGITS = tuple("0123456789abcdefABCDEF") +OCTDIGITS = set("01234567") +HEXDIGITS = set("0123456789abcdefABCDEF") -WHITESPACE = tuple(" \t\n\r\v\f") +WHITESPACE = set(" \t\n\r\v\f") ESCAPES = { r"\a": (LITERAL, ord("\a")), @@ -371,6 +377,11 @@ def _parse_sub_cond(source, state, condgroup): subpattern.append((GROUPREF_EXISTS, (condgroup, item_yes, item_no))) return subpattern +_PATTERNENDERS = set("|)") +_ASSERTCHARS = set("=!<") +_LOOKBEHINDASSERTCHARS = set("=!") +_REPEATCODES = set([MIN_REPEAT, MAX_REPEAT]) + def _parse(source, state): # parse a simple pattern subpattern = SubPattern(state) @@ -380,10 +391,10 @@ def _parse(source, state): sourceget = source.get sourcematch = source.match _len = len - PATTERNENDERS = ("|", ")") - ASSERTCHARS = ("=", "!", "<") - LOOKBEHINDASSERTCHARS = ("=", "!") - REPEATCODES = (MIN_REPEAT, MAX_REPEAT) + PATTERNENDERS = _PATTERNENDERS + ASSERTCHARS = _ASSERTCHARS + LOOKBEHINDASSERTCHARS = _LOOKBEHINDASSERTCHARS + REPEATCODES = _REPEATCODES while 1: |