diff options
author | ptmcg <ptmcg@austin.rr.com> | 2019-09-25 18:48:56 -0500 |
---|---|---|
committer | ptmcg <ptmcg@austin.rr.com> | 2019-09-25 18:48:56 -0500 |
commit | 3ca6774b07400e7337f34071daa68763247789b0 (patch) | |
tree | ef1d9c828a9b73ac50c7dda4a2df514367267c58 | |
parent | 44a2cbf921d14a78b05a7c7854c9e8e256c6e38d (diff) | |
download | pyparsing-git-3ca6774b07400e7337f34071daa68763247789b0.tar.gz |
Revert Word perf enhancement, not Py2-friendly
-rw-r--r-- | CHANGES | 3 | ||||
-rw-r--r-- | pyparsing.py | 20 |
2 files changed, 11 insertions, 12 deletions
@@ -8,8 +8,7 @@ Version 2.4.3 - September, 2019 create a recursion error at parser definition time. Thanks to Michael Clerx for the assist. (Addresses issue #123) -- Backport from pyparsing 3.0.0 of __diag__.enable_all_warnings() - and performance enhancement to Word. +- Backport from pyparsing 3.0.0 of __diag__.enable_all_warnings(). Version 2.4.2 - July, 2019 diff --git a/pyparsing.py b/pyparsing.py index 111bf3b..6e503cb 100644 --- a/pyparsing.py +++ b/pyparsing.py @@ -3158,13 +3158,13 @@ class Word(Token): if ' ' not in self.initCharsOrig + self.bodyCharsOrig and (min == 1 and max == 0 and exact == 0): if self.bodyCharsOrig == self.initCharsOrig: - self.reString = "[%s]+" % _collapseAndEscapeRegexRangeChars(self.initCharsOrig) + self.reString = "[%s]+" % _escapeRegexRangeChars(self.initCharsOrig) elif len(self.initCharsOrig) == 1: self.reString = "%s[%s]*" % (re.escape(self.initCharsOrig), - _collapseAndEscapeRegexRangeChars(self.bodyCharsOrig),) + _escapeRegexRangeChars(self.bodyCharsOrig),) else: - self.reString = "[%s][%s]*" % (_collapseAndEscapeRegexRangeChars(self.initCharsOrig), - _collapseAndEscapeRegexRangeChars(self.bodyCharsOrig),) + self.reString = "[%s][%s]*" % (_escapeRegexRangeChars(self.initCharsOrig), + _escapeRegexRangeChars(self.bodyCharsOrig),) if self.asKeyword: self.reString = r"\b" + self.reString + r"\b" @@ -3242,7 +3242,7 @@ class Char(_WordRegex): """ def __init__(self, charset, asKeyword=False, excludeChars=None): super(Char, self).__init__(charset, exact=1, asKeyword=asKeyword, excludeChars=excludeChars) - self.reString = "[%s]" % _collapseAndEscapeRegexRangeChars(''.join(self.initChars)) + self.reString = "[%s]" % _escapeRegexRangeChars(''.join(self.initChars)) if asKeyword: self.reString = r"\b%s\b" % self.reString self.re = re.compile(self.reString) @@ -3450,17 +3450,17 @@ class QuotedString(Token): if multiline: self.flags = re.MULTILINE | re.DOTALL self.pattern = r'%s(?:[^%s%s]' % (re.escape(self.quoteChar), - _collapseAndEscapeRegexRangeChars(self.endQuoteChar[0]), - (escChar is not None and _collapseAndEscapeRegexRangeChars(escChar) or '')) + _escapeRegexRangeChars(self.endQuoteChar[0]), + (escChar is not None and _escapeRegexRangeChars(escChar) or '')) else: self.flags = 0 self.pattern = r'%s(?:[^%s\n\r%s]' % (re.escape(self.quoteChar), - _collapseAndEscapeRegexRangeChars(self.endQuoteChar[0]), - (escChar is not None and _collapseAndEscapeRegexRangeChars(escChar) or '')) + _escapeRegexRangeChars(self.endQuoteChar[0]), + (escChar is not None and _escapeRegexRangeChars(escChar) or '')) if len(self.endQuoteChar) > 1: self.pattern += ( '|(?:' + ')|(?:'.join("%s[^%s]" % (re.escape(self.endQuoteChar[:i]), - _collapseAndEscapeRegexRangeChars(self.endQuoteChar[i])) + _escapeRegexRangeChars(self.endQuoteChar[i])) for i in range(len(self.endQuoteChar) - 1, 0, -1)) + ')') if escQuote: |