summaryrefslogtreecommitdiff
path: root/examples/nested.py
diff options
context:
space:
mode:
authorCengiz Kaygusuz <cngkaygusuz@gmail.com>2017-11-20 20:46:39 -0500
committerCengiz Kaygusuz <cngkaygusuz@gmail.com>2017-11-20 20:46:39 -0500
commit27e183a78c8062ed7c2bbb91655a5e56cd697bba (patch)
tree88fd355a0cc6da4c130582e092d702836596cbb2 /examples/nested.py
parent4ba589cf13588e90992e23deb5a9784340efd2cc (diff)
downloadpyparsing-git-27e183a78c8062ed7c2bbb91655a5e56cd697bba.tar.gz
Move src to root
Diffstat (limited to 'examples/nested.py')
-rw-r--r--examples/nested.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/examples/nested.py b/examples/nested.py
new file mode 100644
index 0000000..24cf2f4
--- /dev/null
+++ b/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))") ))
+