summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b>2008-11-07 17:16:59 +0000
committerptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b>2008-11-07 17:16:59 +0000
commit7fc2ddaff5b07b5c677d0f933ae002dc1d1d0291 (patch)
tree9d239ad4d6aeacfc3c9e4c1a62862507d10d6d12
parent84c458be8666d4b2c8ea54b3dd704d8f5eee811b (diff)
downloadpyparsing-7fc2ddaff5b07b5c677d0f933ae002dc1d1d0291.tar.gz
Clean up exception stack traces returned to caller
git-svn-id: svn://svn.code.sf.net/p/pyparsing/code/src@169 9bf210a0-9d2d-494c-87cf-cfb32e7dff7b
-rw-r--r--pyparsing.py25
1 files changed, 17 insertions, 8 deletions
diff --git a/pyparsing.py b/pyparsing.py
index 1d67533..baa432a 100644
--- a/pyparsing.py
+++ b/pyparsing.py
@@ -59,7 +59,7 @@ The pyparsing module handles some of the problems that are typically vexing when
"""
__version__ = "1.5.2"
-__versionTime__ = "6 November 2008 12:30"
+__versionTime__ = "7 November 2008 11:15"
__author__ = "Paul McGuire <ptmcg@users.sourceforge.net>"
import string
@@ -1062,11 +1062,16 @@ class ParserElement(object):
e.streamline()
if not self.keepTabs:
instring = instring.expandtabs()
- loc, tokens = self._parse( instring, 0 )
- if parseAll:
- loc = self.preParse( instring, loc )
- StringEnd()._parse( instring, loc )
- return tokens
+ try:
+ loc, tokens = self._parse( instring, 0 )
+ if parseAll:
+ loc = self.preParse( instring, loc )
+ StringEnd()._parse( instring, loc )
+ except ParseBaseException, exc:
+ # catch and re-raise exception from here, clears out pyparsing internal stack trace
+ raise exc
+ else:
+ return tokens
def scanString( self, instring, maxMatches=_MAX_INT ):
"""Scan the input string for expression matches. Each match will return the
@@ -1383,7 +1388,11 @@ class ParserElement(object):
f = open(file_or_filename, "rb")
file_contents = f.read()
f.close()
- return self.parseString(file_contents, parseAll)
+ try:
+ return self.parseString(file_contents, parseAll)
+ except ParseBaseException, exc:
+ # catch and re-raise exception from here, clears out pyparsing internal stack trace
+ raise exc
def getException(self):
return ParseException("",0,self.errmsg,self)
@@ -2828,7 +2837,7 @@ class SkipTo(ParseElementEnhance):
except ParseBaseException:
pass
else:
- failParse = True
+ failParse = True
raise ParseException(instring, loc, "Found expression " + str(self.failOn))
failParse = False
loc = expr._skipIgnorables( instring, loc )