Skip to content

Commit b0dadd5

Browse files
committed
Fix yield / yield from precedence
1 parent 1058a50 commit b0dadd5

File tree

2 files changed

+29
-26
lines changed

2 files changed

+29
-26
lines changed

spec/10-expressions.md

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3097,17 +3097,25 @@ $a[$i++] += 50; // $a[1] = 250, $i → 2
30973097
**Syntax**
30983098

30993099
<!-- GRAMMAR
3100+
yield-from-expression:
3101+
'yield from' assignment-expression
3102+
31003103
yield-expression:
3101-
assignment-expression
3102-
'yield' array-element-initializer
3103-
'yield from' expression
3104+
yield-from-expression
3105+
'yield'
3106+
'yield' yield-expression
3107+
'yield' yield-from-expression '=>' yield-expression
31043108
-->
31053109

31063110
<pre>
3111+
<i id="grammar-yield-from-expression">yield-from-expression:</i>
3112+
yield from <i><a href="#grammar-assignment-expression">assignment-expression</a></i>
3113+
31073114
<i id="grammar-yield-expression">yield-expression:</i>
3108-
<i><a href="#grammar-assignment-expression">assignment-expression</a></i>
3109-
yield <i><a href="#grammar-array-element-initializer">array-element-initializer</a></i>
3110-
yield from <i><a href="#grammar-expression">expression</a></i>
3115+
<i><a href="#grammar-yield-from-expression">yield-from-expression</a></i>
3116+
yield
3117+
yield <i><a href="#grammar-yield-expression">yield-expression</a></i>
3118+
yield <i><a href="#grammar-yield-from-expression">yield-from-expression</a></i> =&gt; <i><a href="#grammar-yield-expression">yield-expression</a></i>
31113119
</pre>
31123120

31133121
**Semantics**
@@ -3127,22 +3135,13 @@ The `yield` operator produces the result `NULL` unless the method
31273135
[`Generator->send`](14-classes.md#class-generator) was called to provide a result value. This
31283136
operator has the side effect of generating the next value in the collection.
31293137

3130-
Before being used, an *element-key* must have, or be converted to, type
3131-
`int` or `string`. Keys with `float` or `bool` values, or numeric strings, are
3132-
[converted to `int`](08-conversions.md#converting-to-integer-type). Values of all other key types are [converted to
3133-
`string`](08-conversions.md#converting-to-string-type).
3134-
3135-
If *element-key* is omitted from an *array-element-initializer*, an
3138+
If the key is omitted from an a *yield-expression*, an
31363139
element key of type `int` is associated with the corresponding
3137-
*element-value*. The key associated is one more than the previously
3140+
value. The key associated is one more than the previously
31383141
assigned int key for this collection. However, if this is the first
3139-
element in this collection with an `int` key, key zero is used. If
3140-
*element-key* is provided, it is associated with the corresponding
3141-
*element-value*. The resulting key/value pair is made available by
3142-
`yield`.
3142+
element in this collection with an `int` key, zero is used.
31433143

3144-
If *array-element-initializer* is omitted, default int-key assignment is
3145-
used and each value is `NULL`.
3144+
If the value is also omitted, `NULL` will be used instead.
31463145

31473146
If the generator function definition declares that it returns byRef,
31483147
each value in a key/value pair is yielded byRef.
@@ -3151,15 +3150,15 @@ The following applies only to the `yield from` form:
31513150

31523151
A generator function (referred to as a *delegating generator*) can delegate to another generator function (referred to as a *subgenerator*), a Traversable object, or an array, each of which is designated by *expression*.
31533152

3154-
Each value yielded by *expression* is passed directly to the delegating generator's caller.
3153+
Each value yielded by *assignment-expression* is passed directly to the delegating generator's caller.
31553154

3156-
Each value sent to the delegating generator's `send` method is passed to the subgenerator's `send` method. If *expression* is not a generator function, any sent values are ignored.
3155+
Each value sent to the delegating generator's `send` method is passed to the subgenerator's `send` method. If *assignment-expression* is not a generator function, any sent values are ignored.
31573156

3158-
Exceptions thrown by *expression* are propagated up to the delegating generator.
3157+
Exceptions thrown by *assignment-expression* are propagated up to the delegating generator.
31593158

31603159
Upon traversable completion, `NULL` is returned to the delegating generator if the traversable is not a generator. If the traversable is a generator, its return value is sent to the delegating generator as the value of the `yield from` *expression*.
31613160

3162-
An exception of type `Error` is thrown if *expression* evaluates to a generator that previously terminated with an uncaught exception, or it evaluates to something that is neither Traversable nor an array.
3161+
An exception of type `Error` is thrown if *assignment-expression* evaluates to a generator that previously terminated with an uncaught exception, or it evaluates to something that is neither Traversable nor an array.
31633162

31643163
**Examples**
31653164

spec/19-grammar.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -672,10 +672,14 @@ The grammar notation is described in [Grammars section](09-lexical-structure.md#
672672
<i id="grammar-compound-assignment-operator">compound-assignment-operator: one of</i>
673673
**= *= /= %= += -= .= &lt;&lt;= &gt;&gt;= &amp;= ^= |=
674674

675+
<i id="grammar-yield-from-expression">yield-from-expression:</i>
676+
yield from <i><a href="#grammar-assignment-expression">assignment-expression</a></i>
677+
675678
<i id="grammar-yield-expression">yield-expression:</i>
676-
<i><a href="#grammar-assignment-expression">assignment-expression</a></i>
677-
yield <i><a href="#grammar-array-element-initializer">array-element-initializer</a></i>
678-
yield from <i><a href="#grammar-expression">expression</a></i>
679+
<i><a href="#grammar-yield-from-expression">yield-from-expression</a></i>
680+
yield
681+
yield <i><a href="#grammar-yield-expression">yield-expression</a></i>
682+
yield <i><a href="#grammar-yield-from-expression">yield-from-expression</a></i> =&gt; <i><a href="#grammar-yield-expression">yield-expression</a></i>
679683

680684
<i id="grammar-logical-AND-expression-2">logical-AND-expression-2:</i>
681685
<i><a href="#grammar-yield-expression">yield-expression</a></i>

0 commit comments

Comments
 (0)