bpo-41762: Fix usage of productionlist markup in the doc (GH-22281)

Use an unique identifier for the different grammars documented using
the Sphinx productionlist markup.

productionlist markups of the same grammar, like "expressions" or
"compound statements", use the same identifier "python-grammar".
This commit is contained in:
Victor Stinner 2020-09-18 09:10:15 +02:00 committed by GitHub
parent 27201cddf3
commit 8af239eacf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 70 additions and 69 deletions

View file

@ -13,7 +13,7 @@ This chapter explains the meaning of the elements of expressions in Python.
be used to describe syntax, not lexical analysis. When (one alternative of) a
syntax rule has the form
.. productionlist:: *
.. productionlist:: python-grammar
name: `othername`
and no semantics are given, the semantics of this form of ``name`` are the same
@ -54,7 +54,7 @@ Atoms are the most basic elements of expressions. The simplest atoms are
identifiers or literals. Forms enclosed in parentheses, brackets or braces are
also categorized syntactically as atoms. The syntax for atoms is:
.. productionlist::
.. productionlist:: python-grammar
atom: `identifier` | `literal` | `enclosure`
enclosure: `parenth_form` | `list_display` | `dict_display` | `set_display`
: | `generator_expression` | `yield_atom`
@ -103,7 +103,7 @@ Literals
Python supports string and bytes literals and various numeric literals:
.. productionlist::
.. productionlist:: python-grammar
literal: `stringliteral` | `bytesliteral`
: | `integer` | `floatnumber` | `imagnumber`
@ -134,7 +134,7 @@ Parenthesized forms
A parenthesized form is an optional expression list enclosed in parentheses:
.. productionlist::
.. productionlist:: python-grammar
parenth_form: "(" [`starred_expression`] ")"
A parenthesized expression list yields whatever that expression list yields: if
@ -177,7 +177,7 @@ called "displays", each of them in two flavors:
Common syntax elements for comprehensions are:
.. productionlist::
.. productionlist:: python-grammar
comprehension: `assignment_expression` `comp_for`
comp_for: ["async"] "for" `target_list` "in" `or_test` [`comp_iter`]
comp_iter: `comp_for` | `comp_if`
@ -243,7 +243,7 @@ List displays
A list display is a possibly empty series of expressions enclosed in square
brackets:
.. productionlist::
.. productionlist:: python-grammar
list_display: "[" [`starred_list` | `comprehension`] "]"
A list display yields a new list object, the contents being specified by either
@ -267,7 +267,7 @@ Set displays
A set display is denoted by curly braces and distinguishable from dictionary
displays by the lack of colons separating keys and values:
.. productionlist::
.. productionlist:: python-grammar
set_display: "{" (`starred_list` | `comprehension`) "}"
A set display yields a new mutable set object, the contents being specified by
@ -296,7 +296,7 @@ Dictionary displays
A dictionary display is a possibly empty series of key/datum pairs enclosed in
curly braces:
.. productionlist::
.. productionlist:: python-grammar
dict_display: "{" [`key_datum_list` | `dict_comprehension`] "}"
key_datum_list: `key_datum` ("," `key_datum`)* [","]
key_datum: `expression` ":" `expression` | "**" `or_expr`
@ -355,7 +355,7 @@ Generator expressions
A generator expression is a compact generator notation in parentheses:
.. productionlist::
.. productionlist:: python-grammar
generator_expression: "(" `expression` `comp_for` ")"
A generator expression yields a new generator object. Its syntax is the same as
@ -409,7 +409,7 @@ Yield expressions
pair: yield; expression
pair: generator; function
.. productionlist::
.. productionlist:: python-grammar
yield_atom: "(" `yield_expression` ")"
yield_expression: "yield" [`expression_list` | "from" `expression`]
@ -746,7 +746,7 @@ Primaries
Primaries represent the most tightly bound operations of the language. Their
syntax is:
.. productionlist::
.. productionlist:: python-grammar
primary: `atom` | `attributeref` | `subscription` | `slicing` | `call`
@ -761,7 +761,7 @@ Attribute references
An attribute reference is a primary followed by a period and a name:
.. productionlist::
.. productionlist:: python-grammar
attributeref: `primary` "." `identifier`
.. index::
@ -799,7 +799,7 @@ Subscriptions
A subscription selects an item of a sequence (string, tuple or list) or mapping
(dictionary) object:
.. productionlist::
.. productionlist:: python-grammar
subscription: `primary` "[" `expression_list` "]"
The primary must evaluate to an object that supports subscription (lists or
@ -855,7 +855,7 @@ A slicing selects a range of items in a sequence object (e.g., a string, tuple
or list). Slicings may be used as expressions or as targets in assignment or
:keyword:`del` statements. The syntax for a slicing:
.. productionlist::
.. productionlist:: python-grammar
slicing: `primary` "[" `slice_list` "]"
slice_list: `slice_item` ("," `slice_item`)* [","]
slice_item: `expression` | `proper_slice`
@ -905,7 +905,7 @@ Calls
A call calls a callable object (e.g., a :term:`function`) with a possibly empty
series of :term:`arguments <argument>`:
.. productionlist::
.. productionlist:: python-grammar
call: `primary` "(" [`argument_list` [","] | `comprehension`] ")"
argument_list: `positional_arguments` ["," `starred_and_keywords`]
: ["," `keywords_arguments`]
@ -1088,7 +1088,7 @@ Await expression
Suspend the execution of :term:`coroutine` on an :term:`awaitable` object.
Can only be used inside a :term:`coroutine function`.
.. productionlist::
.. productionlist:: python-grammar
await_expr: "await" `primary`
.. versionadded:: 3.5
@ -1106,7 +1106,7 @@ The power operator
The power operator binds more tightly than unary operators on its left; it binds
less tightly than unary operators on its right. The syntax is:
.. productionlist::
.. productionlist:: python-grammar
power: (`await_expr` | `primary`) ["**" `u_expr`]
Thus, in an unparenthesized sequence of power and unary operators, the operators
@ -1139,7 +1139,7 @@ Unary arithmetic and bitwise operations
All unary arithmetic and bitwise operations have the same priority:
.. productionlist::
.. productionlist:: python-grammar
u_expr: `power` | "-" `u_expr` | "+" `u_expr` | "~" `u_expr`
.. index::
@ -1183,7 +1183,7 @@ that some of these operations also apply to certain non-numeric types. Apart
from the power operator, there are only two levels, one for multiplicative
operators and one for additive operators:
.. productionlist::
.. productionlist:: python-grammar
m_expr: `u_expr` | `m_expr` "*" `u_expr` | `m_expr` "@" `m_expr` |
: `m_expr` "//" `u_expr` | `m_expr` "/" `u_expr` |
: `m_expr` "%" `u_expr`
@ -1279,7 +1279,7 @@ Shifting operations
The shifting operations have lower priority than the arithmetic operations:
.. productionlist::
.. productionlist:: python-grammar
shift_expr: `a_expr` | `shift_expr` ("<<" | ">>") `a_expr`
These operators accept integers as arguments. They shift the first argument to
@ -1300,7 +1300,7 @@ Binary bitwise operations
Each of the three bitwise operations has a different priority level:
.. productionlist::
.. productionlist:: python-grammar
and_expr: `shift_expr` | `and_expr` "&" `shift_expr`
xor_expr: `and_expr` | `xor_expr` "^" `and_expr`
or_expr: `xor_expr` | `or_expr` "|" `xor_expr`
@ -1349,7 +1349,7 @@ lower than that of any arithmetic, shifting or bitwise operation. Also unlike
C, expressions like ``a < b < c`` have the interpretation that is conventional
in mathematics:
.. productionlist::
.. productionlist:: python-grammar
comparison: `or_expr` (`comp_operator` `or_expr`)*
comp_operator: "<" | ">" | "==" | ">=" | "<=" | "!="
: | "is" ["not"] | ["not"] "in"
@ -1608,7 +1608,7 @@ Boolean operations
pair: Conditional; expression
pair: Boolean; operation
.. productionlist::
.. productionlist:: python-grammar
or_test: `and_test` | `or_test` "or" `and_test`
and_test: `not_test` | `and_test` "and" `not_test`
not_test: `comparison` | "not" `not_test`
@ -1647,7 +1647,7 @@ returns a boolean value regardless of the type of its argument
Assignment expressions
======================
.. productionlist::
.. productionlist:: python-grammar
assignment_expression: [`identifier` ":="] `expression`
An assignment expression (sometimes also called a "named expression" or
@ -1683,7 +1683,7 @@ Conditional expressions
single: if; conditional expression
single: else; conditional expression
.. productionlist::
.. productionlist:: python-grammar
conditional_expression: `or_test` ["if" `or_test` "else" `expression`]
expression: `conditional_expression` | `lambda_expr`
expression_nocond: `or_test` | `lambda_expr_nocond`
@ -1710,7 +1710,7 @@ Lambdas
pair: anonymous; function
single: : (colon); lambda expression
.. productionlist::
.. productionlist:: python-grammar
lambda_expr: "lambda" [`parameter_list`] ":" `expression`
lambda_expr_nocond: "lambda" [`parameter_list`] ":" `expression_nocond`
@ -1737,7 +1737,7 @@ Expression lists
pair: expression; list
single: , (comma); expression list
.. productionlist::
.. productionlist:: python-grammar
expression_list: `expression` ("," `expression`)* [","]
starred_list: `starred_item` ("," `starred_item`)* [","]
starred_expression: `expression` | (`starred_item` ",")* [`starred_item`]