Sourcetrail icon indicating copy to clipboard operation
Sourcetrail copied to clipboard

Unexpected token

Open ukos-git opened this issue 5 years ago • 2 comments

I get a lot of errors like Unexpected token of type "OP" encountered at valid (but uncommonly strange-looking) python code. The code is formatted PEP compliant.

        map(
            lambda (x, y): '{:s} = {:.3f}um'.format(
                x, y * 1e6
            ), dict(
                {axis: position[axis] for axis in axes}
            ).iteritems()
        )

image image

I suspect this is an issue with the tokenizer used by SourceTrail that somehow misses to detect the opening and closing brackets correctly.

I hope the above example suffices as a mwe.

ukos-git avatar Oct 28 '20 12:10 ukos-git

This looks like a parser issue. I'm not an expert, but are you really supposed to use ( and ) after the lambda keyword?

mlangkabel avatar Nov 09 '20 14:11 mlangkabel

I missed to mention that this is python2 code.

I would expect that unparenthesized tuples make it harder for your tokenizer to recognize operator precedence.

I am also not sure if varargslist to lambda would actually conflict with the function parameter argslist of map. So that the function parameters actually have precedence. However, lambdadef also waits for a colon after varargslist, so I guess the brackets in fpdef are always optional.

https://docs.python.org/2/reference/grammar.html parameters: '(' [varargslist] ')' varargslist: ((fpdef ['=' test] ',')* ('' NAME [',' '' NAME] | '' NAME) | fpdef ['=' test] (',' fpdef ['=' test]) [',']) fpdef: NAME | '(' fplist ')' fplist: fpdef (',' fpdef)* [','] ... lambdef: 'lambda' [varargslist] ':' test

Nevertheless, as I mentioned before, the above python code is valid.

ukos-git avatar Nov 10 '20 07:11 ukos-git