-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
Simplify the grammar of the assignment
rule
#122951
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Excuse me.
What's the meaning of these patterns, for example, What is |
See https://docs.python.org/3/reference/grammar.html#full-grammar-specification to understand the grammar. The As for the issue, I think you can replace it. On the other hand, I wonder whether this could cause a slight performance change where the parser needs to make another pass to subsitute the rule or not. EDIT: nvm the performance shouldn't really be the bottleneck here (in the relevant PR, the occurrences were just outright replaced) |
I reviewed several functions in Is it really nessesary to be designed like this? |
If you want a more in-depth rationale, read PEP 617. If you can find a way to make an equivalent parser but simpler, we'll gladly accept it. Long story short, we moved from an LL(1) parser to a PEG one because left recursion is not supported by LL(k) parsers (actually, it can cause an infinite recursion on PEG parsers but LL(k) parsers do not allow them in their grammar). Another reason why we use a PEG parser is that a CFG parser would have ambiguous cases which a PEG does not by essence. |
Thx for your explanation. I will take a deeper look at the parser. I used to assume the parser works when executing python program. But when I checked CPython source codes, I recognized parsing Python codes only occurs before generating |
Depends on the use I'd say but here it's probably negligible, though I'm not very familiar with how the pieces are generated. Nonetheless, simplfying how the grammar looks for the user is a good thing IMO. |
This issue seems suitable for a new contributor so I'm adding the easy label :)
|
Opened #124998 |
Uh oh!
There was an error while loading. Please reload this page.
Feature or enhancement
Proposal:
I don't know all the nuances of the new grammar but I think that the
assignment
rule can be simplified in the following way:That is, just reusing
annotated_rhs
instead of writing out(yield_expr | star_expressions)
.There was a similar issue before that fixed some cases, but this one remained. I can submit a PR if this is considered worthwhile but anyone feel free to pick this up :)
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
#116988
Linked PRs
The text was updated successfully, but these errors were encountered: