[Python-ideas] Does jargon make learning more difficult?

Chris Angelico rosuav at gmail.com
Tue Aug 21 18:51:40 EDT 2018


On Wed, Aug 22, 2018 at 8:45 AM, Abe Dillon <abedillon at gmail.com> wrote:
> [Chris Angelico]
>>
>> Python's parser is *deliberately* incapable of backtracking this far
>> in its definition of syntax.
>
>
> Can you explain how far the parser is capable of backtracking?
> It seems like <expression> with <signature> would require a similar amount
> of backtracking to ternary expressions:
>
> <expression> if <condition> else <expression>
>
> If the preceding expression is the same in both cases, then the parser needs
> to backtrack just as far when it finds an "if" as when it finds a "with".

I have to defer to someone who knows in more detail here, but the
parser will look ahead one "token", whatever a token is. (Technically
it doesn't backtrack, it looks ahead - same difference.) In order for
the ternary-if to work, the expression before the if has to be of a
more restricted type than just "any expression" (for instance, you
can't put a lambda function there, unless you parenthesize it). But
I'm not fluent in all the details, and I definitely am not comfortable
citing exactly what the limits are. The last time I tried editing the
grammar, weird things happened.

ChrisA


More information about the Python-ideas mailing list