Sophie

Sophie

distrib > Mandriva > 2010.2 > i586 > media > contrib-release > by-pkgid > 6009aaa8e5ab2df861ebfa6faf6af1ce > files > 51

python-parsing-1.5.2-2mdv2010.1.noarch.rpm

#
#  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))") )