Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 9 additions & 0 deletions src/Parser/TokenIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,15 @@ public function rollback(): void
}


/** @internal */
public function copy(): self
{
$copy = new self($this->tokens, $this->index);
$copy->savePoints = $this->savePoints;
return $copy;
}


/**
* @throws ParserException
*/
Expand Down
21 changes: 12 additions & 9 deletions src/Parser/TypeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,26 +139,29 @@ private function parseAtomic(TokenIterator $tokens): Ast\Type\TypeNode
$tokens->dropSavePoint(); // because of ConstFetchNode
}

$exception = new ParserException(
$tokens->currentTokenValue(),
$tokens->currentTokenType(),
$tokens->currentTokenOffset(),
Lexer::TOKEN_IDENTIFIER
);
$tokensCopy = $tokens->copy();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you not just clone $tokens?

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, but I know Ondřej dislikes clone

$exception = static function () use ($tokensCopy): ParserException {
return new ParserException(
$tokensCopy->currentTokenValue(),
$tokensCopy->currentTokenType(),
$tokensCopy->currentTokenOffset(),
Lexer::TOKEN_IDENTIFIER
);
};

if ($this->constExprParser === null) {
throw $exception;
throw $exception();
}

try {
$constExpr = $this->constExprParser->parse($tokens, true);
if ($constExpr instanceof Ast\ConstExpr\ConstExprArrayNode) {
throw $exception;
throw $exception();
}

return new Ast\Type\ConstTypeNode($constExpr);
} catch (LogicException $e) {
throw $exception;
throw $exception();
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like constExprParser no longer throws LogicException since d8e9fd9.

}
}

Expand Down