New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bug: AlternativeSyntaxAnalyzer - fix for nested else #6495
Conversation
Hi, thanks for this PR! Maybe we can make the public function findAlternativeSyntaxBlockEnd(Tokens $tokens, int $index): int
{
if (!isset($tokens[$index])) {
throw new \InvalidArgumentException("There is no token at index {$index}.");
}
if (!$this->isStartOfAlternativeSyntaxBlock($tokens, $index)) {
throw new \InvalidArgumentException("Token at index {$index} is not the start of an alternative syntax block.");
}
$startTokenKind = $tokens[$index]->getId();
$endTokenKinds = self::ALTERNATIVE_SYNTAX_BLOCK_EDGES[$startTokenKind];
$findKinds = [[$startTokenKind]];
foreach ($endTokenKinds as $endTokenKind) {
$findKinds[] = [$endTokenKind];
}
while (true) {
$index = $tokens->getNextTokenOfKind($index, $findKinds);
if ($tokens[$index]->isGivenKind($endTokenKinds)) {
return $index;
}
if ($this->isStartOfAlternativeSyntaxBlock($tokens, $index)) {
$index = $this->findAlternativeSyntaxBlockEnd($tokens, $index);
}
}
} also, maybe we can update the signature: private function isStartOfAlternativeSyntaxBlock(Tokens $tokens, $index): bool into: private function isStartOfAlternativeSyntaxBlock(Tokens $tokens, int $index): bool |
@SpacePossum Thanks for the review, I appreciate your patience with my PRs! I've applied your suggestions and added you as co-author, as you've done most of the work there :) |
Co-authored-by: SpacePossum <possumfromspace@gmail.com>
Thank you @jrmajor. |
thanks @jrmajor , nice fix! :) |
Fixes #6484.