| 1 |
.. _full-grammar-specification: |
| 2 |
|
| 3 |
Full Grammar specification |
| 4 |
========================== |
| 5 |
|
| 6 |
This is the full Python grammar, derived directly from the grammar |
| 7 |
used to generate the CPython parser (see :source:`Grammar/python.gram`). |
| 8 |
The version here omits details related to code generation and |
| 9 |
error recovery. |
| 10 |
|
| 11 |
The notation used here is the same as in the preceding docs, |
| 12 |
and is described in the :ref:`notation <notation>` section, |
| 13 |
except for an extra complication: |
| 14 |
|
| 15 |
* ``~`` ("cut"): commit to the current alternative; fail the rule |
| 16 |
if the alternative fails to parse |
| 17 |
|
| 18 |
Python mainly uses cuts for optimizations or improved error |
| 19 |
messages. They often appear to be useless in the listing below. |
| 20 |
|
| 21 |
.. see gh-143054, and CutValidator in the source, if you want to change this: |
| 22 |
|
| 23 |
Cuts currently don't appear inside parentheses, brackets, lookaheads |
| 24 |
and similar. |
| 25 |
Their behavior in these contexts is deliberately left unspecified. |
| 26 |
|
| 27 |
.. literalinclude:: ../../Grammar/python.gram |
| 28 |
:language: peg |