Skip to content

Commit

Permalink
bpo-41762: Fix usage of productionlist markup in the doc (pythonGH-22281
Browse files Browse the repository at this point in the history
)

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".
  • Loading branch information
vstinner authored Sep 18, 2020
1 parent 27201cd commit 8af239e
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 69 deletions.
2 changes: 1 addition & 1 deletion Doc/library/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ are always available. They are listed here in alphabetical order.
input must conform to the following grammar after leading and trailing
whitespace characters are removed:

.. productionlist::
.. productionlist:: float
sign: "+" | "-"
infinity: "Infinity" | "inf"
nan: "nan"
Expand Down
4 changes: 2 additions & 2 deletions Doc/library/string.rst
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ literal text, it can be escaped by doubling: ``{{`` and ``}}``.

The grammar for a replacement field is as follows:

.. productionlist:: sf
.. productionlist:: format-string
replacement_field: "{" [`field_name`] ["!" `conversion`] [":" `format_spec`] "}"
field_name: arg_name ("." `attribute_name` | "[" `element_index` "]")*
arg_name: [`identifier` | `digit`+]
Expand Down Expand Up @@ -308,7 +308,7 @@ non-empty format specification typically modifies the result.

The general form of a *standard format specifier* is:

.. productionlist::
.. productionlist:: format-spec
format_spec: [[`fill`]`align`][`sign`][#][0][`width`][`grouping_option`][.`precision`][`type`]
fill: <any character>
align: "<" | ">" | "=" | "^"
Expand Down
23 changes: 12 additions & 11 deletions Doc/reference/compound_stmts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ executed::

Summarizing:

.. productionlist::

.. productionlist:: python-grammar
compound_stmt: `if_stmt`
: | `while_stmt`
: | `for_stmt`
Expand Down Expand Up @@ -89,7 +90,7 @@ The :keyword:`!if` statement

The :keyword:`if` statement is used for conditional execution:

.. productionlist::
.. productionlist:: python-grammar
if_stmt: "if" `assignment_expression` ":" `suite`
: ("elif" `assignment_expression` ":" `suite`)*
: ["else" ":" `suite`]
Expand All @@ -115,7 +116,7 @@ The :keyword:`!while` statement
The :keyword:`while` statement is used for repeated execution as long as an
expression is true:

.. productionlist::
.. productionlist:: python-grammar
while_stmt: "while" `assignment_expression` ":" `suite`
: ["else" ":" `suite`]

Expand Down Expand Up @@ -151,7 +152,7 @@ The :keyword:`!for` statement
The :keyword:`for` statement is used to iterate over the elements of a sequence
(such as a string, tuple or list) or other iterable object:

.. productionlist::
.. productionlist:: python-grammar
for_stmt: "for" `target_list` "in" `expression_list` ":" `suite`
: ["else" ":" `suite`]

Expand Down Expand Up @@ -234,7 +235,7 @@ The :keyword:`!try` statement
The :keyword:`try` statement specifies exception handlers and/or cleanup code
for a group of statements:

.. productionlist::
.. productionlist:: python-grammar
try_stmt: `try1_stmt` | `try2_stmt`
try1_stmt: "try" ":" `suite`
: ("except" [`expression` ["as" `identifier`]] ":" `suite`)+
Expand Down Expand Up @@ -390,7 +391,7 @@ methods defined by a context manager (see section :ref:`context-managers`).
This allows common :keyword:`try`...\ :keyword:`except`...\ :keyword:`finally`
usage patterns to be encapsulated for convenient reuse.

.. productionlist::
.. productionlist:: python-grammar
with_stmt: "with" `with_item` ("," `with_item`)* ":" `suite`
with_item: `expression` ["as" `target`]

Expand Down Expand Up @@ -503,7 +504,7 @@ Function definitions
A function definition defines a user-defined function object (see section
:ref:`types`):

.. productionlist::
.. productionlist:: python-grammar
funcdef: [`decorators`] "def" `funcname` "(" [`parameter_list`] ")"
: ["->" `expression`] ":" `suite`
decorators: `decorator`+
Expand Down Expand Up @@ -670,7 +671,7 @@ Class definitions

A class definition defines a class object (see section :ref:`types`):

.. productionlist::
.. productionlist:: python-grammar
classdef: [`decorators`] "class" `classname` [`inheritance`] ":" `suite`
inheritance: "(" [`argument_list`] ")"
classname: `identifier`
Expand Down Expand Up @@ -762,7 +763,7 @@ Coroutines
Coroutine function definition
-----------------------------

.. productionlist::
.. productionlist:: python-grammar
async_funcdef: [`decorators`] "async" "def" `funcname` "(" [`parameter_list`] ")"
: ["->" `expression`] ":" `suite`

Expand Down Expand Up @@ -795,7 +796,7 @@ An example of a coroutine function::
The :keyword:`!async for` statement
-----------------------------------

.. productionlist::
.. productionlist:: python-grammar
async_for_stmt: "async" `for_stmt`

An :term:`asynchronous iterable` is able to call asynchronous code in its
Expand Down Expand Up @@ -840,7 +841,7 @@ body of a coroutine function.
The :keyword:`!async with` statement
------------------------------------

.. productionlist::
.. productionlist:: python-grammar
async_with_stmt: "async" `with_stmt`

An :term:`asynchronous context manager` is a :term:`context manager` that is
Expand Down
54 changes: 27 additions & 27 deletions Doc/reference/expressions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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`

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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`]

Expand Down Expand Up @@ -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`


Expand All @@ -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::
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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`]
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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::
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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
Expand All @@ -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`
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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`
Expand All @@ -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`

Expand All @@ -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`]
Expand Down
2 changes: 1 addition & 1 deletion Doc/reference/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Notation
The descriptions of lexical analysis and syntax use a modified BNF grammar
notation. This uses the following style of definition:

.. productionlist::
.. productionlist:: notation
name: `lc_letter` (`lc_letter` | "_")*
lc_letter: "a"..."z"

Expand Down
Loading

0 comments on commit 8af239e

Please sign in to comment.