-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
bpo-40939: Add the new grammar to the grammar specification documentation #19969
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I worry about some of the rather verbose comments in the grammar file, and the various error rules. Also there are some cases where lookaheads are essential (notably the way formal parameters are now parsed). And maybe the ordering and formatting of some of the rules could be better.
PS. Your initial comments still shows variables (a=...
) but the script correctly erases those.
I can try to eliminate alternatives if they start with "invalid_" but I think it will not be super resilient :(
Would you like to bring lookaheads back?
Not much we can do here with a custom lexer unless we touch the original file.
Yeah, I removed the variables in the last amend after I realized that we wanted to get rid of them. |
Plus, you'd have to eliminate both the alternatives and the rules. But these really do not deserve to be listed in the reference manual.
Only the ones that are significant -- and those in formal parameters are significant (without them,
Yeah, we can do that later. |
Hmmm.... is there any obvious automatic way (using regular expressions) to detect the ones we want from the ones we don't want? Otherwise, we may need to maintain a copy of the grammar for displaying here and manually trim what we need. |
I dunno. Let's think about this some more before rushing into it. (We'd
have to explain a big about PEG's ordering of alternatives too, to guide
people using this as a basis for anything.)
|
A heuristic that is currently 100% correct is that a lookahead is only used for optimisation and can be skipped if and only if it is a positive lookahead and it appears first in its alternative. Although this is currently correct, it seems like something that could very easily be invalidated in the future, so I don't know if it can be used in the script. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, I like the approach. There are a few places where color makes a line choppy and hard to follow and may make it more difficult to read than just black text.
Co-authored-by: Guido van Rossum <gvanrossum@gmail.com>
I think I'm going to do something with this after all. Let's see if we can't make the highlighter also remove |
Okay, @lysnikolaou we may need your review because now it's both Pablo's and my code. |
I think it makes sense to do the backport. What do you think @lysnikolaou ? |
Okay then @pablogsal what do you think of my version? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks @pablogsal and @gvanrossum.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay then @pablogsal what do you think of my version?
I think is great :) I left a minor question, but feel free to ignore
Note: I cannot approve my own PR, so go ahead and merge!
I also think that backporting this to 3.9 makes sense. |
The new version I pushed has a longer intro in grammar.rst, both to explain (some of) what's omitted and to clarify the notation. It also restores most lookaheads, except for the positive ones that are purely optimizations (as a heuristic I use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks!!
Thanks @pablogsal for the PR, and @gvanrossum for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9. |
Sorry, @pablogsal and @gvanrossum, I could not cleanly backport this to |
GH-21641 is a backport of this pull request to the 3.9 branch. |
…ation (pythonGH-19969) (We censor the heck out of actions and some other stuff using a custom "highlighter".) Co-authored-by: Guido van Rossum <guido@python.org>
…ation (pythonGH-19969) (We censor the heck out of actions and some other stuff using a custom "highlighter".) Co-authored-by: Guido van Rossum <guido@python.org>
…ation (pythonGH-19969) (We censor the heck out of actions and some other stuff using a custom "highlighter".) Co-authored-by: Guido van Rossum <guido@python.org>
Example of how it looks like when using the new lexer:
https://bugs.python.org/issue40939