@@ -754,12 +754,43 @@ private function tryParseArrayOrOffsetAccess(TokenIterator $tokens, Ast\Type\Typ
754754 return $ type ;
755755 }
756756
757+ private function parseArrayShape (TokenIterator $ tokens , Ast \Type \TypeNode $ type , string $ kind ): Ast \Type \ArrayShapeNode
758+ {
759+ $ tokens ->consumeTokenType (Lexer::TOKEN_OPEN_CURLY_BRACKET );
760+
761+ $ items = [];
762+ $ sealed = true ;
763+
764+ do {
765+ $ tokens ->tryConsumeTokenType (Lexer::TOKEN_PHPDOC_EOL );
766+
767+ if ($ tokens ->tryConsumeTokenType (Lexer::TOKEN_CLOSE_CURLY_BRACKET )) {
768+ return new Ast \Type \ArrayShapeNode ($ items , true , $ kind );
769+ }
770+
771+ if ($ tokens ->tryConsumeTokenType (Lexer::TOKEN_VARIADIC )) {
772+ $ sealed = false ;
773+ $ tokens ->tryConsumeTokenType (Lexer::TOKEN_COMMA );
774+ break ;
775+ }
776+
777+ $ items [] = $ this ->parseArrayShapeItem ($ tokens );
778+
779+ $ tokens ->tryConsumeTokenType (Lexer::TOKEN_PHPDOC_EOL );
780+ } while ($ tokens ->tryConsumeTokenType (Lexer::TOKEN_COMMA ));
781+
782+ $ tokens ->tryConsumeTokenType (Lexer::TOKEN_PHPDOC_EOL );
783+ $ tokens ->consumeTokenType (Lexer::TOKEN_CLOSE_CURLY_BRACKET );
784+
785+ return new Ast \Type \ArrayShapeNode ($ items , $ sealed , $ kind );
786+ }
787+
757788
758789 /**
759790 * @phpstan-impure
760791 * @param Ast\Type\ArrayShapeNode::KIND_* $kind
761792 */
762- private function parseArrayShape (TokenIterator $ tokens , Ast \Type \TypeNode $ type , string $ kind ): Ast \Type \ArrayShapeNode
793+ private function parseArrayShape_bak (TokenIterator $ tokens , Ast \Type \TypeNode $ type , string $ kind ): Ast \Type \ArrayShapeNode
763794 {
764795 $ tokens ->consumeTokenType (Lexer::TOKEN_OPEN_CURLY_BRACKET );
765796
@@ -815,6 +846,19 @@ private function parseArrayShapeItem(TokenIterator $tokens): Ast\Type\ArrayShape
815846 {
816847 $ startLine = $ tokens ->currentTokenLine ();
817848 $ startIndex = $ tokens ->currentTokenIndex ();
849+
850+ $ comments = [];
851+ while (1 ) {
852+ if ($ tokens ->tryConsumeTokenType (Lexer::TOKEN_PHPDOC_EOL )) {
853+ continue ;
854+ } elseif ($ tokens ->currentTokenType () === Lexer::TOKEN_COMMENT ) {
855+ $ comments [] = new Ast \Comment ($ tokens ->currentTokenValue (), $ tokens ->currentTokenLine (), $ tokens ->currentTokenIndex ());
856+ $ tokens ->next ();
857+ } else {
858+ break ;
859+ }
860+ }
861+
818862 try {
819863 $ tokens ->pushSavePoint ();
820864 $ key = $ this ->parseArrayShapeKey ($ tokens );
@@ -827,7 +871,8 @@ private function parseArrayShapeItem(TokenIterator $tokens): Ast\Type\ArrayShape
827871 $ tokens ,
828872 new Ast \Type \ArrayShapeItemNode ($ key , $ optional , $ value ),
829873 $ startLine ,
830- $ startIndex
874+ $ startIndex ,
875+ $ comments
831876 );
832877 } catch (ParserException $ e ) {
833878 $ tokens ->rollback ();
0 commit comments