Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@ private function getParseListElementFn($context) {

/**
* Aborts parsing list when one of the parent contexts understands something
* @param ParseContext $context
* @return bool
*/
private function isCurrentTokenValidInEnclosingContexts() {
Expand All @@ -367,7 +366,7 @@ private function isInParseContext($contextToCheck) {
* Retrieve the current token, and check that it's of the expected TokenKind.
* If so, advance and return the token. Otherwise return a MissingToken for
* the expected token.
* @param int $kind
* @param int|int[] ...$kinds
* @return Token
*/
private function eat(...$kinds) {
Expand All @@ -385,6 +384,10 @@ private function eat(...$kinds) {
return new MissingToken($kinds[0], $token->fullStart);
}

/**
* @param int|int[] ...$kinds (Can provide a single value with a list of kinds, or multiple kinds)
* @return Token|null
*/
private function eatOptional(...$kinds) {
$token = $this->token;
if (\is_array($kinds[0])) {
Expand Down Expand Up @@ -849,6 +852,10 @@ private function isExpressionStartFn() {
};
}

/**
* @param Node $parentNode
* @return Token|MissingToken|Node
*/
private function parsePrimaryExpression($parentNode) {
$token = $this->getCurrentToken();
switch ($token->kind) {
Expand Down Expand Up @@ -1135,6 +1142,15 @@ private function isParameterStartFn() {
};
}

/**
* @param string $className (name of subclass of DelimitedList)
* @param int $delimiter
* @param callable $isElementStartFn
* @param callable $parseElementFn
* @param Node $parentNode
* @param bool $allowEmptyElements
* @return DelimitedList|null instance of $className
*/
private function parseDelimitedList($className, $delimiter, $isElementStartFn, $parseElementFn, $parentNode, $allowEmptyElements = false) {
// TODO consider allowing empty delimiter to be more tolerant
$node = new $className();
Expand Down Expand Up @@ -1191,7 +1207,7 @@ private function parseQualifiedNameFn() {
$node->globalSpecifier = $this->eatOptional(TokenKind::BackslashToken);
}

$node->nameParts =
$nameParts =
$this->parseDelimitedList(
DelimitedList\QualifiedNameParts::class,
TokenKind::BackslashToken,
Expand All @@ -1214,11 +1230,11 @@ function ($parentNode) {
$name->kind = TokenKind::Name; // bool/true/null/static should not be treated as keywords in this case
return $name;
}, $node);
if ($node->nameParts === null && $node->globalSpecifier === null && $node->relativeSpecifier === null) {
if ($nameParts === null && $node->globalSpecifier === null && $node->relativeSpecifier === null) {
return null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously it would return null if $node->nameParts was null, ie if parseDelimitedList returned null. I think this check should be for $nameParts now? Otherwise I agree with not using $node->nameParts to hold a temporary value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it should. Missed that.

}

$node->nameParts = $node->nameParts ? $node->nameParts->children : [];
$node->nameParts = $nameParts ? $nameParts->children : [];

return $node;
};
Expand Down