summaryrefslogtreecommitdiffstats
path: root/Doc/reference
diff options
context:
space:
mode:
authorPablo Galindo <Pablogsal@gmail.com>2020-07-27 18:20:36 (GMT)
committerGitHub <noreply@github.com>2020-07-27 18:20:36 (GMT)
commit72cabb2aa636272e608285f5a6ba83b62be9be4e (patch)
treec43c2815b9aa9389413934136c7be9ac514c6081 /Doc/reference
parent67987acd5dc9776f55f4e139e2b3d9e7a6434d9f (diff)
downloadcpython-72cabb2aa636272e608285f5a6ba83b62be9be4e.zip
cpython-72cabb2aa636272e608285f5a6ba83b62be9be4e.tar.gz
cpython-72cabb2aa636272e608285f5a6ba83b62be9be4e.tar.bz2
bpo-40939: Use the new grammar for the grammar specification documentation (GH-19969)
(We censor the heck out of actions and some other stuff using a custom "highlighter".) Co-authored-by: Guido van Rossum <guido@python.org>
Diffstat (limited to 'Doc/reference')
-rw-r--r--Doc/reference/grammar.rst18
1 files changed, 15 insertions, 3 deletions
diff --git a/Doc/reference/grammar.rst b/Doc/reference/grammar.rst
index 83d0f85..acf8376 100644
--- a/Doc/reference/grammar.rst
+++ b/Doc/reference/grammar.rst
@@ -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
+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