summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b>2016-09-28 00:51:09 +0000
committerptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b>2016-09-28 00:51:09 +0000
commit8a30afc12d6f3b93e56238ea791251bcccc87a82 (patch)
tree6ae1b98022a467a27496279b32a57a1d8cb6e0bd
parent68c2b32b49f0c25d67b5a2e91ef0d1039f287e8b (diff)
downloadpyparsing-8a30afc12d6f3b93e56238ea791251bcccc87a82.tar.gz
Fix bug in ZeroOrMore results name reporting
git-svn-id: svn://svn.code.sf.net/p/pyparsing/code/trunk@444 9bf210a0-9d2d-494c-87cf-cfb32e7dff7b
-rw-r--r--src/CHANGES3
-rw-r--r--src/pyparsing.py9
-rw-r--r--src/unitTests.py15
3 files changed, 21 insertions, 6 deletions
diff --git a/src/CHANGES b/src/CHANGES
index b8530b2..7a9d3f2 100644
--- a/src/CHANGES
+++ b/src/CHANGES
@@ -4,6 +4,9 @@ Change Log
Version 2.1.10 -
-------------------------------
+- Fixed bug in reporting named parse results for ZeroOrMore
+ expressions, thanks Ethan Nash for reporting this!
+
- Added support for multiline test strings in runTests.
- Fixed bug in ParseResults.dump when keys were not strings.
diff --git a/src/pyparsing.py b/src/pyparsing.py
index e3b014e..e1648b5 100644
--- a/src/pyparsing.py
+++ b/src/pyparsing.py
@@ -61,7 +61,7 @@ The pyparsing module handles some of the problems that are typically vexing when
"""
__version__ = "2.1.10"
-__versionTime__ = "17 Sep 2016 16:37 UTC"
+__versionTime__ = "28 Sep 2016 00:47 UTC"
__author__ = "Paul McGuire <ptmcg@users.sourceforge.net>"
import string
@@ -3800,6 +3800,7 @@ class NotAny(ParseElementEnhance):
class _MultipleMatch(ParseElementEnhance):
def __init__( self, expr, stopOn=None):
super(_MultipleMatch, self).__init__(expr)
+ self.saveAsList = True
ender = stopOn
if isinstance(ender, basestring):
ender = ParserElement._literalStringClass(ender)
@@ -3869,11 +3870,6 @@ class OneOrMore(_MultipleMatch):
return self.strRepr
- def setResultsName( self, name, listAllMatches=False ):
- ret = super(OneOrMore,self).setResultsName(name,listAllMatches)
- ret.saveAsList = True
- return ret
-
class ZeroOrMore(_MultipleMatch):
"""
Optional repetition of zero or more of the given expression.
@@ -3950,6 +3946,7 @@ class Optional(ParseElementEnhance):
"""
def __init__( self, expr, default=_optionalNotMatched ):
super(Optional,self).__init__( expr, savelist=False )
+ self.saveAsList = self.expr.saveAsList
self.defaultValue = default
self.mayReturnEmpty = True
diff --git a/src/unitTests.py b/src/unitTests.py
index d9a6471..8eaade5 100644
--- a/src/unitTests.py
+++ b/src/unitTests.py
@@ -3403,6 +3403,7 @@ class MiscellaneousParserTests(ParseTestCase):
# test bugfix with repeated tokens when packrat parsing enabled
if "L" in runtests:
+ print_('verify behavior with repeated tokens when packrat parsing is enabled')
a = pyparsing.Literal("a")
b = pyparsing.Literal("b")
c = pyparsing.Literal("c")
@@ -3413,6 +3414,20 @@ class MiscellaneousParserTests(ParseTestCase):
grammar = abb | abc | aba
assert ''.join(grammar.parseString( "aba" )) == 'aba', "Packrat ABA failure!"
+
+ if "M" in runtests:
+ print_('verify behavior of setResultsName with OneOrMore and ZeroOrMore')
+
+ stmt = pyparsing.Keyword('test')
+ print(pyparsing.ZeroOrMore(stmt)('tests').parseString('test test').tests)
+ print(pyparsing.OneOrMore(stmt)('tests').parseString('test test').tests)
+ print(pyparsing.Optional(pyparsing.OneOrMore(stmt)('tests')).parseString('test test').tests)
+ print(pyparsing.Optional(pyparsing.OneOrMore(stmt))('tests').parseString('test test').tests)
+ assert False, "testing..."
+ assert len(pyparsing.ZeroOrMore(stmt)('tests').parseString('test test').tests) == 2, "ZeroOrMore failure with setResultsName"
+ assert len(pyparsing.OneOrMore(stmt)('tests').parseString('test test').tests) == 2, "OneOrMore failure with setResultsName"
+ assert len(pyparsing.Optional(pyparsing.OneOrMore(stmt)('tests')).parseString('test test').tests) == 2, "OneOrMore failure with setResultsName"
+ assert len(pyparsing.Optional(pyparsing.OneOrMore(stmt))('tests').parseString('test test').tests) == 2, "OneOrMore failure with setResultsName"
def makeTestSuite():
import inspect