I'm glad to see so many reponses to my initial post! But to be fair, I can also see that this is a not so important feature and changing the parser for this is probably not worth it. Anyway, I will just keep following this discussion and see what comes out of it :-)
Am 14-Nov-2019 19:13:16 +0100 schrieb email@example.com: On Nov 14, 2019, at 09:53, Andrew Barnert via Python-ideas wrote:
Yeah, it seems like this should be doable in basically the same way bracketed multiline expressions are. I'm not sure how much of a change that would require. But it seems like it's worth fiddling with the CPython parser to see if it can actually be done, rather than guessing.
Actually; as an intermediate proof of concept without getting into hacking the parser, you could hack the pure-Python version of the tokenizer in the tokenize module. IIRC, it has code in a couple places that decides whether to yield a NEWLINE (logical end of line) or an NL (physical end of line that's just whitespace rather than logical end of line), and whether to check indent level and yield INDENT/DEDENT tokens, based on keeping track of the open bracket count and a backslash flag and probably something else for triple-quoted strings. You'd probably just need to add another flag for the head line of a compound statement to those two places, and the code to set and clear that flag in a couple other places, and that's it.
And then you can run it on a whole mess of code and verify that it's only different in the cases where you want it to be different (what used to be an ERRORTOKEN or NEWLINE is now an NL because we're in the middle of a with compound statement header).
_______________________________________________ Python-ideas mailing list -- firstname.lastname@example.org To unsubscribe send an email to email@example.com https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at firstname.lastname@example.org/message/ZXT5VX2GLHYICHXPIG5GUNQD6D6FE33K/" target="_blank">https://email@example.com/message/ZXT5VX... Code of Conduct: http://python.org/psf/codeofconduct/