Kaydet (Commit) 65245739 authored tarafından Žiga Seilnacht's avatar Žiga Seilnacht

Patch #1489771: update syntax rules in Python Reference Manual.

Python 2.5 added support for explicit relative import statements and
yield expressions, which were missing in the manual.
Also fix grammar productions that used the names from the Grammar file,
markup that broke the generated grammar.txt, and wrap some lines that
broke the pdf output.
 (backport from rev. 54559)
üst b151f721
...@@ -93,7 +93,7 @@ grammar notation. This uses the following style of definition: ...@@ -93,7 +93,7 @@ grammar notation. This uses the following style of definition:
\index{syntax} \index{syntax}
\index{notation} \index{notation}
\begin{productionlist} \begin{productionlist}[*]
\production{name}{\token{lc_letter} (\token{lc_letter} | "_")*} \production{name}{\token{lc_letter} (\token{lc_letter} | "_")*}
\production{lc_letter}{"a"..."z"} \production{lc_letter}{"a"..."z"}
\end{productionlist} \end{productionlist}
......
This diff is collapsed.
...@@ -108,7 +108,8 @@ objects: ...@@ -108,7 +108,8 @@ objects:
\begin{productionlist} \begin{productionlist}
\production{assignment_stmt} \production{assignment_stmt}
{(\token{target_list} "=")+ \token{expression_list}} {(\token{target_list} "=")+
(\token{expression_list} | \token{yield_expression})}
\production{target_list} \production{target_list}
{\token{target} ("," \token{target})* [","]} {\token{target} ("," \token{target})* [","]}
\production{target} \production{target}
...@@ -273,11 +274,11 @@ operation and an assignment statement: ...@@ -273,11 +274,11 @@ operation and an assignment statement:
\begin{productionlist} \begin{productionlist}
\production{augmented_assignment_stmt} \production{augmented_assignment_stmt}
{\token{target} \token{augop} \token{expression_list}} {\token{target} \token{augop}
(\token{expression_list} | \token{yield_expression})}
\production{augop} \production{augop}
{"+=" | "-=" | "*=" | "/=" | "\%=" | "**="} {"+=" | "-=" | "*=" | "/=" | "\%=" | "**="}
% The empty groups below prevent conversion to guillemets. \productioncont{| ">>=" | "<<=" | "\&=" | "\textasciicircum=" | "|="}
\productioncont{| ">{}>=" | "<{}<=" | "\&=" | "\textasciicircum=" | "|="}
\end{productionlist} \end{productionlist}
(See section~\ref{primaries} for the syntax definitions for the last (See section~\ref{primaries} for the syntax definitions for the last
...@@ -376,9 +377,9 @@ right type (but even this is determined by the sliced object). ...@@ -376,9 +377,9 @@ right type (but even this is determined by the sliced object).
\begin{productionlist} \begin{productionlist}
\production{print_stmt} \production{print_stmt}
{"print" ( \optional{\token{expression} ("," \token{expression})* \optional{","}}} {"print" ([\token{expression} ("," \token{expression})* [","]}
\productioncont{| ">>" \token{expression} \productioncont{| ">>" \token{expression}
\optional{("," \token{expression})+ \optional{","}} )} [("," \token{expression})+ [","])}
\end{productionlist} \end{productionlist}
\keyword{print} evaluates each expression in turn and writes the \keyword{print} evaluates each expression in turn and writes the
...@@ -460,7 +461,7 @@ to include an \grammartoken{expression_list}. In that context, a bare ...@@ -460,7 +461,7 @@ to include an \grammartoken{expression_list}. In that context, a bare
\begin{productionlist} \begin{productionlist}
\production{yield_stmt} \production{yield_stmt}
{"yield" \token{expression_list}} {\token{yield_expression}}
\end{productionlist} \end{productionlist}
\index{generator!function} \index{generator!function}
...@@ -630,15 +631,19 @@ It continues with the next cycle of the nearest enclosing loop. ...@@ -630,15 +631,19 @@ It continues with the next cycle of the nearest enclosing loop.
\production{import_stmt} \production{import_stmt}
{"import" \token{module} ["as" \token{name}] {"import" \token{module} ["as" \token{name}]
( "," \token{module} ["as" \token{name}] )*} ( "," \token{module} ["as" \token{name}] )*}
\productioncont{| "from" \token{module} "import" \token{identifier} \productioncont{| "from" \token{relative_module} "import" \token{identifier}
["as" \token{name}]} ["as" \token{name}]}
\productioncont{ ( "," \token{identifier} ["as" \token{name}] )*} \productioncont{ ( "," \token{identifier} ["as" \token{name}] )*}
\productioncont{| "from" \token{module} "import" "(" \token{identifier} \productioncont{| "from" \token{relative_module} "import" "("
["as" \token{name}]} \token{identifier} ["as" \token{name}]}
\productioncont{ ( "," \token{identifier} ["as" \token{name}] )* [","] ")"} \productioncont{ ( "," \token{identifier} ["as" \token{name}] )* [","] ")"}
\productioncont{| "from" \token{module} "import" "*"} \productioncont{| "from" \token{module} "import" "*"}
\production{module} \production{module}
{(\token{identifier} ".")* \token{identifier}} {(\token{identifier} ".")* \token{identifier}}
\production{relative_module}
{"."* \token{module} | "."+}
\production{name}
{\token{identifier}}
\end{productionlist} \end{productionlist}
Import statements are executed in two steps: (1) find a module, and Import statements are executed in two steps: (1) find a module, and
...@@ -757,8 +762,10 @@ before the release in which the feature becomes standard. ...@@ -757,8 +762,10 @@ before the release in which the feature becomes standard.
\begin{productionlist}[*] \begin{productionlist}[*]
\production{future_statement} \production{future_statement}
{"from" "__future__" "import" feature ["as" name] ("," feature ["as" name])*} {"from" "__future__" "import" feature ["as" name]}
\productioncont{| "from" "__future__" "import" "(" feature ["as" name] ("," feature ["as" name])* [","] ")"} \productioncont{ ("," feature ["as" name])*}
\productioncont{| "from" "__future__" "import" "(" feature ["as" name]}
\productioncont{ ("," feature ["as" name])* [","] ")"}
\production{feature}{identifier} \production{feature}{identifier}
\production{name}{identifier} \production{name}{identifier}
\end{productionlist} \end{productionlist}
...@@ -775,9 +782,10 @@ lines that can appear before a future statement are: ...@@ -775,9 +782,10 @@ lines that can appear before a future statement are:
\end{itemize} \end{itemize}
The features recognized by Python 2.3 are \samp{generators}, The features recognized by Python 2.5 are \samp{absolute_import},
\samp{division} and \samp{nested_scopes}. \samp{generators} and \samp{division}, \samp{generators}, \samp{nested_scopes} and
\samp{nested_scopes} are redundant in 2.3 because they are always \samp{with_statement}. \samp{generators} and \samp{nested_scopes}
are redundant in Python version 2.3 and above because they are always
enabled. enabled.
A future statement is recognized and treated specially at compile A future statement is recognized and treated specially at compile
...@@ -872,7 +880,7 @@ containing the \keyword{exec} statement. The same applies to the ...@@ -872,7 +880,7 @@ containing the \keyword{exec} statement. The same applies to the
\begin{productionlist} \begin{productionlist}
\production{exec_stmt} \production{exec_stmt}
{"exec" \token{expression} {"exec" \token{or_expr}
["in" \token{expression} ["," \token{expression}]]} ["in" \token{expression} ["," \token{expression}]]}
\end{productionlist} \end{productionlist}
...@@ -916,3 +924,5 @@ for use by \keyword{exec}. ...@@ -916,3 +924,5 @@ for use by \keyword{exec}.
...@@ -319,7 +319,7 @@ be encapsulated for convenient reuse. ...@@ -319,7 +319,7 @@ be encapsulated for convenient reuse.
\begin{productionlist} \begin{productionlist}
\production{with_stmt} \production{with_stmt}
{"with" \token{expression} ["as" target] ":" \token{suite}} {"with" \token{expression} ["as" \token{target}] ":" \token{suite}}
\end{productionlist} \end{productionlist}
The execution of the \keyword{with} statement proceeds as follows: The execution of the \keyword{with} statement proceeds as follows:
......
...@@ -452,6 +452,9 @@ Windows ...@@ -452,6 +452,9 @@ Windows
Documentation Documentation
------------- -------------
- Patch #1489771: the syntax rules in Python Reference Manual were
updated to reflect the current Python syntax.
- Patch #1686451: Fix return type for - Patch #1686451: Fix return type for
PySequence_{Count,Index,Fast_GET_SIZE}. PySequence_{Count,Index,Fast_GET_SIZE}.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment