Skip to content

Commit

Permalink
Document what parseText is doing
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jul 21, 2023
1 parent a113f0c commit 395b6db
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Parser/PhpDocParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,21 +214,27 @@ private function parseText(TokenIterator $tokens): Ast\PhpDoc\PhpDocTextNode
{
$text = '';

// if the next token is EOL, everything below is skipped and empty string is returned
while (!$tokens->isCurrentTokenType(Lexer::TOKEN_PHPDOC_EOL)) {
$text .= $tokens->getSkippedHorizontalWhiteSpaceIfAny() . $tokens->joinUntil(Lexer::TOKEN_PHPDOC_EOL, Lexer::TOKEN_CLOSE_PHPDOC, Lexer::TOKEN_END);

// stop if we're not at EOL - meaning it's the end of PHPDoc
if (!$tokens->isCurrentTokenType(Lexer::TOKEN_PHPDOC_EOL)) {
break;
}

$tokens->pushSavePoint();
$tokens->next();

// if we're at EOL, check what's next
// if next is a PHPDoc tag, EOL, or end of PHPDoc, stop
if ($tokens->isCurrentTokenType(Lexer::TOKEN_PHPDOC_TAG, Lexer::TOKEN_DOCTRINE_TAG, Lexer::TOKEN_PHPDOC_EOL, Lexer::TOKEN_CLOSE_PHPDOC, Lexer::TOKEN_END)) {
$tokens->rollback();
break;
}

// otherwise if the next is text, continue building the description string

$tokens->dropSavePoint();
$text .= $tokens->getDetectedNewline() ?? "\n";
}
Expand All @@ -241,9 +247,11 @@ private function parseOptionalDescriptionAfterDoctrineTag(TokenIterator $tokens)
{
$text = '';

// if the next token is EOL, everything below is skipped and empty string is returned
while (!$tokens->isCurrentTokenType(Lexer::TOKEN_PHPDOC_EOL)) {
$text .= $tokens->getSkippedHorizontalWhiteSpaceIfAny() . $tokens->joinUntil(Lexer::TOKEN_PHPDOC_TAG, Lexer::TOKEN_DOCTRINE_TAG, Lexer::TOKEN_PHPDOC_EOL, Lexer::TOKEN_CLOSE_PHPDOC, Lexer::TOKEN_END);

// stop if we're not at EOL - meaning it's the end of PHPDoc
if (!$tokens->isCurrentTokenType(Lexer::TOKEN_PHPDOC_EOL)) {
if (!$tokens->isPrecededByHorizontalWhitespace()) {
return trim($text . $this->parseText($tokens)->text, " \t");
Expand Down Expand Up @@ -281,11 +289,15 @@ private function parseOptionalDescriptionAfterDoctrineTag(TokenIterator $tokens)
$tokens->pushSavePoint();
$tokens->next();

// if we're at EOL, check what's next
// if next is a PHPDoc tag, EOL, or end of PHPDoc, stop
if ($tokens->isCurrentTokenType(Lexer::TOKEN_PHPDOC_TAG, Lexer::TOKEN_DOCTRINE_TAG, Lexer::TOKEN_PHPDOC_EOL, Lexer::TOKEN_CLOSE_PHPDOC, Lexer::TOKEN_END)) {
$tokens->rollback();
break;
}

// otherwise if the next is text, continue building the description string

$tokens->dropSavePoint();
$text .= $tokens->getDetectedNewline() ?? "\n";
}
Expand Down

0 comments on commit 395b6db

Please sign in to comment.