Skip to content

Commit afabfdf

Browse files
committed
TypeParser: ignore unclosed array notation
1 parent 3dda812 commit afabfdf

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/Parser/TypeParser.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ private function parseAtomic(TokenIterator $tokens): Ast\Type\TypeNode
3535
$tokens->consumeTokenType(Lexer::TOKEN_CLOSE_PARENTHESES);
3636

3737
if ($tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_SQUARE_BRACKET)) {
38-
$type = $this->parseArray($tokens, $type);
38+
$type = $this->tryParseArray($tokens, $type);
3939
}
4040

4141
} elseif ($tokens->tryConsumeTokenType(Lexer::TOKEN_THIS_VARIABLE)) {
@@ -49,7 +49,7 @@ private function parseAtomic(TokenIterator $tokens): Ast\Type\TypeNode
4949
$type = $this->parseGeneric($tokens, $type);
5050

5151
} elseif ($tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_SQUARE_BRACKET)) {
52-
$type = $this->parseArray($tokens, $type);
52+
$type = $this->tryParseArray($tokens, $type);
5353
}
5454
}
5555

@@ -110,11 +110,19 @@ private function parseGeneric(TokenIterator $tokens, Ast\Type\IdentifierTypeNode
110110
}
111111

112112

113-
private function parseArray(TokenIterator $tokens, Ast\Type\TypeNode $type): Ast\Type\TypeNode
113+
private function tryParseArray(TokenIterator $tokens, Ast\Type\TypeNode $type): Ast\Type\TypeNode
114114
{
115-
while ($tokens->tryConsumeTokenType(Lexer::TOKEN_OPEN_SQUARE_BRACKET)) {
116-
$tokens->consumeTokenType(Lexer::TOKEN_CLOSE_SQUARE_BRACKET);
117-
$type = new Ast\Type\ArrayTypeNode($type);
115+
try {
116+
while ($tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_SQUARE_BRACKET)) {
117+
$tokens->pushSavePoint();
118+
$tokens->consumeTokenType(Lexer::TOKEN_OPEN_SQUARE_BRACKET);
119+
$tokens->consumeTokenType(Lexer::TOKEN_CLOSE_SQUARE_BRACKET);
120+
$tokens->dropSavePoint();
121+
$type = new Ast\Type\ArrayTypeNode($type);
122+
}
123+
124+
} catch (ParserException $e) {
125+
$tokens->rollback();
118126
}
119127

120128
return $type;

0 commit comments

Comments
 (0)