Next / Previous / Contents / Shipman's homepage

6.12. nestedExpr(): Parser for nested lists

pp.nestedExpr(opener='(', closer=')', content=None, ignoreExpr=I)

This function returns a parser that matches text that is structured as a nested list, that is, as a sequence LCR where:

>>> text = '{They {mean to {win}} Wimbledon}'
>>> print pp.nestedExpr(opener='{', closer='}').parseString(text)
[['They', ['mean', 'to', ['win']], 'Wimbledon']]
>>> text = '''(define (factorial n)
...   (fact-iter 1 1 n))'''
>>> print pp.nestedExpr().parseString(text)
[['define', ['factorial', 'n'], ['fact-iter', '1', '1', 'n']]]