File: nested.py

package info (click to toggle)
pyparsing 2.1.10%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 5,412 kB
  • ctags: 8,284
  • sloc: python: 11,929; sh: 17; makefile: 7
file content (30 lines) | stat: -rw-r--r-- 609 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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))") ))