summaryrefslogtreecommitdiff
path: root/src/pyparsing.py
diff options
context:
space:
mode:
authorPaul McGuire <ptmcg@austin.rr.com>2016-03-06 18:14:08 +0000
committerPaul McGuire <ptmcg@austin.rr.com>2016-03-06 18:14:08 +0000
commit7924141daf8fab288b13889a907b1a80c9bca367 (patch)
tree8a8f62bb07a0df5bf795210cba9363708ac8d325 /src/pyparsing.py
parent4761de7d4ea5839b76d1a1e6ea98419915134ae7 (diff)
downloadpyparsing-git-7924141daf8fab288b13889a907b1a80c9bca367.tar.gz
Fixed bug in ParseResults.toDict(), in which dict values were always converted to dicts, even if they were just unkeyed lists of tokens.
Diffstat (limited to 'src/pyparsing.py')
-rw-r--r--src/pyparsing.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/pyparsing.py b/src/pyparsing.py
index 61bfc21..b1d5598 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__ = "23 Feb 2016 16:16"
+__versionTime__ = "5 Mar 2016 23:42"
__author__ = "Paul McGuire <ptmcg@users.sourceforge.net>"
import string
@@ -541,7 +541,17 @@ class ParseResults(object):
item_fn = self.items
else:
item_fn = self.iteritems
- return dict((k,v.asDict()) if isinstance(v, ParseResults) else (k,v) for k,v in item_fn())
+
+ def toItem(obj):
+ if isinstance(obj, ParseResults):
+ if obj.haskeys():
+ return obj.asDict()
+ else:
+ return [toItem(v) for v in obj]
+ else:
+ return obj
+
+ return dict((k,toItem(v)) for k,v in item_fn())
def copy( self ):
"""Returns a new copy of a C{ParseResults} object."""