mirror of
https://github.com/danog/phpdoc-parser.git
synced 2024-11-26 20:15:11 +01:00
Add support for trailing comma
This commit is contained in:
parent
9efbbb656a
commit
44500ca1b7
@ -167,10 +167,15 @@ class TypeParser
|
||||
$tokens->consumeTokenType(Lexer::TOKEN_OPEN_ANGLE_BRACKET);
|
||||
$tokens->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL);
|
||||
$genericTypes = [$this->parse($tokens)];
|
||||
$tokens->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL);
|
||||
|
||||
$tokens->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL);
|
||||
|
||||
while ($tokens->tryConsumeTokenType(Lexer::TOKEN_COMMA)) {
|
||||
$tokens->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL);
|
||||
if ($tokens->tryConsumeTokenType(Lexer::TOKEN_CLOSE_ANGLE_BRACKET)) {
|
||||
// trailing comma case
|
||||
return new Ast\Type\GenericTypeNode($baseType, $genericTypes);
|
||||
}
|
||||
$genericTypes[] = $this->parse($tokens);
|
||||
$tokens->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL);
|
||||
}
|
||||
|
@ -3079,29 +3079,6 @@ chunk. Must be higher that in the previous request.'),
|
||||
]),
|
||||
];
|
||||
|
||||
// yield [
|
||||
// 'multiline generic types - trailing comma',
|
||||
// '/**' . PHP_EOL .
|
||||
// ' * @implements Foo<' . PHP_EOL .
|
||||
// ' * A,' . PHP_EOL .
|
||||
// ' * >' . PHP_EOL .
|
||||
// ' */',
|
||||
// new PhpDocNode([
|
||||
// new PhpDocTagNode(
|
||||
// '@implements',
|
||||
// new ImplementsTagValueNode(
|
||||
// new GenericTypeNode(
|
||||
// new IdentifierTypeNode('Foo'),
|
||||
// [
|
||||
// new IdentifierTypeNode('A'),
|
||||
// ]
|
||||
// ),
|
||||
// ''
|
||||
// )
|
||||
// ),
|
||||
// ]),
|
||||
// ];
|
||||
|
||||
yield [
|
||||
'multiline generic types - leading comma',
|
||||
'/**' . PHP_EOL .
|
||||
@ -3126,6 +3103,31 @@ chunk. Must be higher that in the previous request.'),
|
||||
),
|
||||
]),
|
||||
];
|
||||
|
||||
yield [
|
||||
'multiline generic types - traling comma',
|
||||
'/**' . PHP_EOL .
|
||||
' * @implements Foo<' . PHP_EOL .
|
||||
' * A,' . PHP_EOL .
|
||||
' * B,' . PHP_EOL .
|
||||
' * >' . PHP_EOL .
|
||||
' */',
|
||||
new PhpDocNode([
|
||||
new PhpDocTagNode(
|
||||
'@implements',
|
||||
new ImplementsTagValueNode(
|
||||
new GenericTypeNode(
|
||||
new IdentifierTypeNode('Foo'),
|
||||
[
|
||||
new IdentifierTypeNode('A'),
|
||||
new IdentifierTypeNode('B'),
|
||||
]
|
||||
),
|
||||
''
|
||||
)
|
||||
),
|
||||
]),
|
||||
];
|
||||
}
|
||||
|
||||
public function dataParseTagValue(): array
|
||||
|
@ -899,7 +899,7 @@ class TypeParserTest extends \PHPUnit\Framework\TestCase
|
||||
new ConstTypeNode(new ConstFetchNode('QueueAttributeName', '*')),
|
||||
]),
|
||||
],
|
||||
[
|
||||
[
|
||||
'array<' . PHP_EOL .
|
||||
' Foo' . PHP_EOL .
|
||||
'>',
|
||||
@ -955,6 +955,26 @@ class TypeParserTest extends \PHPUnit\Framework\TestCase
|
||||
]
|
||||
),
|
||||
],
|
||||
[
|
||||
'array<' . PHP_EOL .
|
||||
' Foo,' . PHP_EOL .
|
||||
' array<' . PHP_EOL .
|
||||
' Bar,' . PHP_EOL .
|
||||
' >' . PHP_EOL .
|
||||
'>',
|
||||
new GenericTypeNode(
|
||||
new IdentifierTypeNode('array'),
|
||||
[
|
||||
new IdentifierTypeNode('Foo'),
|
||||
new GenericTypeNode(
|
||||
new IdentifierTypeNode('array'),
|
||||
[
|
||||
new IdentifierTypeNode('Bar'),
|
||||
]
|
||||
),
|
||||
]
|
||||
),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user