@@ -754,12 +754,43 @@ private function tryParseArrayOrOffsetAccess(TokenIterator $tokens, Ast\Type\Typ
754
754
return $ type ;
755
755
}
756
756
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
+
757
788
758
789
/**
759
790
* @phpstan-impure
760
791
* @param Ast\Type\ArrayShapeNode::KIND_* $kind
761
792
*/
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
763
794
{
764
795
$ tokens ->consumeTokenType (Lexer::TOKEN_OPEN_CURLY_BRACKET );
765
796
@@ -815,6 +846,19 @@ private function parseArrayShapeItem(TokenIterator $tokens): Ast\Type\ArrayShape
815
846
{
816
847
$ startLine = $ tokens ->currentTokenLine ();
817
848
$ 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
+
818
862
try {
819
863
$ tokens ->pushSavePoint ();
820
864
$ key = $ this ->parseArrayShapeKey ($ tokens );
@@ -827,7 +871,8 @@ private function parseArrayShapeItem(TokenIterator $tokens): Ast\Type\ArrayShape
827
871
$ tokens ,
828
872
new Ast \Type \ArrayShapeItemNode ($ key , $ optional , $ value ),
829
873
$ startLine ,
830
- $ startIndex
874
+ $ startIndex ,
875
+ $ comments
831
876
);
832
877
} catch (ParserException $ e ) {
833
878
$ tokens ->rollback ();
0 commit comments