#55 nestedExpr ignores parseAction of content

open-works-for-me
nobody
None
5
2012-08-29
2012-05-15
Anonymous
No

When upgrading from pyparsing-1.5.2 to pyparsing-1.5.6 I noticed that parsing a nestedExpr did not execute the parseAction (in this case: removeQuotes) of its content. Notice the differences between the versions:

In [1]: import pyparsing as pp #pyparsing-1.5.2
In [2]: qs = pp.quotedString.setParseAction(pp.removeQuotes)
In [3]: qslist = pp.nestedExpr(content=qs)
In [4]: qslist.parseString('("1" "2")')
Out[4]: ([(['1', '2'], {})], {})

In [5]: import pyparsing_py2 as pp #pyparsing-1.5.6
In [6]: qs = pp.quotedString.setParseAction(pp.removeQuotes)
In [7]: qslist = pp.nestedExpr(content=qs)
In [8]: qslist.parseString('("1" "2")')
Out[8]: ([(['"1"', '"2"'], {})], {})

NB this is specific to nestedExpr, as qs does the right thing:
In [9]: qs.parseString('"1"')
Out[9]: (['1'], {})

I've tried this with a different parseAction as well, with the same results.

Discussion

  • Paul McGuire
    Paul McGuire
    2012-06-16

    Thanks for submitting this, I've reproduced the bug and hope to get a fix worked out soon.

     
  • Paul McGuire
    Paul McGuire
    2012-06-16

    • status: open --> open-accepted
     
  • Paul McGuire
    Paul McGuire
    2012-08-29

    • status: open-accepted --> open-works-for-me
     
  • Paul McGuire
    Paul McGuire
    2012-08-29

    The problem is that nestedExpr defaults to internally ignoring quoted strings, so that nesting delimiters inside quotes won't be interpreted as doing any actual nesting. If your content had been Word(nums).setParseAction(lambda t:int(t[0])), I think there would have been no problem. To turn off nestedExpr's special treatment of quotedString, you could either define qs as QuotedString('"') or define qslist as nestedExpr(content=qs, ignoreExpr=None).