Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitec90d40

Browse files
encukoublaisep
andcommitted
Consolidate with the Full Grammar intro
Co-authored-by: Blaise Pabon <blaise@gmail.com>
1 parent211f83d commitec90d40

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

‎Doc/reference/grammar.rst

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@ used to generate the CPython parser (see :source:`Grammar/python.gram`).
88
The version here omits details related to code generation and
99
error recovery.
1010

11-
The notation is a mixture of `EBNF
12-
<https://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_form>`_
13-
and `PEG<https://en.wikipedia.org/wiki/Parsing_expression_grammar>`_.
14-
In particular, ``&`` followed by a symbol, token or parenthesized
15-
group indicates a positive lookahead (i.e., is required to match but
16-
not consumed), while ``!`` indicates a negative lookahead (i.e., is
17-
required *not* to match). We use the ``|`` separator to mean PEG's
18-
"ordered choice" (written as ``/`` in traditional PEG grammars). See
19-
:pep:`617` for more details on the grammar's syntax.
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 a few extra complications:
14+
15+
* ``&e``: a positive lookahead (that is, ``e`` is required to match but
16+
not consumed)
17+
* ``!e``: a negative lookahead (that is, ``e`` is required *not* to match)
2018

2119
..literalinclude::../../Grammar/python.gram
2220
:language: peg

‎Doc/reference/introduction.rst

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,10 @@ Notation
9090

9191
..index::BNF, grammar, syntax, notation
9292

93-
The descriptions of lexical analysis and syntax use a modified
94-
`Backus–Naur form (BNF)<https://en.wikipedia.org/wiki/Backus%E2%80%93Naur_form>`_ grammar
95-
notation. This uses the following style of definition:
93+
The descriptions of lexical analysis use a grammar notation that is a mixture
94+
of `EBNF<https://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_form>`_
95+
and `PEG<https://en.wikipedia.org/wiki/Parsing_expression_grammar>`_.
96+
For example:
9697

9798
..grammar-snippet::
9899
:group: notation
@@ -136,7 +137,11 @@ The definition to the right of the colon uses the following syntax elements:
136137
* ``e1 e2``: Items separated only by whitespace denote a sequence.
137138
Here, ``e1`` must be followed by ``e2``.
138139
* ``e1 | e2``: A vertical bar is used to separate alternatives.
139-
It is the least tightly binding operator in this notation.
140+
It denotes PEG's "ordered choice": if ``e1`` matches, ``e2`` is
141+
not considered.
142+
In traditional PEG grammars, this is written as a slash, ``/``, rather than
143+
a vertical bar.
144+
See:pep:`617` for more background and details.
140145
* ``e*``: A star means zero or more repetitions of the preceding item.
141146
* ``e+``: Likewise, a plus means one or more repetitions.
142147
* ``[e]``: A phrase enclosed in square brackets means zero or
@@ -145,7 +150,8 @@ The definition to the right of the colon uses the following syntax elements:
145150
the preceding item is optional.
146151
* ``(e)``: Parentheses are used for grouping.
147152

148-
The unary operators (``*``, ``+``, ``?``) bind as tightly as possible.
153+
The unary operators (``*``, ``+``, ``?``) bind as tightly as possible;
154+
the vertical bar (``|``) binds most loosely.
149155

150156
White space is only meaningful to separate tokens.
151157

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp