Index: Doc/ref/ref1.tex =================================================================== --- Doc/ref/ref1.tex (revision 46030) +++ 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/ref2.tex =================================================================== --- Doc/ref/ref2.tex (revision 46030) +++ Doc/ref/ref2.tex (working copy) @@ -284,7 +284,7 @@ \index{name} \begin{productionlist} - \production{identifier} + \production{NAME} {(\token{letter}|"_") (\token{letter} | \token{digit} | "_")*} \production{letter} {\token{lowercase} | \token{uppercase}} Index: Doc/ref/ref5.tex =================================================================== --- Doc/ref/ref5.tex (revision 46030) +++ Doc/ref/ref5.tex (working copy) @@ -52,7 +52,7 @@ \begin{productionlist} \production{atom} - {\token{identifier} | \token{literal} | \token{enclosure}} + {\token{NAME} | \token{literal} | \token{enclosure}} \production{enclosure} {\token{parenth_form} | \token{list_display}} \productioncont{| \token{generator_expression} | \token{dict_display}} @@ -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 @@ -124,7 +125,7 @@ \begin{productionlist} \production{parenth_form} - {"(" [\token{expression_list}] ")"} + {"(" [\token{testlist}] ")"} \end{productionlist} A parenthesized expression list yields whatever that expression list @@ -154,22 +155,21 @@ square brackets: \begin{productionlist} - \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} )* [","] )} + {\token{test} (\token{list_for} | (',' \token{test})* [','] )} + \production{list_for} + {"for" \token{target_list} "in" \token{testlist_safe} + [\token{list_iter}]} + \production{testlist_safe} + {\token{old_test} [("," \token{old_test})+ [","]]} + \production{old_test} + {\token{or_test} | \token{lambda_form}} \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}]} + {"if" \token{old_test} [\token{list_iter}]} \end{productionlist} A list display yields a new list object. Its contents are specified @@ -200,14 +200,14 @@ \begin{productionlist} \production{generator_expression} - {"(" \token{test} \token{genexpr_for} ")"} - \production{genexpr_for} - {"for" \token{expression_list} "in" \token{test} - [\token{genexpr_iter}]} - \production{genexpr_iter} - {\token{genexpr_for} | \token{genexpr_if}} - \production{genexpr_if} - {"if" \token{test} [\token{genexpr_iter}]} + {"(" \token{test} \token{gen_for} ")"} + \production{gen_for} + {"for" \token{target_list} "in" \token{or_test} + [\token{gen_iter}]} + \production{gen_iter} + {\token{gen_for} | \token{gen_if}} + \production{gen_if} + {"if" \token{old_test} [\token{gen_iter}]} \end{productionlist} A generator expression yields a new generator object. @@ -246,11 +246,11 @@ \begin{productionlist} \production{dict_display} - {"\{" [\token{key_datum_list}] "\}"} - \production{key_datum_list} + {"\{" [\token{dictmaker}] "\}"} + \production{dictmaker} {\token{key_datum} ("," \token{key_datum})* [","]} \production{key_datum} - {\token{expression} ":" \token{expression}} + {\token{test} ":" \token{test}} \end{productionlist} A dictionary display yields a new dictionary object. @@ -279,7 +279,7 @@ \begin{productionlist} \production{string_conversion} - {"`" \token{expression_list} "`"} + {"`" \token{testlist} "`"} \end{productionlist} A string conversion evaluates the contained expression list and @@ -331,7 +331,7 @@ \begin{productionlist} \production{attributeref} - {\token{primary} "." \token{identifier}} + {\token{primary} "." \token{NAME}} \end{productionlist} The primary must evaluate to an object of a type that supports @@ -361,7 +361,7 @@ \begin{productionlist} \production{subscription} - {\token{primary} "[" \token{expression_list} "]"} + {\token{primary} "[" \token{testlist} "]"} \end{productionlist} The primary must evaluate to an object of a sequence or mapping type. @@ -407,7 +407,7 @@ \production{slice_list} {\token{slice_item} ("," \token{slice_item})* [","]} \production{slice_item} - {\token{expression} | \token{proper_slice} | \token{ellipsis}} + {\token{test} | \token{proper_slice} | \token{ellipsis}} \production{proper_slice} {\token{short_slice} | \token{long_slice}} \production{short_slice} @@ -415,11 +415,11 @@ \production{long_slice} {\token{short_slice} ":" [\token{stride}]} \production{lower_bound} - {\token{expression}} + {\token{test}} \production{upper_bound} - {\token{expression}} + {\token{test}} \production{stride} - {\token{expression}} + {\token{test}} \production{ellipsis} {"..."} \end{productionlist} @@ -473,23 +473,24 @@ \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{test} \token{gen_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{test}} + \productioncont{| [\token{positional_arguments} ","] + [\token{keyword_arguments} ","]} + \productioncont{ ["*" \token{test} ","] "**" \token{test}} \production{positional_arguments} - {\token{expression} ("," \token{expression})*} + {\token{test} ("," \token{test})*} \production{keyword_arguments} {\token{keyword_item} ("," \token{keyword_item})*} \production{keyword_item} - {\token{identifier} "=" \token{expression}} + {\token{NAME} "=" \token{test}} \end{productionlist} A trailing comma may be present after the positional and keyword @@ -643,7 +644,7 @@ \begin{productionlist} \production{power} - {\token{primary} ["**" \token{u_expr}]} + {\token{primary} ["**" \token{factor}]} \end{productionlist} Thus, in an unparenthesized sequence of power and unary operators, the @@ -677,9 +678,9 @@ All unary arithmetic (and bit-wise) operations have the same priority: \begin{productionlist} - \production{u_expr} - {\token{power} | "-" \token{u_expr} - | "+" \token{u_expr} | "{\~}" \token{u_expr}} + \production{factor} + {\token{power} | "-" \token{factor} + | "+" \token{factor} | "{\~}" \token{factor}} \end{productionlist} The unary \code{-} (minus) operator yields the negation of its @@ -712,14 +713,14 @@ operators: \begin{productionlist} - \production{m_expr} - {\token{u_expr} | \token{m_expr} "*" \token{u_expr} - | \token{m_expr} "//" \token{u_expr} - | \token{m_expr} "/" \token{u_expr}} - \productioncont{| \token{m_expr} "\%" \token{u_expr}} - \production{a_expr} - {\token{m_expr} | \token{a_expr} "+" \token{m_expr} - | \token{a_expr} "-" \token{m_expr}} + \production{term} + {\token{factor} | \token{term} "*" \token{factor} + | \token{term} "//" \token{factor} + | \token{term} "/" \token{factor}} + \productioncont{| \token{term} "\%" \token{factor}} + \production{arith_expr} + {\token{term} | \token{arith_expr} "+" \token{term} + | \token{arith_expr} "-" \token{term}} \end{productionlist} The \code{*} (multiplication) operator yields the product of its @@ -808,10 +809,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{arith_expr} + | \token{shift_expr} ( "<<" | ">>" ) \token{arith_expr}} \end{productionlist} These operators accept plain or long integers as arguments. The @@ -839,8 +839,8 @@ {\token{shift_expr} | \token{and_expr} "\&" \token{shift_expr}} \production{xor_expr} {\token{and_expr} | \token{xor_expr} "\textasciicircum" \token{and_expr}} - \production{or_expr} - {\token{xor_expr} | \token{or_expr} "|" \token{xor_expr}} + \production{expr} + {\token{xor_expr} | \token{expr} "|" \token{xor_expr}} \end{productionlist} The \code{\&} operator yields the bitwise AND of its arguments, which @@ -872,8 +872,8 @@ \begin{productionlist} \production{comparison} - {\token{or_expr} ( \token{comp_operator} \token{or_expr} )*} - \production{comp_operator} + {\token{expr} ( \token{comp_op} \token{expr} )*} + \production{comp_op} {"<" | ">" | "==" | ">=" | "<=" | "" | "!="} \productioncont{| "is" ["not"] | ["not"] "in"} \end{productionlist} @@ -1010,14 +1010,15 @@ \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}} + \production{test} + {\token{or_test} ["if" \token{or_test} "else" \token{test}] + | \token{lambda_form}} \production{or_test} {\token{and_test} | \token{or_test} "or" \token{and_test}} \production{and_test} @@ -1068,7 +1069,7 @@ \begin{productionlist} \production{lambda_form} - {"lambda" [\token{parameter_list}]: \token{expression}} + {"lambda" [\token{parameter_list}]: \token{test}} \end{productionlist} Lambda forms (lambda expressions) have the same syntactic position as @@ -1090,8 +1091,8 @@ \indexii{expression}{list} \begin{productionlist} - \production{expression_list} - {\token{expression} ( "," \token{expression} )* [","]} + \production{testlist} + {\token{test} ( "," \token{test} )* [","]} \end{productionlist} An expression list containing at least one comma yields a Index: Doc/ref/ref6.tex =================================================================== --- Doc/ref/ref6.tex (revision 46030) +++ Doc/ref/ref6.tex (working copy) @@ -35,7 +35,7 @@ \begin{productionlist} \production{expression_stmt} - {\token{expression_list}} + {\token{testlist}} \end{productionlist} An expression statement evaluates the expression list (which may be a @@ -63,7 +63,7 @@ \begin{productionlist} \production{assert_stmt} - {"assert" \token{expression} ["," \token{expression}]} + {"assert" \token{test} ["," \token{test}]} \end{productionlist} The simple form, \samp{assert expression}, is equivalent to @@ -108,11 +108,11 @@ \begin{productionlist} \production{assignment_stmt} - {(\token{target_list} "=")+ \token{expression_list}} + {(\token{target_list} "=")+ \token{testlist}} \production{target_list} {\token{target} ("," \token{target})* [","]} \production{target} - {\token{identifier}} + {\token{NAME}} \productioncont{| "(" \token{target_list} ")"} \productioncont{| "[" \token{target_list} "]"} \productioncont{| \token{attributeref}} @@ -273,11 +273,10 @@ \begin{productionlist} \production{augmented_assignment_stmt} - {\token{target} \token{augop} \token{expression_list}} + {\token{target} \token{augop} \token{testlist}} \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{","}}} - \productioncont{| ">>" \token{expression} - \optional{("," \token{expression})+ \optional{","}} )} + {"print" ([\token{test} ("," \token{test})* [","]} + \productioncont{| ">>" \token{test} + [("," \token{test})+ [","])} \end{productionlist} \keyword{print} evaluates each expression in turn and writes the @@ -430,7 +429,7 @@ \begin{productionlist} \production{return_stmt} - {"return" [\token{expression_list}]} + {"return" [\token{testlist}]} \end{productionlist} \keyword{return} may only occur syntactically nested in a function @@ -460,7 +459,7 @@ \begin{productionlist} \production{yield_stmt} - {"yield" \token{expression_list}} + {"yield" [\token{testlist}]} \end{productionlist} \index{generator!function} @@ -524,8 +523,8 @@ \begin{productionlist} \production{raise_stmt} - {"raise" [\token{expression} ["," \token{expression} - ["," \token{expression}]]]} + {"raise" [\token{test} ["," \token{test} + ["," \token{test}]]]} \end{productionlist} If no expressions are present, \keyword{raise} re-raises the last @@ -626,19 +625,23 @@ \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} - ["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{| "from" \token{module} "import" "*"} - \production{module} - {(\token{identifier} ".")* \token{identifier}} + {"import" \token{dotted_name} ["as" \token{NAME}] + ("," \token{NAME} ["as" \token{NAME}])*} + \productioncont{| "from" \token{relative_module} "import" \token{NAME} + ["as" \token{NAME}]} + \productioncont{ ("," \token{NAME} ["as" \token{NAME}])*} + \productioncont{| "from" \token{relative_module} "import" "(" + \token{NAME} ["as" \token{NAME}]} + \productioncont{ ("," \token{NAME} ["as" \token{NAME}])* [","] ")"} + \productioncont{| "from" \token{dotted_name} "import" "*"} + \production{relative_module} + {"."* \token{dotted_name} | "."+} + \production{dotted_name} + {\token{NAME} ("." \token{NAME})*} \end{productionlist} Import statements are executed in two steps: (1) find a module, and @@ -757,10 +760,14 @@ \begin{productionlist}[*] \production{future_statement} - {"from" "__future__" "import" feature ["as" name] ("," feature ["as" name])*} - \productioncont{| "from" "__future__" "import" "(" feature ["as" name] ("," feature ["as" name])* [","] ")"} - \production{feature}{identifier} - \production{name}{identifier} + {"from" "__future__" "import" + \token{feature} ["as" \token{NAME}]} + \productioncont{ ("," \token{feature} ["as" \token{NAME}])*} + \productioncont{| "from" "__future__" "import" + "(" \token{feature} ["as" \token{NAME}]} + \productioncont{ ("," \token{feature} ["as" \token{NAME}])* [","] ")"} + \production{feature} + {\token{NAME}} \end{productionlist} A future statement must appear near the top of the module. The only @@ -775,9 +782,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 @@ -829,7 +837,7 @@ \begin{productionlist} \production{global_stmt} - {"global" \token{identifier} ("," \token{identifier})*} + {"global" \token{NAME} ("," \token{NAME})*} \end{productionlist} The \keyword{global} statement is a declaration which holds for the @@ -869,10 +877,37 @@ \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{expr} +% ["in" \token{test} ["," \token{test}]]} +% \production{function_style} +% {"(" \token{test} +% ["," \token{test} ["," \token{test}]] [","] ")"} +%\end{productionlist} + \begin{productionlist} \production{exec_stmt} - {"exec" \token{expression} - ["in" \token{expression} ["," \token{expression}]]} + {"exec" \token{expr} + ["in" \token{test} ["," \token{test}]]} \end{productionlist} This statement supports dynamic execution of Python code. The first Index: Doc/ref/ref7.tex =================================================================== --- Doc/ref/ref7.tex (revision 46030) +++ Doc/ref/ref7.tex (working copy) @@ -78,8 +78,8 @@ \begin{productionlist} \production{if_stmt} - {"if" \token{expression} ":" \token{suite}} - \productioncont{( "elif" \token{expression} ":" \token{suite} )*} + {"if" \token{test} ":" \token{suite}} + \productioncont{( "elif" \token{test} ":" \token{suite} )*} \productioncont{["else" ":" \token{suite}]} \end{productionlist} @@ -102,7 +102,7 @@ \begin{productionlist} \production{while_stmt} - {"while" \token{expression} ":" \token{suite}} + {"while" \token{test} ":" \token{suite}} \productioncont{["else" ":" \token{suite}]} \end{productionlist} @@ -130,7 +130,7 @@ \begin{productionlist} \production{for_stmt} - {"for" \token{target_list} "in" \token{expression_list} + {"for" \token{target_list} "in" \token{testlist} ":" \token{suite}} \productioncont{["else" ":" \token{suite}]} \end{productionlist} @@ -199,7 +199,7 @@ \production{try_stmt} {try1_stmt | try2_stmt} \production{try1_stmt} {"try" ":" \token{suite}} - \productioncont{("except" [\token{expression} + \productioncont{("except" [\token{test} ["," \token{target}]] ":" \token{suite})+} \productioncont{["else" ":" \token{suite}]} \productioncont{["finally" ":" \token{suite}]} @@ -319,7 +319,7 @@ \begin{productionlist} \production{with_stmt} - {"with" \token{expression} ["as" target] ":" \token{suite}} + {"with" \token{test} ["as" \token{target}] ":" \token{suite}} \end{productionlist} The execution of the \keyword{with} statement proceeds as follows: @@ -386,27 +386,31 @@ \begin{productionlist} \production{funcdef} - {[\token{decorators}] "def" \token{funcname} "(" [\token{parameter_list}] ")" + {[\token{decorators}] "def" \token{NAME} "(" [\token{parameter_list}] ")" ":" \token{suite}} \production{decorators} {\token{decorator}+} \production{decorator} {"@" \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}} + {\token{required_parameters} [","]} + \productioncont{| [\token{required_parameters} ","] + \token{default_parameters} [","]} + \productioncont{| [\token{required_parameters} ","] + [\token{default_parameters} ","]} + \productioncont{ "*" \token{NAME}} + \productioncont{| [\token{required_parameters} ","] + [\token{default_parameters} ","]} + \productioncont{ ["*" \token{NAME} ","] "**" \token{NAME}} + \production{required_parameters} + {\token{NAME} | \token{nested_parameters}} + \productioncont{("," \token{NAME} | \token{nested_parameters})*} + \production{nested_parameters} + {"(" \token{NAME} | \token{nested_parameters}} + \productioncont{("," \token{NAME} | \token{nested_parameters})* [","] ")"} + \production{default_parameters} + {\token{NAME} "=" \token{test}} + \productioncont{("," \token{NAME} "=" \token{test})*} \end{productionlist} A function definition is an executable statement. Its execution binds @@ -441,14 +445,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 @@ -507,12 +510,8 @@ \begin{productionlist} \production{classdef} - {"class" \token{classname} [\token{inheritance}] ":" + {"class" \token{NAME} ["(" [\token{testlist}] ")"] ":" \token{suite}} - \production{inheritance} - {"(" [\token{expression_list}] ")"} - \production{classname} - {\token{identifier}} \end{productionlist} A class definition is an executable statement. It first evaluates the

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