Don't make VariadicPlaceholder an expression

And don't store it in an Arg.
This commit is contained in:
Nikita Popov 2021-09-12 21:59:26 +02:00
parent b5234eacd0
commit 08501991d4
7 changed files with 18 additions and 44 deletions

View File

@ -6,8 +6,8 @@ Version 4.12.1-dev
* [PHP 8.1] Added support for intersection types using a new `IntersectionType` node.
* [PHP 8.1] Added support for explicit octal literals.
* [PHP 8.1] Added support for first-class callables. These are represented using a call whose first
`Arg->expr` is an `Expr\VariadicPlaceholder`. The representation is intended to be
forward-compatible with partial function application, just like the PHP feature itself.
argument is a `VariadicPlaceholder`. The representation is intended to be forward-compatible with
partial function application, just like the PHP feature itself.
Version 4.12.0 (2021-07-21)
---------------------------

View File

@ -623,8 +623,7 @@ argument_list:
;
variadic_placeholder:
T_ELLIPSIS
{ $$ = Node\Arg[Node\VariadicPlaceholder[], false, false]; }
T_ELLIPSIS { $$ = Node\VariadicPlaceholder[]; }
;
non_empty_argument_list:

View File

@ -2,7 +2,7 @@
namespace PhpParser\Node;
use PhpParser\Node\Expr\VariadicPlaceholder;
use PhpParser\Node\VariadicPlaceholder;
use PhpParser\NodeAbstract;
class Arg extends NodeAbstract

View File

@ -1,13 +1,13 @@
<?php declare(strict_types=1);
namespace PhpParser\Node\Expr;
namespace PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\NodeAbstract;
/**
* Represents the "..." in "foo(...)" of the first-class callable syntax.
*/
class VariadicPlaceholder extends Expr {
class VariadicPlaceholder extends NodeAbstract {
/**
* Create a variadic argument placeholder (first-class callable syntax).
*
@ -18,7 +18,7 @@ class VariadicPlaceholder extends Expr {
}
public function getType(): string {
return 'Expr_VariadicPlaceholder';
return 'VariadicPlaceholder';
}
public function getSubNodeNames(): array {

View File

@ -1934,7 +1934,7 @@ class Php7 extends \PhpParser\ParserAbstract
$this->semValue = array($this->semStack[$stackPos-(3-2)]);
},
310 => function ($stackPos) {
$this->semValue = new Node\Arg(new Expr\VariadicPlaceholder($this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes), false, false, $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes);
$this->semValue = new Node\VariadicPlaceholder($this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes);
},
311 => function ($stackPos) {
$this->semValue = array($this->semStack[$stackPos-(1-1)]);

View File

@ -33,6 +33,10 @@ class Standard extends PrettyPrinterAbstract
. $this->p($node->value);
}
protected function pVariadicPlaceholder(Node\VariadicPlaceholder $node) {
return '...';
}
protected function pConst(Node\Const_ $node) {
return $node->name . ' = ' . $this->p($node->value);
}
@ -692,10 +696,6 @@ class Standard extends PrettyPrinterAbstract
}
}
protected function pExpr_VariadicPlaceholder(Expr\VariadicPlaceholder $node) {
return '...';
}
// Declarations
protected function pStmt_Namespace(Stmt\Namespace_ $node) {

View File

@ -21,12 +21,7 @@ array(
)
)
args: array(
0: Arg(
name: null
value: Expr_VariadicPlaceholder(
)
byRef: false
unpack: false
0: VariadicPlaceholder(
)
)
)
@ -40,12 +35,7 @@ array(
name: foo
)
args: array(
0: Arg(
name: null
value: Expr_VariadicPlaceholder(
)
byRef: false
unpack: false
0: VariadicPlaceholder(
)
)
)
@ -61,12 +51,7 @@ array(
name: foo
)
args: array(
0: Arg(
name: null
value: Expr_VariadicPlaceholder(
)
byRef: false
unpack: false
0: VariadicPlaceholder(
)
)
)
@ -79,12 +64,7 @@ array(
)
)
args: array(
0: Arg(
name: null
value: Expr_VariadicPlaceholder(
)
byRef: false
unpack: false
0: VariadicPlaceholder(
)
)
comments: array(
@ -106,12 +86,7 @@ array(
)
)
args: array(
0: Arg(
name: null
value: Expr_VariadicPlaceholder(
)
byRef: false
unpack: false
0: VariadicPlaceholder(
)
)
)