This is a followup on my previous question, I am using the 2to3 tool as suggested by Senthil Kumaran
It seems to work well but it doesn’t pick up this part:
raise LexError,("%s:%d: Rule '%s' returned an unknown token type '%s'" % (
func.func_code.co_filename, func.func_code.co_firstlineno,
func.__name__, newtok.type),lexdata[lexpos:])
What should this look like in 3.2 ?
EDIT: the changes from the answer below are good, 2to3 now seems to work ok. Howevery in the setup.py build I now get the error below, see my new question.
Remove the comma after LexError. That works in both Python 2 and Python 3.
In Python 2 there was a rarely used syntax to raise exceptions like this:
This is the one used here, but for some reason, maybe since there is a parenthesis around the message string (according to Senthils tests, it’s the line break in the parenthesis that does it), 2to3 misses the change into the much better:
So it should look like this (in Python 2)
Because formatting that message on the same line as the raise is fugly. 🙂
Then in addition func_code has been renamed, so in Python 3 there are more changes. But with the above change 2to3 should work correctly.