From 27e183a78c8062ed7c2bbb91655a5e56cd697bba Mon Sep 17 00:00:00 2001 From: Cengiz Kaygusuz Date: Mon, 20 Nov 2017 20:46:39 -0500 Subject: Move src to root --- examples/nested.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 examples/nested.py (limited to 'examples/nested.py') 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))") )) + -- cgit v1.2.1