[Python-ideas] Syntax: 'return: ...' expressions

Andrew Barnert abarnert at yahoo.com
Mon Jan 5 11:37:22 CET 2015


On Jan 5, 2015, at 10:55, Chris Angelico <rosuav at gmail.com> wrote:

> On Mon, Jan 5, 2015 at 8:49 PM, Andrew Barnert
> <abarnert at yahoo.com.dmarc.invalid> wrote:
>> Finally, are you sure your new return: isn't ambiguous without look ahead or context? When the parser reads "if spam: return", is it starting a return simple statement, or an expression statement that starts with a return expression? Have you tried actually writing out the grammar?
> 
> The way I see it, the return-expression is "return:", whereas the
> simple return statement would have no colon.

Are you suggesting that "return:" would be a single token (as opposed to all the other colons in the tokenizer), or that you'd use look ahead to disambiguate?

I suspect it probably _is_ possible to make something work that fits into Python's parser, but it isn't immediately obvious (at least to me) what that would be, which is why I wanted to see a grammar. (And also to know which "level" this comes at, to automatically answer questions like how it fits into things like conditional expressions and comprehension clauses and so forth.)


More information about the Python-ideas mailing list