#30 ignore sometimes keeps ignored string, sometimes omits

closed-fixed
nobody
None
5
2009-01-16
2008-12-09
No

In pyparsing 1.5.1, when I use .ignore() on a SkipTo, the ignored content is usually preserved in the result. (This is the behavior I expect.)

>>> print SkipTo(';').ignore(dblQuotedString).parseString('a "b c;" d e; f').dump()
['a "b c;" d e']

However, if the ignored content comes at the beginning of the string being parsed, then it is not only ignored but also omitted from the result.

>>> print SkipTo(';').ignore(dblQuotedString).parseString('"b c;" d e; f').dump()
['d e']

I've attached a testcase utilizing doctest.

Thanks very much!

Discussion

  • Catherine Devlin

    Test case - doctest should run clean, but doesn't

     
  • Paul McGuire

    Paul McGuire - 2008-12-20

    This is definitely a bug, thanks for posting a simple test case.

    -- Paul

     
  • Paul McGuire

    Paul McGuire - 2008-12-20

    Catherine -

    Thanks for submitting this bug. Part of the problem is that you are using the wrong ignore. To do what you want, you need to change:

    print SkipTo(';').ignore(dblQuotedString).parseString('"b c;" d e; f')

    to:

    print SkipTo(';',ignore=dblQuotedString).parseString('"b c;" d e; f')

    The first form is how you indicate to pyparsing what expressions should be skipped over before trying to parse this expression - it's usually used for defining comment expressions so that you don't have to sprinkle Suppress(commentExpr) all over your grammar - you just add .ignore(commentExpr) to your top-level expression.

    In this case, we are looking for a way to define an expression that SkipTo should ignore or skip over when looking for the terminating matching expression, such as the ';' in this example. This is defined by passing the expression as the ignore argument when constructing the SkipTo expression.

    I had a bug in SkipTo because I was using the expression defined by the ignore() method for two purposes. I've fixed this now, and I'll have it posted to SVN shortly. (I've also added your test to my pyparsing unit tests.)

    Thanks again, Catherine, and welcome to pyparsing!

    -- Paul

     
  • Paul McGuire

    Paul McGuire - 2008-12-20
    • status: open --> pending
     
  • Paul McGuire

    Paul McGuire - 2008-12-20
    • status: pending --> pending-fixed
     
  • SourceForge Robot

    This Tracker item was closed automatically by the system. It was
    previously set to a Pending status, and the original submitter
    did not respond within 14 days (the time period specified by
    the administrator of this Tracker).

     
  • SourceForge Robot

    • status: pending-fixed --> closed-fixed
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks