diff options
author | ptmcg <ptmcg@austin.rr.com> | 2022-06-24 03:22:57 -0500 |
---|---|---|
committer | ptmcg <ptmcg@austin.rr.com> | 2022-06-24 03:22:57 -0500 |
commit | d6a9a77401f8402a6aad790b3b98f12eb2dd0a9d (patch) | |
tree | 7ea7b3a8cf11226ab16cbb5214ea978df51c8cdf /pyparsing | |
parent | 18abf0727deb9b1a4f93f2747345d4e9ea0e8d69 (diff) | |
download | pyparsing-git-d6a9a77401f8402a6aad790b3b98f12eb2dd0a9d.tar.gz |
Remove assignment to __class__ in Word, remove internal _WordRegex class
Diffstat (limited to 'pyparsing')
-rw-r--r-- | pyparsing/core.py | 15 | ||||
-rw-r--r-- | pyparsing/exceptions.py | 2 |
2 files changed, 5 insertions, 12 deletions
diff --git a/pyparsing/core.py b/pyparsing/core.py index e34cfee..11f7368 100644 --- a/pyparsing/core.py +++ b/pyparsing/core.py @@ -2868,7 +2868,7 @@ class Word(Token): self.re = None else: self.re_match = self.re.match - self.__class__ = _WordRegex + self.parseImpl = self.parseImpl_regex def _generateDefaultName(self) -> str: def charsAsStr(s): @@ -2929,9 +2929,7 @@ class Word(Token): return loc, instring[start:loc] - -class _WordRegex(Word): - def parseImpl(self, instring, loc, doActions=True): + def parseImpl_regex(self, instring, loc, doActions=True): result = self.re_match(instring, loc) if not result: raise ParseException(instring, loc, self.errmsg, self) @@ -2940,7 +2938,7 @@ class _WordRegex(Word): return loc, result.group() -class Char(_WordRegex): +class Char(Word): """A short-cut class for defining :class:`Word` ``(characters, exact=1)``, when defining a match of any single character in a string of characters. @@ -2958,13 +2956,8 @@ class Char(_WordRegex): asKeyword = asKeyword or as_keyword excludeChars = excludeChars or exclude_chars super().__init__( - charset, exact=1, asKeyword=asKeyword, excludeChars=excludeChars + charset, exact=1, as_keyword=asKeyword, exclude_chars=excludeChars ) - self.reString = f"[{_collapse_string_to_ranges(self.initChars)}]" - if asKeyword: - self.reString = rf"\b{self.reString}\b" - self.re = re.compile(self.reString) - self.re_match = self.re.match class Regex(Token): diff --git a/pyparsing/exceptions.py b/pyparsing/exceptions.py index ed88ad2..b0694c3 100644 --- a/pyparsing/exceptions.py +++ b/pyparsing/exceptions.py @@ -80,7 +80,7 @@ class ParseBaseException(Exception): f_self = frm.f_locals.get("self", None) if isinstance(f_self, ParserElement): - if frm.f_code.co_name not in ("parseImpl", "_parseNoCache"): + if not frm.f_code.co_name.startswith(("parseImpl", "_parseNoCache")): continue if id(f_self) in seen: continue |