Permalink
Browse files

Refs #204: Support for the ... operator in function calls implemented

  • Loading branch information...
manuelpichler committed Jan 6, 2017
1 parent e805725 commit 078e5320b2436adf4c393af4180df8372c1309be
@@ -46,6 +46,7 @@
use PDepend\Source\AST\AbstractASTClassOrInterface;
use PDepend\Source\AST\AbstractASTType;
use PDepend\Source\AST\ASTAllocationExpression;
use PDepend\Source\AST\ASTArguments;
use PDepend\Source\AST\ASTArray;
use PDepend\Source\AST\ASTClass;
use PDepend\Source\AST\ASTDeclareStatement;
@@ -2532,12 +2533,11 @@ private function parseAlternativeScopeTermination($tokenType)
* This method parses multiple expressions and adds them as children to the
* given <b>$exprList</b> node.
*
* @param \PDepend\Source\AST\ASTNode $exprList Parent that accepts multiple expr.
*
* @param \PDepend\Source\AST\ASTNode
* @return \PDepend\Source\AST\ASTNode
* @since 1.0.0
*/
private function parseExpressionList(\PDepend\Source\AST\ASTNode $exprList)
private function parseExpressionList(ASTNode $exprList)
{
$this->consumeComments();
while ($expr = $this->parseOptionalExpression()) {
@@ -4225,13 +4225,22 @@ protected function parseArguments()
$this->consumeComments();
if (Tokens::T_PARENTHESIS_CLOSE !== $this->tokenizer->peek()) {
$arguments = $this->parseExpressionList($arguments);
$arguments = $this->parseArgumentList($arguments);
}
$this->consumeToken(Tokens::T_PARENTHESIS_CLOSE);
return $this->setNodePositionsAndReturn($arguments);
}
/**
* @param \PDepend\Source\AST\ASTArguments $arguments
* @return \PDepend\Source\AST\ASTArguments
*/
protected function parseArgumentList(ASTArguments $arguments)
{
return $this->parseExpressionList($arguments);
}
/**
* This method implements the parsing for various expression types like
* variables, object/static method. All these expressions are valid in
@@ -43,6 +43,7 @@
namespace PDepend\Source\Language\PHP;
use PDepend\Source\AST\ASTArguments;
use PDepend\Source\AST\ASTValue;
use PDepend\Source\Parser\UnexpectedTokenException;
use PDepend\Source\Tokenizer\Tokenizer;
@@ -321,4 +322,35 @@ protected function parseExpressionVersion56()
return $expr;
}
}
/**
* @param \PDepend\Source\AST\ASTArguments $arguments
* @return \PDepend\Source\AST\ASTArguments
*/
protected function parseArgumentList(ASTArguments $arguments)
{
while (true) {
$this->consumeComments();
if (Tokens::T_ELLIPSIS === $this->tokenizer->peek()) {
$this->consumeToken(Tokens::T_ELLIPSIS);
}
$this->consumeComments();
if (null === ($expr = $this->parseOptionalExpression())) {
break;
}
$arguments->addChild($expr);
$this->consumeComments();
if (Tokens::T_COMMA === $this->tokenizer->peek()) {
$this->consumeToken(Tokens::T_COMMA);
$this->consumeComments();
continue;
}
}
return $arguments;
}
}
@@ -231,4 +231,12 @@ public function testPowExpressionInFieldDeclaration()
$this->assertNotNull($node);
}
/**
* @return void
*/
public function testEllipsisOperatorInFunctionCall()
{
$this->assertNotNull($this->parseCodeResourceForTest());
}
}
@@ -111,6 +111,16 @@ public function testListKeywordAsFunctionNameThrowsException()
$this->parseCodeResourceForTest();
}
/**
* @return void
* @expectedException \PDepend\Source\Parser\UnexpectedTokenException
* @expectedExceptionMessageRegExp (^Unexpected token: \.\.\., line: 6, col: 9, file: )
*/
public function testEllipsisOperatorInFunctionCallThrowsException()
{
$this->parseCodeResourceForTest();
}
/**
* @param \PDepend\Source\Tokenizer\Tokenizer $tokenizer
* @param \PDepend\Source\Builder\Builder $builder
@@ -169,6 +169,14 @@ public function testGroupUseStatementThrowsException()
* @expectedExceptionMessageRegExp (^Unexpected token: ::, line: 8, col: 24, file: )
*/
public function testUniformVariableSyntaxThrowsException()
{
$this->parseCodeResourceForTest();
}
/**
* @return void
*/
public function testEllipsisOperatorInFunctionCall()
{
$this->assertNotNull($this->parseCodeResourceForTest());
}
@@ -0,0 +1,11 @@
<?php
function foo($a, $b) {
}
function bar($x, $y) {
foo(...[$x, $y]);
}
function baz() {
bar(42, ...[23]);
}
@@ -0,0 +1,11 @@
<?php
function foo($a, $b) {
}
function bar($x, $y) {
foo(...[$x, $y]);
}
function baz() {
bar(42, ...[23]);
}
@@ -0,0 +1,11 @@
<?php
function foo($a, $b) {
}
function bar($x, $y) {
foo(...[$x, $y]);
}
function baz() {
bar(42, ...[23]);
}

0 comments on commit 078e532

Please sign in to comment.