summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b>2016-02-22 01:51:33 +0000
committerptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b>2016-02-22 01:51:33 +0000
commit158315294d41ec0f833969f5781aa6f3fa61aafc (patch)
treef44185ee5333edeb20b5e034b2a78915cc1962fa
parent2c5a9633e9f44d7594170d279de4476b287820f1 (diff)
downloadpyparsing-158315294d41ec0f833969f5781aa6f3fa61aafc.tar.gz
Fixed bug in SkipTo when using failOn; replaced explicit references to obj.__dict__ with vars(obj) (several places); tightened up unit tests for SkipTo
git-svn-id: svn://svn.code.sf.net/p/pyparsing/code/trunk@327 9bf210a0-9d2d-494c-87cf-cfb32e7dff7b
-rw-r--r--src/CHANGES2
-rw-r--r--src/pyparsing.py8
-rw-r--r--src/unitTests.py16
3 files changed, 16 insertions, 10 deletions
diff --git a/src/CHANGES b/src/CHANGES
index 2aea473..2072701 100644
--- a/src/CHANGES
+++ b/src/CHANGES
@@ -6,6 +6,8 @@ Version 2.1.1 -
------------------------------
- Added support for assigning to ParseResults using slices.
+- Fixed bug in SkipTo when using failOn, reported by robyschek, thanks!
+
- Removed use of functools.partial in replaceWith, as this creates
an ambiguous signature for the generated parse action, which fails in
PyPy. Reported by Evan Hubinger, thanks Evan!
diff --git a/src/pyparsing.py b/src/pyparsing.py
index 9e086bc..849473f 100644
--- a/src/pyparsing.py
+++ b/src/pyparsing.py
@@ -58,7 +58,7 @@ The pyparsing module handles some of the problems that are typically vexing when
"""
__version__ = "2.1.1"
-__versionTime__ = "15 Feb 2016 23:22"
+__versionTime__ = "21 Feb 2016 19:41"
__author__ = "Paul McGuire <ptmcg@users.sourceforge.net>"
import string
@@ -1552,7 +1552,7 @@ class ParserElement(object):
def __eq__(self,other):
if isinstance(other, ParserElement):
- return self is other or self.__dict__ == other.__dict__
+ return self is other or vars(self) == vars(other)
elif isinstance(other, basestring):
try:
self.parseString(_ustr(other), parseAll=True)
@@ -2938,7 +2938,7 @@ class SkipTo(ParseElementEnhance):
self.mayIndexError = False
self.includeMatch = include
self.asList = False
- if failOn is not None and isinstance(failOn, basestring):
+ if isinstance(failOn, basestring):
self.failOn = Literal(failOn)
else:
self.failOn = failOn
@@ -2956,7 +2956,7 @@ class SkipTo(ParseElementEnhance):
while tmploc <= instrlen:
if self_failOn_canParseNext is not None:
# break if failOn expression matches
- if self_failOn.canParseNext(instring, tmploc):
+ if self_failOn_canParseNext(instring, tmploc):
break
if self_ignoreExpr_tryParse is not None:
diff --git a/src/unitTests.py b/src/unitTests.py
index 96a43d0..044cae9 100644
--- a/src/unitTests.py
+++ b/src/unitTests.py
@@ -893,23 +893,28 @@ class ReStringRangeTest(ParseTestCase):
class SkipToParserTests(ParseTestCase):
def runTest(self):
- from pyparsing import Literal, SkipTo, NotAny, cStyleComment
+ from pyparsing import Literal, SkipTo, NotAny, cStyleComment, ParseBaseException
thingToFind = Literal('working')
- testExpr = SkipTo(Literal(';'), True, cStyleComment) + thingToFind
+ testExpr = SkipTo(Literal(';'), include=True, ignore=cStyleComment) + thingToFind
- def tryToParse (someText):
+ def tryToParse (someText, fail_expected=False):
try:
print_(testExpr.parseString(someText))
+ assert not fail_expected, "expected failure but no exception raised"
except Exception as e:
print_("Exception %s while parsing string %s" % (e,repr(someText)))
- assert False, "Exception %s while parsing string %s" % (e,repr(someText))
+ assert fail_expected and isinstance(e,ParseBaseException), "Exception %s while parsing string %s" % (e,repr(someText))
# This first test works, as the SkipTo expression is immediately following the ignore expression (cStyleComment)
tryToParse('some text /* comment with ; in */; working')
- # This second test fails, as there is text following the ignore expression, and before the SkipTo expression.
+ # This second test previously failed, as there is text following the ignore expression, and before the SkipTo expression.
tryToParse('some text /* comment with ; in */some other stuff; working')
+ # tests for optional failOn argument
+ testExpr = SkipTo(Literal(';'), include=True, ignore=cStyleComment, failOn='other') + thingToFind
+ tryToParse('some text /* comment with ; in */; working')
+ tryToParse('some text /* comment with ; in */some other stuff; working', fail_expected=True)
class CustomQuotesTest(ParseTestCase):
def runTest(self):
@@ -2735,7 +2740,6 @@ if console:
testclasses = []
#~ testclasses.append(put_test_class_here)
- testclasses.append(OriginalTextForTest)
if not testclasses:
testRunner.run( makeTestSuite() )
else: