2023-12-17 21:23:14 +02:00
|
|
|
.. _full-grammar-specification:
|
|
|
|
|
|
2008-08-03 09:47:27 +00:00
|
|
|
Full Grammar specification
|
|
|
|
|
==========================
|
|
|
|
|
|
2020-07-27 19:20:36 +01:00
|
|
|
This is the full Python grammar, derived directly from the grammar
|
|
|
|
|
used to generate the CPython parser (see :source:`Grammar/python.gram`).
|
|
|
|
|
The version here omits details related to code generation and
|
|
|
|
|
error recovery.
|
2008-08-03 09:47:27 +00:00
|
|
|
|
2025-06-09 15:50:11 +02:00
|
|
|
The notation used here is the same as in the preceding docs,
|
|
|
|
|
and is described in the :ref:`notation <notation>` section,
|
2025-07-23 17:57:54 +02:00
|
|
|
except for an extra complication:
|
2025-06-09 15:50:11 +02:00
|
|
|
|
2026-01-13 13:21:59 +01:00
|
|
|
* ``~`` ("cut"): commit to the current alternative; fail the rule
|
|
|
|
|
if the alternative fails to parse
|
|
|
|
|
|
|
|
|
|
Python mainly uses cuts for optimizations or improved error
|
|
|
|
|
messages. They often appear to be useless in the listing below.
|
|
|
|
|
|
|
|
|
|
.. see gh-143054, and CutValidator in the source, if you want to change this:
|
|
|
|
|
|
|
|
|
|
Cuts currently don't appear inside parentheses, brackets, lookaheads
|
|
|
|
|
and similar.
|
|
|
|
|
Their behavior in these contexts is deliberately left unspecified.
|
2020-07-27 19:20:36 +01:00
|
|
|
|
|
|
|
|
.. literalinclude:: ../../Grammar/python.gram
|
|
|
|
|
:language: peg
|