Skip to content

Commit

Permalink
impl. parser
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Jun 24, 2023
1 parent 2f64090 commit 4d2da12
Showing 1 changed file with 39 additions and 8 deletions.
47 changes: 39 additions & 8 deletions src/Parser/TypeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -495,15 +495,46 @@ private function parseCallable(TokenIterator $tokens, Ast\Type\IdentifierTypeNod
*/
private function parseCallableTemplates(TokenIterator $tokens): array
{
// TODO not implemented yet
throw new ParserException(
$tokens->currentTokenValue(),
$tokens->currentTokenType(),
$tokens->currentTokenOffset(),
Lexer::TOKEN_IDENTIFIER,
null,
$tokens->currentTokenLine()
$tokens->consumeTokenType(Lexer::TOKEN_OPEN_ANGLE_BRACKET);

$templates = [];

$isFirst = true;
while ($isFirst || $tokens->tryConsumeTokenType(Lexer::TOKEN_COMMA)) {
$tokens->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL);

// trailing comma case
if (!$isFirst && $tokens->isCurrentTokenType(Lexer::TOKEN_CLOSE_ANGLE_BRACKET)) {
break;
}
$isFirst = false;

$templates[] = $this->parseCallableTemplateArgument($tokens);
}

$tokens->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL);
$tokens->consumeTokenType(Lexer::TOKEN_CLOSE_ANGLE_BRACKET);

return $templates;
}


private function parseCallableTemplateArgument(TokenIterator $tokens): Ast\Type\CallableTypeTemplateNode
{
$identifier = $this->enrichWithAttributes(
$tokens,
new Ast\Type\IdentifierTypeNode($tokens->currentTokenValue()),
$tokens->currentTokenLine(),
$tokens->currentTokenIndex()
);
$tokens->consumeTokenType(Lexer::TOKEN_IDENTIFIER);

$ofType = null;
if ($tokens->tryConsumeTokenValue('of')) {
$ofType = $this->parse($tokens);
}

return new Ast\Type\CallableTypeTemplateNode($identifier, $ofType);
}


Expand Down

0 comments on commit 4d2da12

Please sign in to comment.