-
-
Notifications
You must be signed in to change notification settings - Fork 31k
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
gh-127833: Docs: Add a grammar-snippet
directive & replace productionlist
#127835
Conversation
Co-authored-by: Blaise Pabon <[email protected]> Co-authored-by: William Ferreira <[email protected]>
to conserve the productionlist usage in the docs.
Co-Authored-By: bswck <[email protected]>
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.
A few initial notes. The targets problem is annoying, Sphinx doesn't make it easy...
- Add a module docstring - Use the snake_case convention for node classes - Make :group: a required option - declare parallel_write_safe = True
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'm happy with this as it stands, thank you @encukou for the discussion. As discussed, I've pushed a commit to add type annotations. I've included some other minor changes and left a self-review for a brief explanation -- feel free to revert any you disagree with.
A
Thanks @encukou for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13. |
…roductionlist` (pythonGH-127835) As a first step toward aligning the grammar documentation with Python's actual grammar, this overrides the ReST `productionlist` directive to: - use `:` instead of the `::=` symbol - add syntax highlighting for strings (using a Pygments highlighting class) All links and link targets should be preserved. (Unfortunately, this reaches into some Sphinx internals; I don't see a better way to do exactly what Sphinx does.) This also adds a new directive, `grammar-snippet`, which formats the snippet almost exactly like what's in the source, modulo syntax highlighting and keeping the backtick character to mark links to other rules. This will allow formatting the snippets as in the grammar file (file:///home/encukou/dev/cpython/Doc/build/html/reference/grammar.html). The new directive is applied to two simple rules in toplevel_components.rst --------- (cherry picked from commit 58a4357e29a15135e6fd99f320c60f8ea0472d27) Co-authored-by: Petr Viktorin <[email protected]> Co-authored-by: Blaise Pabon <[email protected]> Co-authored-by: William Ferreira <[email protected]> Co-authored-by: bswck <[email protected]> Co-authored-by: Adam Turner <[email protected]>
GH-129689 is a backport of this pull request to the 3.13 branch. |
…roductionlist` (pythonGH-127835) As a first step toward aligning the grammar documentation with Python's actual grammar, this overrides the ReST `productionlist` directive to: - use `:` instead of the `::=` symbol - add syntax highlighting for strings (using a Pygments highlighting class) All links and link targets should be preserved. (Unfortunately, this reaches into some Sphinx internals; I don't see a better way to do exactly what Sphinx does.) This also adds a new directive, `grammar-snippet`, which formats the snippet almost exactly like what's in the source, modulo syntax highlighting and keeping the backtick character to mark links to other rules. This will allow formatting the snippets as in the grammar file (file:///home/encukou/dev/cpython/Doc/build/html/reference/grammar.html). The new directive is applied to two simple rules in toplevel_components.rst --------- (cherry picked from commit 58a4357e29a15135e6fd99f320c60f8ea0472d27) Co-authored-by: Petr Viktorin <[email protected]> Co-authored-by: Blaise Pabon <[email protected]> Co-authored-by: William Ferreira <[email protected]> Co-authored-by: bswck <[email protected]> Co-authored-by: Adam Turner <[email protected]>
GH-129690 is a backport of this pull request to the 3.12 branch. |
As a first step to what's proposed in the issue, this overrides the ReST
productionlist
directive to::
instead of the::=
symbolAll links and link targets should be preserved. (Unfortunately, this reaches into some Sphinx internals; I don't see a better way to do exactly what Sphinx does.)
This also adds a new directive,
grammar-snippet
, which formats the snippet almost exactly like what's in the source, modulo syntax highlighting and keeping the backtick character to mark links to other rules.This will allow formatting the snippets as in the grammar file (most importantly: to remove the the indentation that Sphinx adds to align the text).
I'd appreciate if a Sphinx expert could take a look to see if there's a better way to do something :) cc @AA-Turner
📚 Documentation preview 📚: https://cpython-previews--127835.org.readthedocs.build/