Python has allowed syntax like this for a while (since python 2!)
x = (1 + 2
+ 3 +
4 + 5)
How is this implemented? I've looked at tokenize, and it doesn't seem to handle removing newlines there. However, the grammar spec doesn't allow for newline. The python docs of course reference it, but I've been unable to find where or how it's actually implemented.
I can think of some ways to implement it myself:
- Write a flag in the parser that checks if you're in an open parenthesis and discard
- Check the entire lexed token list before parsing and remove all newlines in between parenthesis
- During lexing, assume that all parenthesis will be closed and remove newlines there
I'd love to see the actual implementation though, or hear some insight on which method is the best!