summaryrefslogtreecommitdiff
path: root/pyparsing.py
diff options
context:
space:
mode:
authorEric Wald <gitter@brainshell.org>2019-03-10 14:53:14 -0600
committerPaul McGuire <ptmcg@users.noreply.github.com>2019-03-10 15:53:14 -0500
commited2f5ec744ddc25242f947be8ba798d9fca6a674 (patch)
tree8d06927cb0810d13c2f0ecb314f8c3faca8785e6 /pyparsing.py
parent64cbc7245410223e33d81666381821526be48650 (diff)
downloadpyparsing-git-ed2f5ec744ddc25242f947be8ba798d9fca6a674.tar.gz
Descriptive names for Forward expressions (#71)
Resolves the infinite recursion potential by setting a temporary name during resolution.
Diffstat (limited to 'pyparsing.py')
-rw-r--r--pyparsing.py14
1 files changed, 5 insertions, 9 deletions
diff --git a/pyparsing.py b/pyparsing.py
index 3befc7c..4a79904 100644
--- a/pyparsing.py
+++ b/pyparsing.py
@@ -4636,18 +4636,18 @@ class Forward(ParseElementEnhance):
def __str__( self ):
if hasattr(self,"name"):
return self.name
- return self.__class__.__name__ + ": ..."
- # stubbed out for now - creates awful memory and perf issues
- self._revertClass = self.__class__
- self.__class__ = _ForwardNoRecurse
+ # Avoid infinite recursion by setting a temporary name
+ self.name = self.__class__.__name__ + ": ..."
+
+ # Use the string representation of main expression.
try:
if self.expr is not None:
retString = _ustr(self.expr)
else:
retString = "None"
finally:
- self.__class__ = self._revertClass
+ del self.name
return self.__class__.__name__ + ": " + retString
def copy(self):
@@ -4658,10 +4658,6 @@ class Forward(ParseElementEnhance):
ret <<= self
return ret
-class _ForwardNoRecurse(Forward):
- def __str__( self ):
- return "..."
-
class TokenConverter(ParseElementEnhance):
"""
Abstract subclass of :class:`ParseExpression`, for converting parsed results.