diff --git a/spec.md b/spec.md index b109b1b..89fd94a 100644 --- a/spec.md +++ b/spec.md @@ -1575,13 +1575,13 @@ suffixes, to form a _primary_ expression. In some places in the Starlark grammar where an expression is expected, it is legal to provide a comma-separated list of expressions denoting a tuple. -The grammar uses `Expression` where a multiple-component expression is allowed, -and `Test` where it accepts an expression of only a single component. +The grammar uses `Expressions` where a multiple-component expression is allowed, +and `Expression` where it accepts an expression of only a single component. ```text -Expression = Test {',' Test} . +Expressions = Expression {',' Expression} . -Test = IfExpr | PrimaryExpr | UnaryExpr | BinaryExpr | LambdaExpr . +Expression = IfExpr | PrimaryExpr | UnaryExpr | BinaryExpr | LambdaExpr . PrimaryExpr = Operand | PrimaryExpr DotSuffix @@ -1593,12 +1593,12 @@ Operand = identifier | int | float | string | ListExpr | ListComp | DictExpr | DictComp - | '(' [Expression] [,] ')' + | '(' [Expressions] [,] ')' . DotSuffix = '.' identifier . CallSuffix = '(' [Arguments [',']] ')' . -SliceSuffix = '[' [Expression] [':' Test [':' Test]] ']' . +SliceSuffix = '[' [Expressions] [':' Expression [':' Expression]] ']' . ``` ### Identifiers @@ -1626,7 +1626,7 @@ See [Literals](#lexical elements) for details. ### Parenthesized expressions ```text -Operand = '(' [Expression] ')' +Operand = '(' [Expressions] ')' ``` A single expression enclosed in parentheses yields the result of that expression. @@ -1679,7 +1679,7 @@ An optional comma may follow the final pair. ```text DictExpr = '{' [Entries [',']] '}' . Entries = Entry {',' Entry} . -Entry = Test ':' Test . +Entry = Expression ':' Expression . ``` Examples: @@ -1704,7 +1704,7 @@ enclosed in square brackets, and it yields a new list object. An optional comma may follow the last element expression. ```text -ListExpr = '[' [Expression [',']] ']' . +ListExpr = '[' [Expressions [',']] ']' . ``` Element expressions are evaluated in left-to-right order. @@ -1723,10 +1723,10 @@ There are four unary operators, all appearing before their operand: `+`, `-`, `~`, and `not`. ```text -UnaryExpr = '+' Test - | '-' Test - | '~' Test - | 'not' Test +UnaryExpr = '+' Expression + | '-' Expression + | '~' Expression + | 'not' Expression . ``` @@ -1793,7 +1793,7 @@ so the parser will not accept `0 <= i < n`. All other binary operators of equal precedence associate to the left. ```text -BinaryExpr = Test {Binop Test} . +BinaryExpr = Expression {Binop Expression} . Binop = 'or' | 'and' @@ -2089,7 +2089,7 @@ If it's true, it evaluates `a` and yields its value; otherwise it yields the value of `b`. ```text -IfExpr = Test 'if' Test 'else' Test . +IfExpr = Expression 'if' Expression 'else' Expression . ``` Example: @@ -2133,11 +2133,11 @@ A sequence of `for` and `if` clauses acts like a nested sequence of `for` and `if` statements. ```text -ListComp = '[' Test {CompClause} ']'. +ListComp = '[' Expression {CompClause} ']'. DictComp = '{' Entry {CompClause} '}' . -CompClause = 'for' LoopVariables 'in' Test - | 'if' Test . +CompClause = 'for' LoopVariables 'in' Expression + | 'if' Expression . LoopVariables = PrimaryExpr {',' PrimaryExpr} . ``` @@ -2190,7 +2190,7 @@ print(x) # 1 CallSuffix = '(' [Arguments [',']] ')' . Arguments = Argument {',' Argument} . -Argument = Test | identifier '=' Test | '*' Test | '**' Test . +Argument = Expression | identifier '=' Expression | '*' Expression | '**' Expression . ``` A value `f` of type `function` may be called using the expression `f(...)`. @@ -2257,7 +2257,7 @@ value in the range -`n` ≤ `i` < `n`, where `n` is `len(a)`; any other index results in an error. ```text -SliceSuffix = '[' [Expression] [':' Test [':' Test]] ']' . +SliceSuffix = '[' [Expressions] [':' Expression [':' Expression]] ']' . ``` A valid negative index `i` behaves like the non-negative index `n+i`, @@ -2297,7 +2297,7 @@ A slice expression `a[start:stop:stride]` yields a new value containing a subsequence of `a`, which must be a string, tuple, or list. ```text -SliceSuffix = '[' [Expression] [':' Test [':' Test]] ']' . +SliceSuffix = '[' [Expressions] [':' Expression [':' Expression]] ']' . ``` Each of the `start`, `stop`, and `stride` operands is optional; @@ -2351,7 +2351,7 @@ the creation of a new list and copying of the necessary elements. A `lambda` expression yields a new function value. ```grammar {.good} -LambdaExpr = 'lambda' [Parameters] ':' Test . +LambdaExpr = 'lambda' [Parameters] ':' Expression . ``` Syntactically, a lambda expression consists of the keyword `lambda`, @@ -2430,7 +2430,7 @@ expression on the right-hand side then assigns its value (or values) to the variable (or variables) on the left-hand side. ```text -AssignStmt = Expression '=' Expression . +AssignStmt = Expressions '=' Expressions . ``` The expression on the left-hand side is called a _target_. The @@ -2473,7 +2473,7 @@ variable `lhs` by applying a binary arithmetic operator `op` (one of previous value of `lhs` and the value of `rhs`. ```text -AssignStmt = Expression ('=' | '+=' | '-=' | '*=' | '/=' | '//=' | '%=' | '&=' | '|=' | '^=' | '<<=' | '>>=') Expression . +AssignStmt = Expressions ('=' | '+=' | '-=' | '*=' | '/=' | '//=' | '%=' | '&=' | '|=' | '^=' | '<<=' | '>>=') Expressions . ``` The left-hand side must be a simple target: @@ -2581,7 +2581,7 @@ A `return` statement ends the execution of a function and returns a value to the caller of the function. ```text -ReturnStmt = 'return' [Expression] . +ReturnStmt = 'return' [Expressions] . ``` A return statement may have zero, one, or more @@ -2601,7 +2601,7 @@ return 1, 2 # returns (1, 2) An expression statement evaluates an expression and discards its result. ```text -ExprStmt = Expression . +ExprStmt = Expressions . ``` Any expression may be used as a statement, but an expression statement is @@ -2618,7 +2618,7 @@ the truth value of the condition is `True`, executes a list of statements. ```text -IfStmt = 'if' Test ':' Suite {'elif' Test ':' Suite} ['else' ':' Suite] . +IfStmt = 'if' Expression ':' Suite {'elif' Expression ':' Suite} ['else' ':' Suite] . ``` Example: @@ -2665,7 +2665,7 @@ the successive element values to one or more variables and executes a list of statements, the _loop body_. ```text -ForStmt = 'for' LoopVariables 'in' Expression ':' Suite . +ForStmt = 'for' LoopVariables 'in' Expressions ':' Suite . ``` Example: @@ -3896,11 +3896,11 @@ DefStmt = 'def' identifier '(' [Parameters [',']] ')' ':' Suite . Parameters = Parameter {',' Parameter}. -Parameter = identifier | identifier '=' Test | '*' identifier | '**' identifier . +Parameter = identifier | identifier '=' Expression | '*' identifier | '**' identifier . -IfStmt = 'if' Test ':' Suite {'elif' Test ':' Suite} ['else' ':' Suite] . +IfStmt = 'if' Expression ':' Suite {'elif' Expression ':' Suite} ['else' ':' Suite] . -ForStmt = 'for' LoopVariables 'in' Expression ':' Suite . +ForStmt = 'for' LoopVariables 'in' Expressions ':' Suite . Suite = [newline indent {Statement} outdent] | SimpleStmt . @@ -3914,18 +3914,18 @@ SmallStmt = ReturnStmt | LoadStmt . -ReturnStmt = 'return' [Expression] . +ReturnStmt = 'return' [Expressions] . BreakStmt = 'break' . ContinueStmt = 'continue' . PassStmt = 'pass' . -AssignStmt = Expression ('=' | '+=' | '-=' | '*=' | '/=' | '//=' | '%=' | '&=' | '|=' | '^=' | '<<=' | '>>=') Expression . -ExprStmt = Expression . +AssignStmt = Expressions ('=' | '+=' | '-=' | '*=' | '/=' | '//=' | '%=' | '&=' | '|=' | '^=' | '<<=' | '>>=') Expressions . +ExprStmt = Expressions . LoadStmt = 'load' '(' string {',' [identifier '='] string} [','] ')' . -Test = IfExpr | PrimaryExpr | UnaryExpr | BinaryExpr | LambdaExpr . +Expression = IfExpr | PrimaryExpr | UnaryExpr | BinaryExpr | LambdaExpr . -IfExpr = Test 'if' Test 'else' Test . +IfExpr = Expression 'if' Expression 'else' Expression . PrimaryExpr = Operand | PrimaryExpr DotSuffix @@ -3937,33 +3937,33 @@ Operand = identifier | int | float | string | ListExpr | ListComp | DictExpr | DictComp - | '(' [Expression [',']] ')' + | '(' [Expressions [',']] ')' . DotSuffix = '.' identifier . -SliceSuffix = '[' [Expression] [':' Test [':' Test]] ']' . +SliceSuffix = '[' [Expressions] [':' Expression [':' Expression]] ']' . CallSuffix = '(' [Arguments [',']] ')' . Arguments = Argument {',' Argument} . -Argument = Test | identifier '=' Test | '*' Test | '**' Test . +Argument = Expression | identifier '=' Expression | '*' Expression | '**' Expression . -ListExpr = '[' [Expression [',']] ']' . -ListComp = '[' Test {CompClause} ']'. +ListExpr = '[' [Expressions [',']] ']' . +ListComp = '[' Expression {CompClause} ']'. DictExpr = '{' [Entries [',']] '}' . DictComp = '{' Entry {CompClause} '}' . Entries = Entry {',' Entry} . -Entry = Test ':' Test . +Entry = Expression ':' Expression . -CompClause = 'for' LoopVariables 'in' Test | 'if' Test . +CompClause = 'for' LoopVariables 'in' Expression | 'if' Expression . -UnaryExpr = '+' Test - | '-' Test - | '~' Test - | 'not' Test +UnaryExpr = '+' Expression + | '-' Expression + | '~' Expression + | 'not' Expression . -BinaryExpr = Test {Binop Test} . +BinaryExpr = Expression {Binop Expression} . Binop = 'or' | 'and' @@ -3976,9 +3976,9 @@ Binop = 'or' | '*' | '%' | '/' | '//' . -LambdaExpr = 'lambda' [Parameters] ':' Test . +LambdaExpr = 'lambda' [Parameters] ':' Expression . -Expression = Test {',' Test} . +Expressions = Expression {',' Expression} . # NOTE: trailing comma permitted only when within [...] or (...). LoopVariables = PrimaryExpr {',' PrimaryExpr} .