summaryrefslogtreecommitdiff
path: root/src/examples/nested.py
diff options
context:
space:
mode:
authorptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b>2012-10-02 04:55:56 +0000
committerptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b>2012-10-02 04:55:56 +0000
commitb8d7d6e994ba837f197f36f23bbad10fe3e24cc8 (patch)
tree57ea8bcf2e66532a36c833a7bc57cff9d5d0e4dd /src/examples/nested.py
parent0edced5724b253771cc9631184096a98f0432f2a (diff)
downloadpyparsing-b8d7d6e994ba837f197f36f23bbad10fe3e24cc8.tar.gz
Add example files to SVN
git-svn-id: svn://svn.code.sf.net/p/pyparsing/code/trunk@238 9bf210a0-9d2d-494c-87cf-cfb32e7dff7b
Diffstat (limited to 'src/examples/nested.py')
-rw-r--r--src/examples/nested.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/examples/nested.py b/src/examples/nested.py
new file mode 100644
index 0000000..bd529f5
--- /dev/null
+++ b/src/examples/nested.py
@@ -0,0 +1,30 @@
+#
+# nested.py
+# Copyright, 2007 - Paul McGuire
+#
+# Simple example of using nestedExpr to define expressions using
+# paired delimiters for grouping lists and sublists
+#
+
+from pyparsing import *
+import pprint
+
+data = """
+{
+ { item1 "item with } in it" }
+ {
+ {item2a item2b }
+ {item3}
+ }
+
+}
+"""
+
+# use {}'s for nested lists
+nestedItems = nestedExpr("{", "}")
+print( (nestedItems+stringEnd).parseString(data).asList() )
+
+# use default delimiters of ()'s
+mathExpr = nestedExpr()
+print( mathExpr.parseString( "((( ax + by)*C) *(Z | (E^F) & D))") )
+