summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul McGuire <ptmcg@austin.rr.com>2016-01-23 07:51:12 +0000
committerPaul McGuire <ptmcg@austin.rr.com>2016-01-23 07:51:12 +0000
commitfb611ffab05e3fc1d4d3b7dbe2d4905c0d63fcf4 (patch)
tree36ae196298046f00ebf62993673577a3a49eac2c /src
parent44cb232f9df08aca920bf980d5caba14e85fd76a (diff)
downloadpyparsing-git-fb611ffab05e3fc1d4d3b7dbe2d4905c0d63fcf4.tar.gz
Fixed ParseResults.asDict() to correctly convert nested ParseResults values to dicts.
Fixed ParseResults.__radd__ to return other+self if not adding to 0.
Diffstat (limited to 'src')
-rw-r--r--src/CHANGES3
-rw-r--r--src/pyparsing.py13
2 files changed, 12 insertions, 4 deletions
diff --git a/src/CHANGES b/src/CHANGES
index 1f3624b..bf7af4f 100644
--- a/src/CHANGES
+++ b/src/CHANGES
@@ -19,6 +19,9 @@ Version 2.0.8 -
- Converted helper lambdas to functions to refactor and add docstring
support.
+- Fixed ParseResults.asDict() to correctly convert nested ParseResults
+ values to dicts.
+
Version 2.0.7 -
---------------------------
diff --git a/src/pyparsing.py b/src/pyparsing.py
index 808e640..f1f19c8 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.0.8"
-__versionTime__ = "17 Jan 2016 21:22"
+__versionTime__ = "23 Jan 2016 01:33"
__author__ = "Paul McGuire <ptmcg@users.sourceforge.net>"
import string
@@ -504,7 +504,11 @@ class ParseResults(object):
def __radd__(self, other):
if isinstance(other,int) and other == 0:
+ # useful for merging many ParseResults using sum() builtin
return self.copy()
+ else:
+ # this may raise a TypeError - so be it
+ return other + self
def __repr__( self ):
return "(%s, %s)" % ( repr( self.__toklist ), repr( self.__tokdict ) )
@@ -528,11 +532,12 @@ class ParseResults(object):
return [res.asList() if isinstance(res,ParseResults) else res for res in self.__toklist]
def asDict( self ):
- """Returns the named parse results as dictionary."""
+ """Returns the named parse results as a nested dictionary."""
if PY_3:
- return dict( self.items() )
+ item_fn = self.items
else:
- return dict( self.iteritems() )
+ item_fn = self.iteritems
+ return dict((k,v.asDict()) if isinstance(v, ParseResults) else (k,v) for k,v in item_fn())
def copy( self ):
"""Returns a new copy of a C{ParseResults} object."""