#1 CharNotIn exception when min=0

closed
nobody
None
5
2007-10-07
2007-09-06
No

In some cases, it may be desired to match any number of (including None) consecutive characters not in a given set. When I attempt to use CharsNotIn("abc",min=0), I get an exception when I try to parse "abc".

Discussion

  • Joey Tallieu

    Joey Tallieu - 2007-09-06

    Patch file - CharsNotIn parsing with min=0

     
  • Joey Tallieu

    Joey Tallieu - 2007-09-06

    Logged In: YES
    user_id=1748698
    Originator: YES

    The patch:

    1668a1669,1671
    > # return emtpy if allowed
    > if self.mayReturnEmpty:
    > return loc, instring[loc:loc]

     
  • Paul McGuire

    Paul McGuire - 2007-09-24

    Logged In: YES
    user_id=893320
    Originator: NO

    This is not really how pyparsing is supposed to work. For Word and CharsNotIn, the minimum value for min is 1. If you really want to match *no* characters in or not in the set (for Word or CharsNotIn, respectively), you should wrap the expression in an Optional, as in:

    Optional(CharsNotIn("abc")).parseString("abc")

    The mayReturnEmpty attribute is for an entirely different purpose (to tell the base _parse method whether or not an empty string is a possible "match" value).

    If this was unclear, I'll add more detail to the description of the min argument, and emit a warning if a min value < 1 is supplied.

    -- Paul

     
  • Joey Tallieu

    Joey Tallieu - 2007-09-24

    Logged In: YES
    user_id=1748698
    Originator: YES

    Sounds like a good way to do it. Thanks for the help.

     
  • Paul McGuire

    Paul McGuire - 2007-10-07

    Logged In: YES
    user_id=893320
    Originator: NO

    Changes made and released in 1.4.8

     
  • Paul McGuire

    Paul McGuire - 2007-10-07
    • status: open --> closed
     

Log in to post a comment.

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

Sign up for the SourceForge newsletter:





No, thanks