On Nov 14, 2019, at 09:53, Andrew Barnert via Python-ideas 
<python-ideas@python.org> 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 -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/ZXT5VX2GLHYICHXPIG5GUNQD6D6FE33K/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to