Add multiline generic support

This solves #42
This commit is contained in:
Andreas Frömer 2020-05-04 15:13:26 +02:00 committed by Ondřej Mirtes
parent 7093385390
commit b205ccdf21
2 changed files with 62 additions and 1 deletions

View File

@ -164,14 +164,19 @@ class TypeParser
public function parseGeneric(TokenIterator $tokens, Ast\Type\IdentifierTypeNode $baseType): Ast\Type\GenericTypeNode
{
$tokens->consumeTokenType(Lexer::TOKEN_OPEN_ANGLE_BRACKET);
$tokens->consumeTokenType(Lexer::TOKEN_OPEN_ANGLE_BRACKET);
$tokens->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL);
$genericTypes = [$this->parse($tokens)];
while ($tokens->tryConsumeTokenType(Lexer::TOKEN_COMMA)) {
$tokens->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL);
$genericTypes[] = $this->parse($tokens);
$tokens->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL);
}
$tokens->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL);
$tokens->consumeTokenType(Lexer::TOKEN_CLOSE_ANGLE_BRACKET);
return new Ast\Type\GenericTypeNode($baseType, $genericTypes);
}

View File

@ -899,6 +899,62 @@ class TypeParserTest extends \PHPUnit\Framework\TestCase
new ConstTypeNode(new ConstFetchNode('QueueAttributeName', '*')),
]),
],
[
'array<' . PHP_EOL .
' Foo' . PHP_EOL .
'>',
new GenericTypeNode(
new IdentifierTypeNode('array'),
[
new IdentifierTypeNode('Foo')
]
)
],
[
'array<' . PHP_EOL .
' Foo,' . PHP_EOL .
' Bar' . PHP_EOL .
'>',
new GenericTypeNode(
new IdentifierTypeNode('array'),
[
new IdentifierTypeNode('Foo'),
new IdentifierTypeNode('Bar'),
]
)
],
[
'array<' . PHP_EOL .
' Foo, Bar' . PHP_EOL .
'>',
new GenericTypeNode(
new IdentifierTypeNode('array'),
[
new IdentifierTypeNode('Foo'),
new IdentifierTypeNode('Bar'),
]
)
],
[
'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')
]
)
]
)
],
];
}