sagetex icon indicating copy to clipboard operation
sagetex copied to clipboard

sagetexparse: getTokensEndLoc no more supported by pyparsing

Open jgmbenoit opened this issue 8 years ago • 3 comments

It appears that getTokensEndLoc was (silently ?) discarded from pyparsing, so sagetexparse and its friends are no more functionnal.

jgmbenoit avatar Dec 30 '16 04:12 jgmbenoit

You can copy the old code from getTokensEndLoc, it still works:

def getTokensEndLoc():
    """Method to be called from within a parse action to determine the end
       location of the parsed tokens."""
    import inspect
    fstack = inspect.stack()
    try:
        # search up the stack (through intervening argument normalizers) for correct calling routine
        for f in fstack[2:]:
            if f[3] == "_parseNoCache":
                endloc = f[0].f_locals["loc"]
                return endloc
        else:
            raise ParseFatalException("incorrect usage of getTokensEndLoc - may only be called from within a parse action")
    finally:
        del fstack

pablo-angulo avatar Nov 20 '20 22:11 pablo-angulo

def skipToMatching(opener, closer):
    """

    :param opener: opening token
    :param closer: closing token

    """
    nest = nestedExpr(opener, closer)
    return originalTextFor(nest)

This code works for me.

vincek59 avatar Nov 27 '20 20:11 vincek59

Would be great to get to specifics of this issue. How can one see breakage?

dimpase avatar Apr 05 '21 08:04 dimpase