Menu

Proposed API chg - parse actions return type

2004-02-19
2004-02-21
  • Paul McGuire

    Paul McGuire - 2004-02-19

    In working up a documentation example, I realized that, all this time, the location argument to any specified parse actions has always been passed as the *ending* location for parsing.  This is hardly ever of any interest, except for any parse actions that might want to manipulate this location - whatever value is returned is where the parse will get picked up next.

    But, if I change the location value that is passed, this creates instant infinite loops, since this will reset the parse location to the start of the tokens, which will match, which will reset the parse location...

    So I'm proposing changing the return type for parse actions to simply be the list of tokens, instead of the current tuple return type of location and tokens.  I've not yet come up with any good examples where I change the parse location in a parse action, but I've had several cases where I modified the tokens in the parse action (changing case, converting types, etc.).

    Will this be a hardship?   Or other proposals?

    -- Paul

     
    • Paul McGuire

      Paul McGuire - 2004-02-21

      I've found a way to allow current parse actions (which return a (loc,toks) tuple) to continue to run without error, in a deprecated fashion.  I've coded pyparsing to see if the returned value isinstance of tuple, and if so read the tokens out of the [1]'th tuple member, otherwise, assume the returned value *is* the tokens list.  This way, if anyone has defined any parse actions, they will continue to work properly, while they go through converting their code (should I raise one of the 'deprecated' warning messages?).  The next release will be version 1.1, and I'll leave this backward compatibility code in until 1.2.

      -- Paul

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.