1
0
mirror of https://github.com/danog/PHP-Parser.git synced 2024-12-13 01:47:22 +01:00
PHP-Parser/test/code/parser/stmt/generator/basic.test

319 lines
9.2 KiB
Plaintext
Raw Normal View History

2015-04-26 11:46:23 +02:00
Generators (yield expression)
-----
<?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;
}
-----
array(
0: Stmt_Function(
byRef: false
name: Identifier(
name: gen
)
params: array(
)
returnType: null
stmts: array(
2017-01-19 22:25:22 +01:00
0: Stmt_Expression(
expr: Expr_Yield(
key: null
value: null
2017-01-19 22:25:22 +01:00
comments: array(
0: // statements
)
)
comments: array(
2017-01-19 22:25:22 +01:00
0: // statements
)
)
2017-01-19 22:25:22 +01:00
1: Stmt_Expression(
expr: Expr_Yield(
key: null
value: Expr_Variable(
name: value
)
)
)
2017-01-19 22:25:22 +01:00
2: Stmt_Expression(
expr: Expr_Yield(
key: Expr_Variable(
name: key
)
value: Expr_Variable(
name: value
)
)
)
2017-01-19 22:25:22 +01:00
3: Stmt_Expression(
expr: Expr_Assign(
var: Expr_Variable(
name: data
comments: array(
0: // expressions
)
)
expr: Expr_Yield(
key: null
value: null
)
comments: array(
0: // expressions
)
)
comments: array(
0: // expressions
)
)
4: Stmt_Expression(
expr: Expr_Assign(
var: Expr_Variable(
name: data
)
expr: Expr_Yield(
key: null
value: Expr_Variable(
name: value
)
)
)
)
5: Stmt_Expression(
expr: Expr_Assign(
var: Expr_Variable(
name: data
)
expr: Expr_Yield(
key: Expr_Variable(
name: key
)
value: Expr_Variable(
name: value
)
)
)
)
6: Stmt_If(
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
comments: array(
0: // yield in language constructs with their own parentheses
)
)
7: Stmt_If(
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(
stmts: array(
)
cond: Expr_Yield(
key: null
value: Expr_Variable(
name: foo
)
)
)
10: Stmt_Switch(
cond: Expr_Yield(
key: null
value: Expr_Variable(
name: foo
)
)
cases: array(
)
)
2017-01-19 22:25:22 +01:00
11: Stmt_Expression(
expr: Expr_Exit(
expr: Expr_Yield(
key: null
value: Expr_Variable(
name: foo
)
)
)
)
2017-01-19 22:25:22 +01:00
12: Stmt_Expression(
expr: Expr_FuncCall(
name: Name(
parts: array(
0: func
)
comments: array(
0: // yield in function calls
)
)
2017-01-19 22:25:22 +01:00
args: array(
0: Arg(
value: Expr_Yield(
key: null
value: Expr_Variable(
name: foo
)
)
2017-01-19 22:25:22 +01:00
byRef: false
unpack: false
)
2017-01-19 22:25:22 +01:00
)
comments: array(
0: // yield in function calls
)
)
comments: array(
0: // yield in function calls
)
)
2017-01-19 22:25:22 +01:00
13: Stmt_Expression(
expr: Expr_MethodCall(
var: Expr_Variable(
name: foo
)
name: Identifier(
name: func
)
2017-01-19 22:25:22 +01:00
args: array(
0: Arg(
value: Expr_Yield(
key: null
value: Expr_Variable(
name: foo
)
)
2017-01-19 22:25:22 +01:00
byRef: false
unpack: false
)
)
)
)
2017-01-19 22:25:22 +01:00
14: Stmt_Expression(
expr: Expr_New(
class: Name(
parts: array(
0: Foo
)
)
2017-01-19 22:25:22 +01:00
args: array(
0: Arg(
value: Expr_Yield(
key: null
value: Expr_Variable(
name: foo
)
)
2017-01-19 22:25:22 +01:00
byRef: false
unpack: false
)
)
)
)
2017-01-19 22:25:22 +01:00
15: Stmt_Expression(
expr: Expr_YieldFrom(
2015-04-26 11:46:23 +02:00
expr: Expr_Variable(
name: foo
)
)
2017-01-19 22:25:22 +01:00
)
16: Stmt_Expression(
expr: Expr_BinaryOp_LogicalAnd(
left: Expr_YieldFrom(
expr: Expr_Variable(
name: foo
)
)
right: Expr_YieldFrom(
expr: Expr_Variable(
name: bar
)
2015-04-26 11:46:23 +02:00
)
)
)
2017-01-19 22:25:22 +01:00
17: Stmt_Expression(
expr: Expr_YieldFrom(
expr: Expr_BinaryOp_Plus(
left: Expr_Variable(
name: foo
)
right: Expr_Variable(
name: bar
)
2015-04-26 11:46:23 +02:00
)
)
)
)
)
)