Is it possible for nestedExpr
to preserve newlines?
Here is a simple example:
import pyparsing as pp
# Parse expressions like: \name{body}
name = pp.Word( pp.alphas )
body = pp.nestedExpr( '{', '}' )
expr = '\\' + name('name') + body('body')
# Example text to parse
txt = '''
This \works{fine}, but \it{
does not
preserve newlines
}
'''
# Show results
for e in expr.searchString(txt):
print 'name: ' + e.name
print 'body: ' + str(e.body) + '\n'
Output:
name: works
body: [['fine']]
name: it
body: [['does', 'not', 'preserve', 'newlines']]
As you can see, the body of the second expression (\it{ ...
) is parsed despite the newlines in the body, but I would have expected the result to store each line in a separate subarray. This result makes it impossible to distinguish body contents with single vs. multiple lines.