1
0
mirror of https://github.com/danog/PHP-Parser.git synced 2024-11-26 20:04:48 +01:00

Add support for argument unpacking (PHP 5.6)

This commit is contained in:
nikic 2014-03-26 18:42:46 +01:00
parent 96f1151ab2
commit b5bcfa1168
8 changed files with 899 additions and 843 deletions

View File

@ -393,7 +393,7 @@ optional_class_type:
argument_list:
'(' ')' { $$ = array(); }
| '(' non_empty_argument_list ')' { $$ = $2; }
| '(' yield_expr ')' { $$ = array(Arg[$2, false]); }
| '(' yield_expr ')' { $$ = array(Arg[$2, false, false]); }
;
non_empty_argument_list:
@ -402,8 +402,9 @@ non_empty_argument_list:
;
argument:
expr { $$ = Arg[$1, false]; }
| '&' variable { $$ = Arg[$2, true]; }
expr { $$ = Arg[$1, false, false]; }
| '&' variable { $$ = Arg[$2, true, false]; }
| T_ELLIPSIS expr { $$ = Arg[$2, false, true]; }
;
global_var_list:

View File

@ -5,8 +5,9 @@ namespace PhpParser\Node;
use PhpParser\NodeAbstract;
/**
* @property Expr $value Value to pass
* @property bool $byRef Whether to pass by ref
* @property Expr $value Value to pass
* @property bool $byRef Whether to pass by ref
* @property bool $unpack Whether to unpack the argument
*/
class Arg extends NodeAbstract
{
@ -15,13 +16,15 @@ class Arg extends NodeAbstract
*
* @param Expr $value Value to pass
* @param bool $byRef Whether to pass by ref
* @param bool $unpack Whether to unpack the argument
* @param array $attributes Additional attributes
*/
public function __construct(Expr $value, $byRef = false, array $attributes = array()) {
public function __construct(Expr $value, $byRef = false, $unpack = false, array $attributes = array()) {
parent::__construct(
array(
'value' => $value,
'byRef' => $byRef
'value' => $value,
'byRef' => $byRef,
'unpack' => $unpack,
),
$attributes
);

File diff suppressed because it is too large Load Diff

View File

@ -26,7 +26,7 @@ class Standard extends PrettyPrinterAbstract
}
public function pArg(Node\Arg $node) {
return ($node->byRef ? '&' : '') . $this->p($node->value);
return ($node->byRef ? '&' : '') . ($node->unpack ? '...' : '') . $this->p($node->value);
}
public function pConst(Node\Const_ $node) {

View File

@ -6,6 +6,7 @@ f();
f($a);
f($a, $b);
f(&$a);
f($a, ...$b);
-----
array(
0: Expr_FuncCall(
@ -29,6 +30,7 @@ array(
name: a
)
byRef: false
unpack: false
)
)
)
@ -44,12 +46,14 @@ array(
name: a
)
byRef: false
unpack: false
)
1: Arg(
value: Expr_Variable(
name: b
)
byRef: false
unpack: false
)
)
)
@ -65,6 +69,30 @@ array(
name: a
)
byRef: true
unpack: false
)
)
)
4: Expr_FuncCall(
name: Name(
parts: array(
0: f
)
)
args: array(
0: Arg(
value: Expr_Variable(
name: a
)
byRef: false
unpack: false
)
1: Arg(
value: Expr_Variable(
name: b
)
byRef: false
unpack: true
)
)
)

View File

@ -40,6 +40,7 @@ array(
name: b
)
byRef: false
unpack: false
)
)
)

View File

@ -184,6 +184,7 @@ array(
)
)
byRef: false
unpack: false
)
)
)
@ -201,6 +202,7 @@ array(
)
)
byRef: false
unpack: false
)
)
)
@ -219,6 +221,7 @@ array(
)
)
byRef: false
unpack: false
)
)
)

View File

@ -0,0 +1,13 @@
Calls
-----
<?php
f($a);
f(&$a);
f(...$a);
f($a, &$b, ...$c);
-----
f($a);
f(&$a);
f(...$a);
f($a, &$b, ...$c);