Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

error with setParseAction

Anonymous
2012-02-05
2013-05-14

  • Anonymous
    2012-02-05

    hello - i'm getting an error executing parseString when the following seemingly basic ParseAction is added - when there's no ParseAction set it parses without any issue. Any insight? I'm using the latest pyparsing-1.5.6 and Python 3.2

    Series_Code=OneOrMore(Word(alphanums+"-"))("Series_Code")
    Series_Code.setParseAction( lambda tokens : "".join(tokens))
    test = "Series_Code: Series 1-1|"
    topIDs = Suppress("Series_Code:") + Series_Code + Suppress("|")
    parsed = (topIDs).parseString(test)

    File "C:\Python32\lib\site-packages\pyparsing.py", line 689, in wrapper
    return func(*args)
    UnboundLocalError: local variable 'limit' referenced before assignment

    this is the code referenced by the error

    def _trim_arity(func, maxargs=2):
    limit = maxargs
    def wrapper(*args):
    #~ nonlocal limit
    while 1:
    try:
    return func(*args)
    except TypeError:
    if limit:
    limit -= 1
    continue
    raise
    return wrapper

     
  • Paul McGuire
    Paul McGuire
    2012-06-16

    This code is from the version of pyparsing that is compatible with Python 2.x.  Please get one of the Python 3.x compatible installation files, or download the source version and use setup.py - this should install the correct version of pyparsing for you. (You can manually select the pyparsing_py3.py file and just copy it to your site-packages directory also).