[Python-ideas] Crazy idea: allow keywords as names in certain positions
e+python-ideas at kellett.im
Mon May 14 08:19:24 EDT 2018
On 2018-05-14 12:35, Rhodri James wrote:
> On 13/05/18 19:19, Guido van Rossum wrote:
>> The idea I had (not for the first time:-) is that in many syntactic
>> positions we could just treat keywords as names, and that would free up
>> these keywords.
> I'm not familiar with the innards of the parser and it's waaaay too long
> since I sat through a parsing course, but can you turn that inside out?
> Are there times when the compiler knows it must be looking at a keyword,
> not a name? I suspect not, given that arbitrary expressions can be
> statements, but someone else may have a more knowledgeable opinion.
Sure are. For example, just after `1 `, a name would be an error, while
a keyword would be fine. But, more to the point, there are times when
the parser knows (or could know) it can't be looking at a certain
keyword. Suppose you want to parse at the beginning of an expression
when you see "and". Currently, you're duty-bound to explode, because
"and" cannot begin an expression. You *could* equally well not explode
and, knowing that "and" cannot begin an expression, interpret it
completely unambiguously as a name.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 488 bytes
Desc: OpenPGP digital signature
More information about the Python-ideas