bpo-40939: Add the new grammar to the grammar specification documentation by pablogsal · Pull Request #19969 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Doc/conf.py
18 changes: 15 additions & 3 deletions Doc/reference/grammar.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
Full Grammar specification
==========================

This is the full Python grammar, as it is read by the parser generator and used
to parse Python source files:
This is the full Python grammar, derived directly from the grammar
Comment thread
gvanrossum marked this conversation as resolved.
used to generate the CPython parser (see :source:`Grammar/python.gram`).
The version here omits details related to code generation and
error recovery.

.. literalinclude:: ../../Grammar/Grammar
The notation is a mixture of `EBNF
<https://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_form>`_
and `PEG <https://en.wikipedia.org/wiki/Parsing_expression_grammar>`_.
In particular, ``&`` followed by a symbol, token or parenthesized
group indicates a positive lookahead (i.e., is required to match but
not consumed), while ``!`` indicates a negative lookahead (i.e., is
required _not_ to match). We use the ``|`` separator to mean PEG's
"ordered choice" (written as ``/`` in traditional PEG grammars).

.. literalinclude:: ../../Grammar/python.gram
:language: peg
75 changes: 75 additions & 0 deletions Doc/tools/extensions/peg_highlight.py
206 changes: 0 additions & 206 deletions Grammar/Grammar

This file was deleted.