summaryrefslogtreecommitdiff
path: root/pyparsing.py
diff options
context:
space:
mode:
authorPaul McGuire <ptmcg@austin.rr.com>2019-07-07 21:31:46 -0500
committerPaul McGuire <ptmcg@austin.rr.com>2019-07-07 21:31:46 -0500
commit4ecdf1b69b4316ee7356e1f7b433a0495f7df621 (patch)
treedc01824c8b9d06ebf92911f01384224d7e7a9d92 /pyparsing.py
parent3f94c1245d318e0b18b991d72ab52d14f27cd4cf (diff)
downloadpyparsing-git-4ecdf1b69b4316ee7356e1f7b433a0495f7df621.tar.gz
Augment ParseException str() output to include what character was found at the error location, to help diagnose errors.
Diffstat (limited to 'pyparsing.py')
-rw-r--r--pyparsing.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/pyparsing.py b/pyparsing.py
index 27df353..eabfead 100644
--- a/pyparsing.py
+++ b/pyparsing.py
@@ -96,7 +96,7 @@ classes inherit from. Use the docstrings for examples of how to:
"""
__version__ = "2.4.1"
-__versionTime__ = "07 Jul 2019 06:35 UTC"
+__versionTime__ = "08 Jul 2019 02:00 UTC"
__author__ = "Paul McGuire <ptmcg@users.sourceforge.net>"
import string
@@ -290,8 +290,15 @@ class ParseBaseException(Exception):
raise AttributeError(aname)
def __str__( self ):
- return "%s (at char %d), (line:%d, col:%d)" % \
- ( self.msg, self.loc, self.lineno, self.column )
+ if self.pstr:
+ if self.loc >= len(self.pstr):
+ foundstr = ', found end of text'
+ else:
+ foundstr = ', found %r' % self.pstr[self.loc:self.loc+1]
+ else:
+ foundstr = ''
+ return "%s%s (at char %d), (line:%d, col:%d)" % \
+ ( self.msg, foundstr, self.loc, self.lineno, self.column )
def __repr__( self ):
return _ustr(self)
def markInputline( self, markerString = ">!<" ):