@@ -13,7 +13,7 @@ This chapter explains the meaning of the elements of expressions in Python.
1313be used to describe syntax, not lexical analysis. When (one alternative of) a
1414syntax rule has the form
1515
16- .. productionlist :: *
16+ .. productionlist :: python-grammar
1717 name: `othername `
1818
1919and 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
5454identifiers or literals. Forms enclosed in parentheses, brackets or braces are
5555also categorized syntactically as atoms. The syntax for atoms is:
5656
57- .. productionlist ::
57+ .. productionlist :: python-grammar
5858 atom: `identifier ` | `literal ` | `enclosure `
5959 enclosure: `parenth_form ` | `list_display ` | `dict_display ` | `set_display `
6060 : | `generator_expression ` | `yield_atom `
@@ -103,7 +103,7 @@ Literals
103103
104104Python supports string and bytes literals and various numeric literals:
105105
106- .. productionlist ::
106+ .. productionlist :: python-grammar
107107 literal: `stringliteral ` | `bytesliteral `
108108 : | `integer ` | `floatnumber ` | `imagnumber `
109109
@@ -134,7 +134,7 @@ Parenthesized forms
134134
135135A parenthesized form is an optional expression list enclosed in parentheses:
136136
137- .. productionlist ::
137+ .. productionlist :: python-grammar
138138 parenth_form: "(" [`starred_expression `] ")"
139139
140140A parenthesized expression list yields whatever that expression list yields: if
@@ -177,7 +177,7 @@ called "displays", each of them in two flavors:
177177
178178Common syntax elements for comprehensions are:
179179
180- .. productionlist ::
180+ .. productionlist :: python-grammar
181181 comprehension: `assignment_expression ` `comp_for `
182182 comp_for: ["async"] "for" `target_list ` "in" `or_test ` [`comp_iter `]
183183 comp_iter: `comp_for ` | `comp_if `
@@ -243,7 +243,7 @@ List displays
243243A list display is a possibly empty series of expressions enclosed in square
244244brackets:
245245
246- .. productionlist ::
246+ .. productionlist :: python-grammar
247247 list_display: "[" [`starred_list ` | `comprehension `] "]"
248248
249249A list display yields a new list object, the contents being specified by either
@@ -267,7 +267,7 @@ Set displays
267267A set display is denoted by curly braces and distinguishable from dictionary
268268displays by the lack of colons separating keys and values:
269269
270- .. productionlist ::
270+ .. productionlist :: python-grammar
271271 set_display: "{" (`starred_list ` | `comprehension `) "}"
272272
273273A set display yields a new mutable set object, the contents being specified by
@@ -296,7 +296,7 @@ Dictionary displays
296296A dictionary display is a possibly empty series of key/datum pairs enclosed in
297297curly braces:
298298
299- .. productionlist ::
299+ .. productionlist :: python-grammar
300300 dict_display: "{" [`key_datum_list ` | `dict_comprehension `] "}"
301301 key_datum_list: `key_datum ` ("," `key_datum `)* [","]
302302 key_datum: `expression ` ":" `expression ` | "**" `or_expr `
@@ -355,7 +355,7 @@ Generator expressions
355355
356356A generator expression is a compact generator notation in parentheses:
357357
358- .. productionlist ::
358+ .. productionlist :: python-grammar
359359 generator_expression: "(" `expression ` `comp_for ` ")"
360360
361361A generator expression yields a new generator object. Its syntax is the same as
@@ -409,7 +409,7 @@ Yield expressions
409409 pair: yield; expression
410410 pair: generator; function
411411
412- .. productionlist ::
412+ .. productionlist :: python-grammar
413413 yield_atom: "(" `yield_expression ` ")"
414414 yield_expression: "yield" [`expression_list ` | "from" `expression `]
415415
@@ -746,7 +746,7 @@ Primaries
746746Primaries represent the most tightly bound operations of the language. Their
747747syntax is:
748748
749- .. productionlist ::
749+ .. productionlist :: python-grammar
750750 primary: `atom ` | `attributeref ` | `subscription ` | `slicing ` | `call `
751751
752752
@@ -761,7 +761,7 @@ Attribute references
761761
762762An attribute reference is a primary followed by a period and a name:
763763
764- .. productionlist ::
764+ .. productionlist :: python-grammar
765765 attributeref: `primary ` "." `identifier `
766766
767767.. index ::
@@ -799,7 +799,7 @@ Subscriptions
799799A subscription selects an item of a sequence (string, tuple or list) or mapping
800800(dictionary) object:
801801
802- .. productionlist ::
802+ .. productionlist :: python-grammar
803803 subscription: `primary ` "[" `expression_list ` "]"
804804
805805The 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
855855or list). Slicings may be used as expressions or as targets in assignment or
856856:keyword: `del ` statements. The syntax for a slicing:
857857
858- .. productionlist ::
858+ .. productionlist :: python-grammar
859859 slicing: `primary ` "[" `slice_list ` "]"
860860 slice_list: `slice_item ` ("," `slice_item `)* [","]
861861 slice_item: `expression ` | `proper_slice `
@@ -905,7 +905,7 @@ Calls
905905A call calls a callable object (e.g., a :term: `function `) with a possibly empty
906906series of :term: `arguments <argument> `:
907907
908- .. productionlist ::
908+ .. productionlist :: python-grammar
909909 call: `primary ` "(" [`argument_list ` [","] | `comprehension `] ")"
910910 argument_list: `positional_arguments ` ["," `starred_and_keywords `]
911911 : ["," `keywords_arguments `]
@@ -1088,7 +1088,7 @@ Await expression
10881088Suspend the execution of :term: `coroutine ` on an :term: `awaitable ` object.
10891089Can only be used inside a :term: `coroutine function `.
10901090
1091- .. productionlist ::
1091+ .. productionlist :: python-grammar
10921092 await_expr: "await" `primary `
10931093
10941094.. versionadded :: 3.5
@@ -1106,7 +1106,7 @@ The power operator
11061106The power operator binds more tightly than unary operators on its left; it binds
11071107less tightly than unary operators on its right. The syntax is:
11081108
1109- .. productionlist ::
1109+ .. productionlist :: python-grammar
11101110 power: (`await_expr ` | `primary `) ["**" `u_expr `]
11111111
11121112Thus, in an unparenthesized sequence of power and unary operators, the operators
@@ -1139,7 +1139,7 @@ Unary arithmetic and bitwise operations
11391139
11401140All unary arithmetic and bitwise operations have the same priority:
11411141
1142- .. productionlist ::
1142+ .. productionlist :: python-grammar
11431143 u_expr: `power ` | "-" `u_expr ` | "+" `u_expr ` | "~" `u_expr `
11441144
11451145.. index ::
@@ -1183,7 +1183,7 @@ that some of these operations also apply to certain non-numeric types. Apart
11831183from the power operator, there are only two levels, one for multiplicative
11841184operators and one for additive operators:
11851185
1186- .. productionlist ::
1186+ .. productionlist :: python-grammar
11871187 m_expr: `u_expr ` | `m_expr ` "*" `u_expr ` | `m_expr ` "@" `m_expr ` |
11881188 : `m_expr ` "//" `u_expr ` | `m_expr ` "/" `u_expr ` |
11891189 : `m_expr ` "%" `u_expr `
@@ -1279,7 +1279,7 @@ Shifting operations
12791279
12801280The shifting operations have lower priority than the arithmetic operations:
12811281
1282- .. productionlist ::
1282+ .. productionlist :: python-grammar
12831283 shift_expr: `a_expr ` | `shift_expr ` ("<<" | ">>") `a_expr `
12841284
12851285These operators accept integers as arguments. They shift the first argument to
@@ -1300,7 +1300,7 @@ Binary bitwise operations
13001300
13011301Each of the three bitwise operations has a different priority level:
13021302
1303- .. productionlist ::
1303+ .. productionlist :: python-grammar
13041304 and_expr: `shift_expr ` | `and_expr ` "&" `shift_expr `
13051305 xor_expr: `and_expr ` | `xor_expr ` "^" `and_expr `
13061306 or_expr: `xor_expr ` | `or_expr ` "|" `xor_expr`
@@ -1349,7 +1349,7 @@ lower than that of any arithmetic, shifting or bitwise operation. Also unlike
13491349C, expressions like ``a < b < c `` have the interpretation that is conventional
13501350in mathematics:
13511351
1352- .. productionlist ::
1352+ .. productionlist :: python-grammar
13531353 comparison: `or_expr ` (`comp_operator ` `or_expr `)*
13541354 comp_operator: "<" | ">" | "==" | ">=" | "<=" | "!="
13551355 : | "is" ["not"] | ["not"] "in"
@@ -1608,7 +1608,7 @@ Boolean operations
16081608 pair: Conditional; expression
16091609 pair: Boolean; operation
16101610
1611- .. productionlist ::
1611+ .. productionlist :: python-grammar
16121612 or_test: `and_test ` | `or_test ` "or" `and_test `
16131613 and_test: `not_test ` | `and_test ` "and" `not_test `
16141614 not_test: `comparison ` | "not" `not_test `
@@ -1647,7 +1647,7 @@ returns a boolean value regardless of the type of its argument
16471647Assignment expressions
16481648======================
16491649
1650- .. productionlist ::
1650+ .. productionlist :: python-grammar
16511651 assignment_expression: [`identifier ` ":="] `expression `
16521652
16531653An assignment expression (sometimes also called a "named expression" or
@@ -1683,7 +1683,7 @@ Conditional expressions
16831683 single: if; conditional expression
16841684 single: else; conditional expression
16851685
1686- .. productionlist ::
1686+ .. productionlist :: python-grammar
16871687 conditional_expression: `or_test ` ["if" `or_test ` "else" `expression `]
16881688 expression: `conditional_expression ` | `lambda_expr `
16891689 expression_nocond: `or_test ` | `lambda_expr_nocond `
@@ -1710,7 +1710,7 @@ Lambdas
17101710 pair: anonymous; function
17111711 single: : (colon); lambda expression
17121712
1713- .. productionlist ::
1713+ .. productionlist :: python-grammar
17141714 lambda_expr: "lambda" [`parameter_list `] ":" `expression `
17151715 lambda_expr_nocond: "lambda" [`parameter_list `] ":" `expression_nocond `
17161716
@@ -1737,7 +1737,7 @@ Expression lists
17371737 pair: expression; list
17381738 single: , (comma); expression list
17391739
1740- .. productionlist ::
1740+ .. productionlist :: python-grammar
17411741 expression_list: `expression ` ("," `expression `)* [","]
17421742 starred_list: `starred_item ` ("," `starred_item `)* [","]
17431743 starred_expression: `expression ` | (`starred_item ` ",")* [`starred_item `]
0 commit comments