diff options
author | ptmcg <ptmcg@austin.rr.com> | 2022-07-04 20:06:13 -0500 |
---|---|---|
committer | ptmcg <ptmcg@austin.rr.com> | 2022-07-04 20:06:13 -0500 |
commit | 05b3aad6bccdb4d82147077c1b530b09455d8ab8 (patch) | |
tree | b9096d9ce04afea8fdae2820b2f5ff40d4fa63fa /pyparsing/core.py | |
parent | d8af08511bbfd9e441ac6910c96afd3a3ebf2a34 (diff) | |
download | pyparsing-git-05b3aad6bccdb4d82147077c1b530b09455d8ab8.tar.gz |
Add return of NotImplemented to other binary operators (similar to PR #425), and add unit tests
Diffstat (limited to 'pyparsing/core.py')
-rw-r--r-- | pyparsing/core.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/pyparsing/core.py b/pyparsing/core.py index fd5889a..54846f5 100644 --- a/pyparsing/core.py +++ b/pyparsing/core.py @@ -3940,6 +3940,8 @@ class And(ParseExpression): def __iadd__(self, other): if isinstance(other, str_type): other = self._literalStringClass(other) + if not isinstance(other, ParserElement): + return NotImplemented return self.append(other) # And([self, other]) def _checkRecursion(self, parseElementList): @@ -4080,6 +4082,8 @@ class Or(ParseExpression): def __ixor__(self, other): if isinstance(other, str_type): other = self._literalStringClass(other) + if not isinstance(other, ParserElement): + return NotImplemented return self.append(other) # Or([self, other]) def _generateDefaultName(self) -> str: @@ -4191,6 +4195,8 @@ class MatchFirst(ParseExpression): def __ior__(self, other): if isinstance(other, str_type): other = self._literalStringClass(other) + if not isinstance(other, ParserElement): + return NotImplemented return self.append(other) # MatchFirst([self, other]) def _generateDefaultName(self) -> str: @@ -4291,6 +4297,13 @@ class Each(ParseExpression): self.initExprGroups = True self.saveAsList = True + def __iand__(self, other): + if isinstance(other, str_type): + other = self._literalStringClass(other) + if not isinstance(other, ParserElement): + return NotImplemented + return self.append(other) # Each([self, other]) + def streamline(self) -> ParserElement: super().streamline() if self.exprs: @@ -5216,6 +5229,10 @@ class Forward(ParseElementEnhance): del self.caller_frame if isinstance(other, str_type): other = self._literalStringClass(other) + + if not isinstance(other, ParserElement): + return NotImplemented + self.expr = other self.mayIndexError = self.expr.mayIndexError self.mayReturnEmpty = self.expr.mayReturnEmpty @@ -5229,6 +5246,9 @@ class Forward(ParseElementEnhance): return self def __ilshift__(self, other) -> "Forward": + if not isinstance(other, ParserElement): + return NotImplemented + return self << other def __or__(self, other) -> "ParserElement": |