diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/CHANGES | 3 | ||||
-rw-r--r-- | src/pyparsing.py | 10 | ||||
-rw-r--r-- | src/unitTests.py | 21 |
3 files changed, 30 insertions, 4 deletions
diff --git a/src/CHANGES b/src/CHANGES index 2072701..580a2fb 100644 --- a/src/CHANGES +++ b/src/CHANGES @@ -8,6 +8,9 @@ Version 2.1.1 - - Fixed bug in SkipTo when using failOn, reported by robyschek, thanks!
+- Fixed bug in Each introduced in 2.1.0, reported by AND patch and
+ unit test submitted by robyschek, well done!
+
- 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 849473f..61bfc21 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__ = "21 Feb 2016 19:41"
+__versionTime__ = "23 Feb 2016 16:16"
__author__ = "Paul McGuire <ptmcg@users.sourceforge.net>"
import string
@@ -2622,14 +2622,16 @@ class Each(ParseExpression): tmpExprs = tmpReqd + tmpOpt + self.multioptionals + self.multirequired
failed = []
for e in tmpExprs:
- if e.canParseNext(instring, tmpLoc):
+ try:
+ tmpLoc = e.tryParse( instring, tmpLoc )
+ except ParseException:
+ failed.append(e)
+ else:
matchOrder.append(self.opt1map.get(id(e),e))
if e in tmpReqd:
tmpReqd.remove(e)
elif e in tmpOpt:
tmpOpt.remove(e)
- else:
- failed.append(e)
if len(failed) == len(tmpExprs):
keepMatching = False
diff --git a/src/unitTests.py b/src/unitTests.py index 044cae9..f31ceb9 100644 --- a/src/unitTests.py +++ b/src/unitTests.py @@ -2198,6 +2198,25 @@ class WordBoundaryExpressionsTest(ParseTestCase): assert results==expected,"Failed WordBoundaryTest, expected %s, got %s" % (expected,results)
print_()
+class RequiredEachTest(ParseTestCase):
+ def runTest(self):
+ from pyparsing import Keyword
+
+ parser = Keyword('bam') & Keyword('boo')
+ try:
+ res1 = parser.parseString('bam boo')
+ print_(res1.asList())
+ res2 = parser.parseString('boo bam')
+ print_(res2.asList())
+ except ParseException:
+ failed = True
+ else:
+ failed = False
+ assert not failed, "invalid logic in Each"
+
+ assert set(res1) == set(res2), "Failed RequiredEachTest, expected " + \
+ str(res1.asList()) + " and " + str(res2.asList()) + "to contain same words in any order"
+
class OptionalEachTest(ParseTestCase):
def runTest1(self):
from pyparsing import Optional, Keyword
@@ -2688,6 +2707,7 @@ def makeTestSuite(): suite.addTest( WordBoundaryExpressionsTest() )
suite.addTest( ParseAllTest() )
suite.addTest( GreedyQuotedStringsTest() )
+ suite.addTest( RequiredEachTest() )
suite.addTest( OptionalEachTest() )
suite.addTest( SumParseResultsTest() )
suite.addTest( WordExcludeTest() )
@@ -2740,6 +2760,7 @@ if console: testclasses = []
#~ testclasses.append(put_test_class_here)
+ #~ testclasses.append(RequiredEachTest)
if not testclasses:
testRunner.run( makeTestSuite() )
else:
|