summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES3
-rw-r--r--pyparsing.py4
-rw-r--r--unitTests.py19
3 files changed, 24 insertions, 2 deletions
diff --git a/CHANGES b/CHANGES
index 430dd38..c4b95a2 100644
--- a/CHANGES
+++ b/CHANGES
@@ -12,6 +12,9 @@ Version 2.3.1 -
changes in the tokens returned if you have this condition in your pyparsing
scripts.
+- Fix bug in dictOf which could match an empty sequence, making it
+ infinitely loop if wrapped in a OneOrMore.
+
- Added unicode sets to pyparsing_unicode for Latin-A and Latin-B ranges.
- Added ability to define custom unicode sets as combinations of other sets
diff --git a/pyparsing.py b/pyparsing.py
index 48e5e23..975846c 100644
--- a/pyparsing.py
+++ b/pyparsing.py
@@ -94,7 +94,7 @@ classes inherit from. Use the docstrings for examples of how to:
"""
__version__ = "2.3.1"
-__versionTime__ = "28 Dec 2018 20:39 UTC"
+__versionTime__ = "28 Dec 2018 20:52 UTC"
__author__ = "Paul McGuire <ptmcg@users.sourceforge.net>"
import string
@@ -5076,7 +5076,7 @@ def dictOf( key, value ):
SQUARE
{'color': 'light blue', 'shape': 'SQUARE', 'posn': 'upper left', 'texture': 'burlap'}
"""
- return Dict( ZeroOrMore( Group ( key + value ) ) )
+ return Dict(OneOrMore(Group(key + value)))
def originalTextFor(expr, asString=True):
"""Helper to return the original, untokenized text for a given
diff --git a/unitTests.py b/unitTests.py
index cd219bf..9d2731a 100644
--- a/unitTests.py
+++ b/unitTests.py
@@ -3851,6 +3851,25 @@ class ParseResultsWithNameOr(ParseTestCase):
self.assertEqual(list(expr.parseString('not the bird')['rexp']), 'not the bird'.split())
self.assertEqual(list(expr.parseString('the bird')['rexp']), 'the bird'.split())
+class EmptyDictDoesNotRaiseException(ParseTestCase):
+ def runTest(self):
+ import pyparsing as pp
+
+ key = pp.Word(pp.alphas)
+ value = pp.Word(pp.nums)
+ EQ = pp.Suppress('=')
+ key_value_dict = pp.dictOf(key, EQ + value)
+ try:
+ print(key_value_dict.parseString("""\
+ a = 10
+ b = 20
+ """).dump())
+ print(key_value_dict.parseString("").dump())
+ except pp.ParseException:
+ pass
+ else:
+ self.assertTrue(False, "failed to raise exception when matching empty string")
+
class MiscellaneousParserTests(ParseTestCase):
def runTest(self):