2015-04-26 11:46:23 +02:00
|
|
|
Generators (yield expression)
|
2012-09-07 19:24:44 +02:00
|
|
|
-----
|
|
|
|
<?php
|
|
|
|
|
|
|
|
function gen() {
|
|
|
|
// statements
|
|
|
|
yield;
|
|
|
|
yield $value;
|
|
|
|
yield $key => $value;
|
|
|
|
|
|
|
|
// expressions
|
|
|
|
$data = yield;
|
|
|
|
$data = (yield $value);
|
|
|
|
$data = (yield $key => $value);
|
|
|
|
|
|
|
|
// yield in language constructs with their own parentheses
|
|
|
|
if (yield $foo); elseif (yield $foo);
|
|
|
|
if (yield $foo): elseif (yield $foo): endif;
|
|
|
|
while (yield $foo);
|
|
|
|
do {} while (yield $foo);
|
|
|
|
switch (yield $foo) {}
|
|
|
|
die(yield $foo);
|
|
|
|
|
|
|
|
// yield in function calls
|
|
|
|
func(yield $foo);
|
|
|
|
$foo->func(yield $foo);
|
|
|
|
new Foo(yield $foo);
|
2015-04-26 11:46:23 +02:00
|
|
|
|
|
|
|
yield from $foo;
|
|
|
|
yield from $foo and yield from $bar;
|
|
|
|
yield from $foo + $bar;
|
2012-09-07 19:24:44 +02:00
|
|
|
}
|
|
|
|
-----
|
|
|
|
array(
|
|
|
|
0: Stmt_Function(
|
|
|
|
byRef: false
|
2014-03-22 14:49:56 +01:00
|
|
|
name: gen
|
2012-09-07 19:24:44 +02:00
|
|
|
params: array(
|
|
|
|
)
|
2015-03-12 13:17:31 +01:00
|
|
|
returnType: null
|
2012-09-07 19:24:44 +02:00
|
|
|
stmts: array(
|
|
|
|
0: Expr_Yield(
|
|
|
|
key: null
|
|
|
|
value: null
|
2016-03-09 18:57:16 +01:00
|
|
|
comments: array(
|
|
|
|
0: // statements
|
|
|
|
)
|
2012-09-07 19:24:44 +02:00
|
|
|
)
|
|
|
|
1: Expr_Yield(
|
|
|
|
key: null
|
|
|
|
value: Expr_Variable(
|
|
|
|
name: value
|
|
|
|
)
|
|
|
|
)
|
|
|
|
2: Expr_Yield(
|
|
|
|
key: Expr_Variable(
|
2012-09-07 23:21:23 +02:00
|
|
|
name: key
|
2012-09-07 19:24:44 +02:00
|
|
|
)
|
|
|
|
value: Expr_Variable(
|
2012-09-07 23:21:23 +02:00
|
|
|
name: value
|
2012-09-07 19:24:44 +02:00
|
|
|
)
|
|
|
|
)
|
|
|
|
3: Expr_Assign(
|
|
|
|
var: Expr_Variable(
|
|
|
|
name: data
|
2016-03-09 18:57:16 +01:00
|
|
|
comments: array(
|
|
|
|
0: // expressions
|
|
|
|
)
|
2012-09-07 19:24:44 +02:00
|
|
|
)
|
|
|
|
expr: Expr_Yield(
|
|
|
|
key: null
|
|
|
|
value: null
|
|
|
|
)
|
2016-03-09 18:57:16 +01:00
|
|
|
comments: array(
|
|
|
|
0: // expressions
|
|
|
|
)
|
2012-09-07 19:24:44 +02:00
|
|
|
)
|
|
|
|
4: Expr_Assign(
|
|
|
|
var: Expr_Variable(
|
|
|
|
name: data
|
|
|
|
)
|
|
|
|
expr: Expr_Yield(
|
|
|
|
key: null
|
|
|
|
value: Expr_Variable(
|
|
|
|
name: value
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
5: Expr_Assign(
|
|
|
|
var: Expr_Variable(
|
|
|
|
name: data
|
|
|
|
)
|
|
|
|
expr: Expr_Yield(
|
|
|
|
key: Expr_Variable(
|
2012-09-07 23:21:23 +02:00
|
|
|
name: key
|
2012-09-07 19:24:44 +02:00
|
|
|
)
|
|
|
|
value: Expr_Variable(
|
2012-09-07 23:21:23 +02:00
|
|
|
name: value
|
2012-09-07 19:24:44 +02:00
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
6: Stmt_If(
|
2014-03-22 14:49:56 +01:00
|
|
|
cond: Expr_Yield(
|
|
|
|
key: null
|
|
|
|
value: Expr_Variable(
|
|
|
|
name: foo
|
|
|
|
)
|
|
|
|
)
|
2012-09-07 19:24:44 +02:00
|
|
|
stmts: array(
|
|
|
|
)
|
|
|
|
elseifs: array(
|
|
|
|
0: Stmt_ElseIf(
|
|
|
|
cond: Expr_Yield(
|
|
|
|
key: null
|
|
|
|
value: Expr_Variable(
|
|
|
|
name: foo
|
|
|
|
)
|
|
|
|
)
|
|
|
|
stmts: array(
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
else: null
|
2016-03-09 18:57:16 +01:00
|
|
|
comments: array(
|
|
|
|
0: // yield in language constructs with their own parentheses
|
|
|
|
)
|
2014-03-22 14:49:56 +01:00
|
|
|
)
|
|
|
|
7: Stmt_If(
|
2012-09-07 19:24:44 +02:00
|
|
|
cond: Expr_Yield(
|
|
|
|
key: null
|
|
|
|
value: Expr_Variable(
|
|
|
|
name: foo
|
|
|
|
)
|
|
|
|
)
|
|
|
|
stmts: array(
|
|
|
|
)
|
|
|
|
elseifs: array(
|
|
|
|
0: Stmt_ElseIf(
|
|
|
|
cond: Expr_Yield(
|
|
|
|
key: null
|
|
|
|
value: Expr_Variable(
|
|
|
|
name: foo
|
|
|
|
)
|
|
|
|
)
|
|
|
|
stmts: array(
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
else: null
|
|
|
|
)
|
|
|
|
8: Stmt_While(
|
|
|
|
cond: Expr_Yield(
|
|
|
|
key: null
|
|
|
|
value: Expr_Variable(
|
|
|
|
name: foo
|
|
|
|
)
|
|
|
|
)
|
|
|
|
stmts: array(
|
|
|
|
)
|
|
|
|
)
|
|
|
|
9: Stmt_Do(
|
|
|
|
cond: Expr_Yield(
|
|
|
|
key: null
|
|
|
|
value: Expr_Variable(
|
|
|
|
name: foo
|
|
|
|
)
|
|
|
|
)
|
|
|
|
stmts: array(
|
|
|
|
)
|
|
|
|
)
|
|
|
|
10: Stmt_Switch(
|
|
|
|
cond: Expr_Yield(
|
|
|
|
key: null
|
|
|
|
value: Expr_Variable(
|
|
|
|
name: foo
|
|
|
|
)
|
|
|
|
)
|
|
|
|
cases: array(
|
|
|
|
)
|
|
|
|
)
|
|
|
|
11: Expr_Exit(
|
|
|
|
expr: Expr_Yield(
|
|
|
|
key: null
|
|
|
|
value: Expr_Variable(
|
|
|
|
name: foo
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
12: Expr_FuncCall(
|
|
|
|
name: Name(
|
|
|
|
parts: array(
|
|
|
|
0: func
|
|
|
|
)
|
2016-03-09 18:57:16 +01:00
|
|
|
comments: array(
|
|
|
|
0: // yield in function calls
|
|
|
|
)
|
2012-09-07 19:24:44 +02:00
|
|
|
)
|
|
|
|
args: array(
|
|
|
|
0: Arg(
|
|
|
|
value: Expr_Yield(
|
|
|
|
key: null
|
|
|
|
value: Expr_Variable(
|
|
|
|
name: foo
|
|
|
|
)
|
|
|
|
)
|
|
|
|
byRef: false
|
2014-03-26 18:42:46 +01:00
|
|
|
unpack: false
|
2012-09-07 19:24:44 +02:00
|
|
|
)
|
|
|
|
)
|
2016-03-09 18:57:16 +01:00
|
|
|
comments: array(
|
|
|
|
0: // yield in function calls
|
|
|
|
)
|
2012-09-07 19:24:44 +02:00
|
|
|
)
|
|
|
|
13: Expr_MethodCall(
|
|
|
|
var: Expr_Variable(
|
|
|
|
name: foo
|
|
|
|
)
|
|
|
|
name: func
|
|
|
|
args: array(
|
|
|
|
0: Arg(
|
|
|
|
value: Expr_Yield(
|
|
|
|
key: null
|
|
|
|
value: Expr_Variable(
|
|
|
|
name: foo
|
|
|
|
)
|
|
|
|
)
|
|
|
|
byRef: false
|
2014-03-26 18:42:46 +01:00
|
|
|
unpack: false
|
2012-09-07 19:24:44 +02:00
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
14: Expr_New(
|
|
|
|
class: Name(
|
|
|
|
parts: array(
|
|
|
|
0: Foo
|
|
|
|
)
|
|
|
|
)
|
|
|
|
args: array(
|
|
|
|
0: Arg(
|
|
|
|
value: Expr_Yield(
|
|
|
|
key: null
|
|
|
|
value: Expr_Variable(
|
|
|
|
name: foo
|
|
|
|
)
|
|
|
|
)
|
|
|
|
byRef: false
|
2014-03-26 18:42:46 +01:00
|
|
|
unpack: false
|
2012-09-07 19:24:44 +02:00
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
2015-04-26 11:46:23 +02:00
|
|
|
15: Expr_YieldFrom(
|
|
|
|
expr: Expr_Variable(
|
|
|
|
name: foo
|
|
|
|
)
|
|
|
|
)
|
|
|
|
16: Expr_BinaryOp_LogicalAnd(
|
|
|
|
left: Expr_YieldFrom(
|
|
|
|
expr: Expr_Variable(
|
|
|
|
name: foo
|
|
|
|
)
|
|
|
|
)
|
|
|
|
right: Expr_YieldFrom(
|
|
|
|
expr: Expr_Variable(
|
|
|
|
name: bar
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
17: Expr_YieldFrom(
|
|
|
|
expr: Expr_BinaryOp_Plus(
|
|
|
|
left: Expr_Variable(
|
|
|
|
name: foo
|
|
|
|
)
|
|
|
|
right: Expr_Variable(
|
|
|
|
name: bar
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
2012-09-07 19:24:44 +02:00
|
|
|
)
|
|
|
|
)
|
2016-03-09 18:57:16 +01:00
|
|
|
)
|