Skip to content

Commit 17a23f6

Browse files
committed
PhpDocParser: merge adjacent text nodes
1 parent 95787df commit 17a23f6

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/Parser/PhpDocParser.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,36 @@ public function __construct(TypeParser $typeParser, ConstExprParser $constantExp
2323

2424
public function parse(TokenIterator $tokens): Ast\PhpDoc\PhpDocNode
2525
{
26+
$textNode = '';
2627
$children = [];
2728
$tokens->consumeTokenType(Lexer::TOKEN_OPEN_PHPDOC);
2829

2930
if ($tokens->tryConsumeHorizontalWhiteSpace()) {
30-
$children[] = new Ast\PhpDoc\PhpDocTextNode($tokens->prevTokenValue());
31+
$textNode .= $tokens->prevTokenValue();
3132
}
3233

3334
while (!$tokens->tryConsumeTokenType(Lexer::TOKEN_CLOSE_PHPDOC)) {
3435
if ($tokens->isCurrentTokenType(Lexer::TOKEN_PHPDOC_TAG)) {
36+
if ($textNode !== '') {
37+
$children[] = new Ast\PhpDoc\PhpDocTextNode($textNode);
38+
$textNode = '';
39+
}
3540
$children[] = $this->parseTag($tokens);
3641

3742
} else {
38-
$children[] = new Ast\PhpDoc\PhpDocTextNode($tokens->currentTokenValue());
43+
$textNode .= $tokens->currentTokenValue();
3944
$tokens->next();
4045
}
4146

4247
if ($tokens->tryConsumeHorizontalWhiteSpace()) {
43-
$children[] = new Ast\PhpDoc\PhpDocTextNode($tokens->prevTokenValue());
48+
$textNode .= $tokens->prevTokenValue();
4449
}
4550
}
4651

52+
if ($textNode !== '') {
53+
$children[] = new Ast\PhpDoc\PhpDocTextNode($textNode);
54+
}
55+
4756
return new Ast\PhpDoc\PhpDocNode($children);
4857
}
4958

0 commit comments

Comments
 (0)