Index: Doc/ref/ref1.tex =================================================================== --- Doc/ref/ref1.tex (revision 50960) +++ Doc/ref/ref1.tex (working copy) @@ -93,7 +93,7 @@ \index{syntax} \index{notation} -\begin{productionlist} +\begin{productionlist}[*] \production{name}{\token{lc_letter} (\token{lc_letter} | "_")*} \production{lc_letter}{"a"..."z"} \end{productionlist} Index: Doc/ref/ref5.tex =================================================================== --- Doc/ref/ref5.tex (revision 50960) +++ Doc/ref/ref5.tex (working copy) @@ -65,6 +65,7 @@ \index{identifier} An identifier occurring as an atom is a name. See +section \ref{identifiers} for lexical definition and section~\ref{naming} for documentation of naming and binding. When the name is bound to an object, evaluation of the atom yields @@ -154,20 +155,19 @@ square brackets: \begin{productionlist} + \production{list_display} + {"[" [\token{expression_list} | \token{list_comprehension}] "]"} + \production{list_comprehension} + {\token{expression} \token{list_for}} + \production{list_for} + {"for" \token{target_list} "in" \token{test_list} + [\token{list_iter}]} + \production{test_list} + {\token{test} [("," \token{test})+ [","]]} \production{test} {\token{or_test} | \token{lambda_form}} - \production{testlist} - {\token{test} ( "," \token{test} )* [ "," ]} - \production{list_display} - {"[" [\token{listmaker}] "]"} - \production{listmaker} - {\token{expression} ( \token{list_for} - | ( "," \token{expression} )* [","] )} \production{list_iter} {\token{list_for} | \token{list_if}} - \production{list_for} - {"for" \token{expression_list} "in" \token{testlist} - [\token{list_iter}]} \production{list_if} {"if" \token{test} [\token{list_iter}]} \end{productionlist} @@ -200,9 +200,9 @@ \begin{productionlist} \production{generator_expression} - {"(" \token{test} \token{genexpr_for} ")"} + {"(" \token{expression} \token{genexpr_for} ")"} \production{genexpr_for} - {"for" \token{expression_list} "in" \token{test} + {"for" \token{target_list} "in" \token{or_test} [\token{genexpr_iter}]} \production{genexpr_iter} {\token{genexpr_for} | \token{genexpr_if}} @@ -474,17 +474,18 @@ \begin{productionlist} \production{call} - {\token{primary} "(" [\token{argument_list} [","]] ")"} - {\token{primary} "(" [\token{argument_list} [","] | - \token{test} \token{genexpr_for} ] ")"} + {\token{primary} "(" [\token{argument_list} | + \token{expression} \token{genexr_for}] ")"} \production{argument_list} - {\token{positional_arguments} ["," \token{keyword_arguments}]} - \productioncont{ ["," "*" \token{expression}]} - \productioncont{ ["," "**" \token{expression}]} - \productioncont{| \token{keyword_arguments} ["," "*" \token{expression}]} - \productioncont{ ["," "**" \token{expression}]} - \productioncont{| "*" \token{expression} ["," "**" \token{expression}]} - \productioncont{| "**" \token{expression}} + {\token{positional_arguments} [","]} + \productioncont{| [\token{positional_arguments} ","] + \token{keyword_arguments} [","]} + \productioncont{| [\token{positional_arguments} ","] + [\token{keyword_arguments} ","]} + \productioncont{ "*" \token{expression}} + \productioncont{| [\token{positional_arguments} ","] + [\token{keyword_arguments} ","]} + \productioncont{ ["*" \token{expression} ","] "**" \token{expression}} \production{positional_arguments} {\token{expression} ("," \token{expression})*} \production{keyword_arguments} @@ -809,10 +810,9 @@ operations: \begin{productionlist} - % The empty groups below prevent conversion to guillemets. \production{shift_expr} {\token{a_expr} - | \token{shift_expr} ( "<{}<" | ">{}>" ) \token{a_expr}} + | \token{shift_expr} ( "<<" | ">>" ) \token{a_expr}} \end{productionlist} These operators accept plain or long integers as arguments. The @@ -1015,14 +1015,16 @@ \section{Boolean operations\label{Booleans}} +\indexii{Conditional}{expression} \indexii{Boolean}{operation} Boolean operations have the lowest priority of all Python operations: \begin{productionlist} \production{expression} - {\token{or_test} [\token{if} \token{or_test} \token{else} - \token{test}] | \token{lambda_form}} + {\token{conditional_expression} | \token{lambda_form}} + \production{conditional_expression} + {\token{or_test} ["if" \token{or_test} "else" \token{expression}]} \production{or_test} {\token{and_test} | \token{or_test} "or" \token{and_test}} \production{and_test} Index: Doc/ref/ref6.tex =================================================================== --- Doc/ref/ref6.tex (revision 50960) +++ Doc/ref/ref6.tex (working copy) @@ -276,8 +276,7 @@ {\token{target} \token{augop} \token{expression_list}} \production{augop} {"+=" | "-=" | "*=" | "/=" | "\%=" | "**="} - % The empty groups below prevent conversion to guillemets. - \productioncont{| ">{}>=" | "<{}<=" | "\&=" | "\textasciicircum=" | "|="} + \productioncont{| ">>=" | "<<=" | "\&=" | "\textasciicircum=" | "|="} \end{productionlist} (See section~\ref{primaries} for the syntax definitions for the last @@ -376,9 +375,9 @@ \begin{productionlist} \production{print_stmt} - {"print" ( \optional{\token{expression} ("," \token{expression})* \optional{","}}} + {"print" ([\token{expression} ("," \token{expression})* [","]} \productioncont{| ">>" \token{expression} - \optional{("," \token{expression})+ \optional{","}} )} + [("," \token{expression})+ [","])} \end{productionlist} \keyword{print} evaluates each expression in turn and writes the @@ -460,7 +459,7 @@ \begin{productionlist} \production{yield_stmt} - {"yield" \token{expression_list}} + {"yield" [\token{expression_list}]} \end{productionlist} \index{generator!function} @@ -626,19 +625,25 @@ \indexii{name}{binding} \kwindex{from} +% XXX Description of relative imports is still needed. + \begin{productionlist} \production{import_stmt} {"import" \token{module} ["as" \token{name}] - ( "," \token{module} ["as" \token{name}] )*} - \productioncont{| "from" \token{module} "import" \token{identifier} + ("," \token{module} ["as" \token{name}])*} + \productioncont{| "from" \token{relative_module} "import" \token{identifier} ["as" \token{name}]} - \productioncont{ ( "," \token{identifier} ["as" \token{name}] )*} - \productioncont{| "from" \token{module} "import" "(" \token{identifier} - ["as" \token{name}]} - \productioncont{ ( "," \token{identifier} ["as" \token{name}] )* [","] ")"} + \productioncont{ ("," \token{identifier} ["as" \token{name}])*} + \productioncont{| "from" \token{relative_module} "import" "(" + \token{identifier} ["as" \token{name}]} + \productioncont{ ("," \token{identifier} ["as" \token{name}])* [","] ")"} \productioncont{| "from" \token{module} "import" "*"} + \production{relative_module} + {"."* \token{module} | "."+} \production{module} - {(\token{identifier} ".")* \token{identifier}} + {\token{identifier} ("." \token{identifier})*} + \production{name} + {\token{identifier}} \end{productionlist} Import statements are executed in two steps: (1) find a module, and @@ -775,9 +780,10 @@ \end{itemize} -The features recognized by Python 2.3 are \samp{generators}, -\samp{division} and \samp{nested_scopes}. \samp{generators} and -\samp{nested_scopes} are redundant in 2.3 because they are always +The features recognized by Python 2.5 are \samp{absolute_import}, +\samp{division}, \samp{generators}, \samp{nested_scopes} and +\samp{with_statement}. \samp{generators} and \samp{nested_scopes} +are redundant in Python version 2.3 and above because they are always enabled. A future statement is recognized and treated specially at compile @@ -870,9 +876,36 @@ \section{The \keyword{exec} statement \label{exec}} \stindex{exec} +% XXX Should this explain that you can already treat exec as a function ? +% XXX This would mean that users can start writing code that is p3yk +% XXX compatible now, but by relying on a feature that shouldn't work. +% XXX For example, this works in Python 2.4 and in 2.5, IronPython +% XXX and PyPy (I didn't check if it works in Jython): +% +%>>> source = """ +% ... def f(): +% ... pass +% ... """ +%>>> local_ns = {} +%>>> global_ns = {} +%>>> exec(source, global_ns, local_ns) +% +% Then the grammar should be changed to: +% +%\begin{productionlist} +% \production{exec_stmt} +% {"exec" (\token{statement_style} | token{function_style})} +% \production{statement_style} +% {\token{or_expr} +% ["in" \token{expression} ["," \token{expression}]]} +% \production{function_style} +% {"(" \token{expression} +% ["," \token{expression} ["," \token{expression}]] [","] ")"} +%\end{productionlist} + \begin{productionlist} \production{exec_stmt} - {"exec" \token{expression} + {"exec" \token{or_expr} ["in" \token{expression} ["," \token{expression}]]} \end{productionlist} Index: Doc/ref/ref7.tex =================================================================== --- Doc/ref/ref7.tex (revision 50960) +++ Doc/ref/ref7.tex (working copy) @@ -319,7 +319,7 @@ \begin{productionlist} \production{with_stmt} - {"with" \token{expression} ["as" target] ":" \token{suite}} + {"with" \token{expression} ["as" \token{target}] ":" \token{suite}} \end{productionlist} The execution of the \keyword{with} statement proceeds as follows: @@ -394,19 +394,27 @@ {"@" \token{dotted_name} ["(" [\token{argument_list} [","]] ")"] NEWLINE} \production{dotted_name} {\token{identifier} ("." \token{identifier})*} - \production{parameter_list} - {(\token{defparameter} ",")*} - \productioncont{(~~"*" \token{identifier} [, "**" \token{identifier}]} - \productioncont{ | "**" \token{identifier}} - \productioncont{ | \token{defparameter} [","] )} - \production{defparameter} - {\token{parameter} ["=" \token{expression}]} - \production{sublist} - {\token{parameter} ("," \token{parameter})* [","]} - \production{parameter} - {\token{identifier} | "(" \token{sublist} ")"} \production{funcname} {\token{identifier}} + \production{parameter_list} + {\token{required_parameters} [","]} + \productioncont{| [\token{required_parameters} ","] + \token{default_parameters} [","]} + \productioncont{| [\token{required_parameters} ","] + [\token{default_parameters} ","]} + \productioncont{ "*" \token{identifier}} + \productioncont{| [\token{required_parameters} ","] + [\token{default_parameters} ","]} + \productioncont{ ["*" \token{identifier} ","] "**" \token{identifier}} + \production{required_parameters} + {\token{identifier} | \token{nested_parameters}} + \productioncont{("," \token{identifier} | \token{nested_parameters})*} + \production{nested_parameters} + {"(" \token{identifier} | \token{nested_parameters}} + \productioncont{("," \token{identifier} | \token{nested_parameters})* [","] ")"} + \production{default_parameters} + {\token{identifier} | \token{nested_parameters} "=" \token{expression}} + \productioncont{("," \token{identifier} | \token{nested_parameters} "=" \token{expression})*} \end{productionlist} A function definition is an executable statement. Its execution binds @@ -441,14 +449,13 @@ func = f1(arg)(f2(func)) \end{verbatim} -When one or more top-level parameters have the form \var{parameter} +When one or more top-level parameters have the form \var{identifier} \code{=} \var{expression}, the function is said to have ``default parameter values.'' For a parameter with a default value, the corresponding argument may be omitted from a call, in which case the parameter's default value is substituted. If a parameter has a default value, all following parameters must also have -a default value --- this is a syntactic restriction that is not -expressed by the grammar. +a default value. \indexiii{default}{parameter}{value} \strong{Default parameter values are evaluated when the function

AltStyle によって変換されたページ (->オリジナル) /