summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b>2014-08-12 14:28:27 +0000
committerptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b>2014-08-12 14:28:27 +0000
commit73fbfcb5b38a619ab1f98e0b148427a7966172e2 (patch)
treee3f7ee4709e5ef772edb41789972b42ad3422506
parent48ddb33000fd910851e26a7066acb596d8e19e37 (diff)
downloadpyparsing-73fbfcb5b38a619ab1f98e0b148427a7966172e2.tar.gz
Updated ParserElement.dump() to list out numbered array values if no results names are defined for a given level of a nested parse result
git-svn-id: svn://svn.code.sf.net/p/pyparsing/code/trunk@273 9bf210a0-9d2d-494c-87cf-cfb32e7dff7b
-rw-r--r--src/CHANGES3
-rw-r--r--src/pyparsing.py16
2 files changed, 16 insertions, 3 deletions
diff --git a/src/CHANGES b/src/CHANGES
index 07aaa01..687745c 100644
--- a/src/CHANGES
+++ b/src/CHANGES
@@ -15,6 +15,9 @@ Version 2.0.3 -
- Fixed bug in And class when initializing using a generator.
+- Enhanced ParseResults.dump() method to list out nested ParseResults that
+ are unnamed arrays of sub-structures.
+
- Fixed UnboundLocalError under Python 3.4 in oneOf method, reported
on Sourceforge by aldanor, thanks!
diff --git a/src/pyparsing.py b/src/pyparsing.py
index 468fb01..047ed52 100644
--- a/src/pyparsing.py
+++ b/src/pyparsing.py
@@ -641,15 +641,25 @@ class ParseResults(object):
Accepts an optional C{indent} argument so that this string can be embedded
in a nested display of other data."""
out = []
+ NL = '\n'
out.append( indent+_ustr(self.asList()) )
items = sorted(self.items())
for k,v in items:
if out:
- out.append('\n')
+ out.append(NL)
out.append( "%s%s- %s: " % (indent,(' '*depth), k) )
if isinstance(v,ParseResults):
- if v.haskeys():
- out.append( v.dump(indent,depth+1) )
+ if v:
+ if v.haskeys():
+ out.append( v.dump(indent,depth+1) )
+ elif any(isinstance(vv,ParseResults) for vv in v):
+ for i,vv in enumerate(v):
+ if isinstance(vv,ParseResults):
+ out.append("\n%s%s[%d]:\n%s%s%s" % (indent,(' '*(depth+1)),i,indent,(' '*(depth+2)),vv.dump(indent,depth+2) ))
+ else:
+ out.append("\n%s%s[%d]:\n%s%s%s" % (indent,(' '*(depth+1)),i,indent,(' '*(depth+2)),_ustr(vv)))
+ else:
+ out.append(_ustr(v))
else:
out.append(_ustr(v))
else: