#57 nestedExpr relies on default whitespace chars, see examples.

open
nobody
None
5
2012-05-23
2012-05-23
Anonymous
No

I'm using pyparsing-1.5.5 and see this surprising behavior:

Python 2.6.6 (r266:84292, Feb 28 2011, 18:54:06)
[GCC 4.4.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from pyparsing import *
>>> ParserElement.setDefaultWhitespaceChars("\r\t ")
>>> test = nestedExpr('a','b')
>>> print str(test.parseString(u'''ab'''))
[[]]
>>> print str(test.parseString(u'''a\nb'''))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.6/site-packages/pyparsing.py", line 1100, in parseString
raise exc
pyparsing.ParseException: Expected "b" (at char 1), (line:1, col:1)
>>> print str(test.parseString(u'''ax\nb'''))
[[u'x']]
>>> print str(test.parseString(u'''a\nxb'''))
[[u'x']]
>>> print str(test.parseString(u'''a""\nb'''))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.6/site-packages/pyparsing.py", line 1100, in parseString
raise exc
pyparsing.ParseException: Expected "b" (at char 3), (line:1, col:1)
>>> print str(test.parseString(u'''a\n""b'''))
[[u'""']]
>>>

I guess nestedExpr relies on the default whitespace chars - if I don't touch those/set them to default, it does work as expected. Setting the whitespace chars for 'test' doesn't work, though:

>>> test=test.setWhitespaceChars('\r\t\n ')
>>> print str(test.parseString(u'''a""\nb'''))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.6/site-packages/pyparsing.py", line 1100, in parseString
raise exc
pyparsing.ParseException: Expected "b" (at char 3), (line:1, col:1)
>>>

Whereas setting the ParserElement default whitespace chars works:
>>> ParserElement.setDefaultWhitespaceChars('\r\t\n ')
>>> test = nestedExpr('a','b')
>>> print str(test.parseString(u'''a""\nb'''))
[[u'""']]
>>>

Discussion