René's URL Explorer Experiment


Title: Align the grammar documentation with Python's actual grammar · Issue #127833 · python/cpython · GitHub

Open Graph Title: Align the grammar documentation with Python's actual grammar · Issue #127833 · python/cpython

X Title: Align the grammar documentation with Python's actual grammar · Issue #127833 · python/cpython

Description: Documentation The current documentation of Python syntax (the later chapters of the language reference) uses hand-maintained production lists, like this: A) compound_stmt ::= if_stmt | while_stmt | for_stmt | try_stmt | with_stmt | match...

Open Graph Description: Documentation The current documentation of Python syntax (the later chapters of the language reference) uses hand-maintained production lists, like this: A) compound_stmt ::= if_stmt | while_stmt |...

X Description: Documentation The current documentation of Python syntax (the later chapters of the language reference) uses hand-maintained production lists, like this: A) compound_stmt ::= if_stmt | while_stmt |...

Opengraph URL: https://github.com/python/cpython/issues/127833

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Align the grammar documentation with Python's actual grammar","articleBody":"# Documentation\n\nThe current documentation of Python syntax (the later chapters of the [language reference](https://docs.python.org/3/reference/index.html)) uses hand-maintained *production lists*, like this:\n\nA)\n\n```\ncompound_stmt ::=  if_stmt\n                   | while_stmt\n                   | for_stmt\n                   | try_stmt\n                   | with_stmt\n                   | match_stmt\n                   | funcdef\n                   | classdef\n                   | async_with_stmt\n                   | async_for_stmt\n                   | async_funcdef\nsuite         ::=  stmt_list NEWLINE | NEWLINE INDENT statement+ DEDENT\nstatement     ::=  stmt_list NEWLINE | compound_stmt\nstmt_list     ::=  simple_stmt (\";\" simple_stmt)* [\";\"]\n```\n\nThere is no mechanism to ensure that these are in sync with the [actual grammar](https://github.com/python/cpython/blob/main/Grammar/python.gram), and they inevitably do get out of sync.\nSee some of the [“docs” issues mentioning “grammar”](https://github.com/python/cpython/issues?q=is%3Aopen+is%3Aissue+label%3Adocs+grammar).\n\nIt's not easy to write an automatic tool to keep them in sync, because we *do* want to elide some details -- the parser rules, *unnecessary* lookaheads, cuts, etc. But, it's *possible* to write it, and we wrote a [proof of concept](https://github.com/encukou/cpython/blob/grammar-in-docs/Tools/peg_generator/docs_generator.py), which will need to be rewritten, tuned, and reviewed. Before introducing it, I'd like to go through all the docs, correct the existing documentation, bring it closer to what a tool could generate, and discuss what the *ideal* presentation would look like. That needs to be a manual process, and it will also need to touch the *prose* that's next to the grammar snippets.\n\nAs a first step, I propose an update to the tooling, which brings the *presentation* a bit closer to the `python.gram` syntax.\n\nFrom the *existing* ReST source, we can get this:\n\nB)\n\n```\ncompound_stmt: if_stmt\n               | while_stmt\n               | for_stmt\n               | try_stmt\n               | with_stmt\n               | match_stmt\n               | funcdef\n               | classdef\n               | async_with_stmt\n               | async_for_stmt\n               | async_funcdef\nsuite:         stmt_list NEWLINE | NEWLINE INDENT statement+ DEDENT\nstatement:     stmt_list NEWLINE | compound_stmt\nstmt_list:     simple_stmt (\";\" simple_stmt)* [\";\"]\n```\n\nSince Sphinx hard-codes the *productionlist* formatting (the `::=` symbol and the aligning), we'll need to override the `productionlist` directive to achieve this.\n\nThen, by changing the ReST and using a different directive, we can get to something like:\n\nC)\n\n```\ncompound_stmt:\n    | if_stmt\n    | while_stmt\n    | for_stmt\n    | try_stmt\n    | with_stmt\n    | match_stmt\n    | funcdef\n    | classdef\n    | async_with_stmt\n    | async_for_stmt\n    | async_funcdef\nsuite:\n    | stmt_list NEWLINE | NEWLINE INDENT statement+ DEDENT\nstatement:\n    | stmt_list NEWLINE | compound_stmt\nstmt_list:\n    | simple_stmt (\";\" simple_stmt)* [\";\"]\n```\n\nI propose to go from A) to B) at once (by overriding `productionlist`), and from B) to C) gradually, while also updating the content (including changing rule names to match the grammar, and adjusting/reorganizing nearby prose).\nI think that the B) and C) styles are similar enough that mixing them in a single version of the docs should not be jarring.\n\nBy the way, one additional benefit of a custom directive is that we can add syntax highlighting. (Ideally, with support from the theme.) I think that making strings stand out makes the listings more readable:\n\n![image](https://github.com/user-attachments/assets/731cc733-d3d8-4c0b-b4f7-83dcded43157)\n\n---\n\nAs a second step, I'd like to rewrite *token* documentation, and then the *lexical analysis* chapter, on which the grammar chapters build: #135676\n\nThen, continue with the grammar chapters in Language reference:\n\n* #141984\n* Simple statements\n* Compound statements\n* Top-level components\n* Full Grammar specification\n\nAnd after that, use generated grammar snippets wherever possible.\n\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-127835\n* gh-129689\n* gh-129690\n* gh-129692\n* gh-130376\n* gh-131468\n* gh-131474\n* gh-132407\n* gh-133632\n* gh-133633\n* gh-133652\n* gh-134423\n* gh-134443\n* gh-134850\n* gh-135301\n\u003c!-- /gh-linked-prs --\u003e\n\n### Other related PRs\n* gh-130588\n* gh-134034","author":{"url":"https://github.com/encukou","@type":"Person","name":"encukou"},"datePublished":"2024-12-11T16:49:03.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/127833/cpython/issues/127833"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:e7924857-629a-0f46-b41a-b50f54c3ca6e
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idE662:D0F38:127644A:19DF701:696A288D
html-safe-noncec34f56af8dcc87c863a90b6d21cba013fbdc48bc01e6f2ffdebafaf15390d3df
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNjYyOkQwRjM4OjEyNzY0NEE6MTlERjcwMTo2OTZBMjg4RCIsInZpc2l0b3JfaWQiOiIyNTE0MzY5MDgwNTY2ODg0NDkzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac30978a368f5a8b5682f742ed53b8ae0c4805064d6d6e5ddbbf775b5966556ed1
hovercard-subject-tagissue:2733479113
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/127833/issue_layout
twitter:imagehttps://opengraph.githubassets.com/506347b51f7789bc90b4b5f8259a871ed1fc3afc45c006ff148a7bfe7524046b/python/cpython/issues/127833
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/506347b51f7789bc90b4b5f8259a871ed1fc3afc45c006ff148a7bfe7524046b/python/cpython/issues/127833
og:image:altDocumentation The current documentation of Python syntax (the later chapters of the language reference) uses hand-maintained production lists, like this: A) compound_stmt ::= if_stmt | while_stmt |...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameencukou
hostnamegithub.com
expected-hostnamegithub.com
Nonea1022f03e4f0d91ea173e4e5dac892c982e0588c62f1ce56121d755a320a3569
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasef472b8e6c7b3fdd5d0354972a3f4c516289bf0be
ui-targetcanary-1
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/issues/127833#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F127833
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F127833
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/127833
Reloadhttps://github.com/python/cpython/issues/127833
Reloadhttps://github.com/python/cpython/issues/127833
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/issues/127833
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 33.9k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 71.1k https://github.com/login?return_to=%2Fpython%2Fcpython
Code https://github.com/python/cpython
Issues 5k+ https://github.com/python/cpython/issues
Pull requests 2.1k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects 31 https://github.com/python/cpython/projects
Security Uh oh! There was an error while loading. Please reload this page. https://github.com/python/cpython/security
Please reload this pagehttps://github.com/python/cpython/issues/127833
Insights https://github.com/python/cpython/pulse
Code https://github.com/python/cpython
Issues https://github.com/python/cpython/issues
Pull requests https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/127833
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/127833
Align the grammar documentation with Python's actual grammarhttps://github.com/python/cpython/issues/127833#top
docsDocumentation in the Doc dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22docs%22
https://github.com/encukou
https://github.com/encukou
encukouhttps://github.com/encukou
on Dec 11, 2024https://github.com/python/cpython/issues/127833#issue-2733479113
language referencehttps://docs.python.org/3/reference/index.html
actual grammarhttps://github.com/python/cpython/blob/main/Grammar/python.gram
“docs” issues mentioning “grammar”https://github.com/python/cpython/issues?q=is%3Aopen+is%3Aissue+label%3Adocs+grammar
proof of concepthttps://github.com/encukou/cpython/blob/grammar-in-docs/Tools/peg_generator/docs_generator.py
https://private-user-images.githubusercontent.com/302922/394835088-731cc733-d3d8-4c0b-b4f7-83dcded43157.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Njg1NjUxNzgsIm5iZiI6MTc2ODU2NDg3OCwicGF0aCI6Ii8zMDI5MjIvMzk0ODM1MDg4LTczMWNjNzMzLWQzZDgtNGMwYi1iNGY3LTgzZGNkZWQ0MzE1Ny5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjYwMTE2JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI2MDExNlQxMjAxMThaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT05YzMwMGEwMjEwNjg3ZDJkNTViYzk4YjEwZDNmMjc0NTA3N2Q4YjlkN2EzZWU2MWE5MjdhMzBkYzYwMGY0MTljJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.bfRdU-m-d-uP-fbKHITKziZx9uWUshFrNDmQAI-qO0c
#135676https://github.com/python/cpython/issues/135676
Reword the Expressions chapter of the docs #141984https://github.com/python/cpython/issues/141984
gh-127833: Docs: Add a grammar-snippet directive & replace productionlist #127835https://github.com/python/cpython/pull/127835
[3.13] gh-127833: Docs: Add a grammar-snippet directive & replace productionlist (GH-127835) #129689https://github.com/python/cpython/pull/129689
[3.12] gh-127833: Docs: Add a grammar-snippet directive & replace productionlist (GH-127835) #129690https://github.com/python/cpython/pull/129690
gh-127833: Fix grammar snippet formatting for help() output  #129692https://github.com/python/cpython/pull/129692
gh-127833: Use productionlist nodes to implement the grammar-snippet directive #130376https://github.com/python/cpython/pull/130376
gh-127833: Add links to token types to the lexical analysis intro #131468https://github.com/python/cpython/pull/131468
gh-127833: lexical analysis: Improve section on Names #131474https://github.com/python/cpython/pull/131474
gh-127833: lexical analysis: Add backticks to BOM example #132407https://github.com/python/cpython/pull/132407
[3.14] gh-127833: lexical analysis: Add backticks to BOM example (GH-132407) #133632https://github.com/python/cpython/pull/133632
[3.13] gh-127833: lexical analysis: Add backticks to BOM example (GH-132407) #133633https://github.com/python/cpython/pull/133633
[3.14] gh-127833: Add links to token types to the lexical analysis intro (GH-131468) #133652https://github.com/python/cpython/pull/133652
[3.14] gh-127833: lexical analysis: Improve section on Names (GH-131474) #134423https://github.com/python/cpython/pull/134423
gh-127833: Reword and expand the Notation section #134443https://github.com/python/cpython/pull/134443
gh-135676: lexical analysis: Improve section on Numeric literals #134850https://github.com/python/cpython/pull/134850
[3.14] gh-127833: Reword and expand the Notation section (GH-134443) #135301https://github.com/python/cpython/pull/135301
gh-130587: Add hand-written docs for non-OP tokens #130588https://github.com/python/cpython/pull/130588
gh-134026: Fix grammar description of for statement #134034https://github.com/python/cpython/pull/134034
docsDocumentation in the Doc dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22docs%22
docs issueshttps://github.com/orgs/python/projects/52
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.