@@ -34,8 +34,11 @@ class PhpDocParser
3434 /** @var bool */
3535 private $ useLinesAttributes ;
3636
37+ /** @var bool */
38+ private $ useIndexAttributes ;
39+
3740 /**
38- * @param array{lines?: bool} $usedAttributes
41+ * @param array{lines?: bool, indexes?: bool } $usedAttributes
3942 */
4043 public function __construct (
4144 TypeParser $ typeParser ,
@@ -50,6 +53,7 @@ public function __construct(
5053 $ this ->requireWhitespaceBeforeDescription = $ requireWhitespaceBeforeDescription ;
5154 $ this ->preserveTypeAliasesWithInvalidTypes = $ preserveTypeAliasesWithInvalidTypes ;
5255 $ this ->useLinesAttributes = $ usedAttributes ['lines ' ] ?? false ;
56+ $ this ->useIndexAttributes = $ usedAttributes ['indexes ' ] ?? false ;
5357 }
5458
5559
@@ -91,26 +95,40 @@ private function parseChild(TokenIterator $tokens): Ast\PhpDoc\PhpDocChildNode
9195 {
9296 if ($ tokens ->isCurrentTokenType (Lexer::TOKEN_PHPDOC_TAG )) {
9397 $ startLine = $ tokens ->currentTokenLine ();
98+ $ startIndex = $ tokens ->currentTokenIndex ();
9499 $ tag = $ this ->parseTag ($ tokens );
95100 $ endLine = $ tokens ->currentTokenLine ();
101+ $ endIndex = $ tokens ->currentTokenIndex ();
96102
97103 if ($ this ->useLinesAttributes ) {
98104 $ tag ->setAttribute (Ast \Attribute::START_LINE , $ startLine );
99105 $ tag ->setAttribute (Ast \Attribute::END_LINE , $ endLine );
100106 }
101107
108+ if ($ this ->useIndexAttributes ) {
109+ $ tag ->setAttribute (Ast \Attribute::START_INDEX , $ startIndex );
110+ $ tag ->setAttribute (Ast \Attribute::END_INDEX , $ endIndex );
111+ }
112+
102113 return $ tag ;
103114 }
104115
105116 $ startLine = $ tokens ->currentTokenLine ();
117+ $ startIndex = $ tokens ->currentTokenIndex ();
106118 $ text = $ this ->parseText ($ tokens );
107119 $ endLine = $ tokens ->currentTokenLine ();
120+ $ endIndex = $ tokens ->currentTokenIndex ();
108121
109122 if ($ this ->useLinesAttributes ) {
110123 $ text ->setAttribute (Ast \Attribute::START_LINE , $ startLine );
111124 $ text ->setAttribute (Ast \Attribute::END_LINE , $ endLine );
112125 }
113126
127+ if ($ this ->useIndexAttributes ) {
128+ $ text ->setAttribute (Ast \Attribute::START_INDEX , $ startIndex );
129+ $ text ->setAttribute (Ast \Attribute::END_INDEX , $ endIndex );
130+ }
131+
114132 return $ text ;
115133 }
116134
@@ -155,6 +173,7 @@ public function parseTag(TokenIterator $tokens): Ast\PhpDoc\PhpDocTagNode
155173 public function parseTagValue (TokenIterator $ tokens , string $ tag ): Ast \PhpDoc \PhpDocTagValueNode
156174 {
157175 $ startLine = $ tokens ->currentTokenLine ();
176+ $ startIndex = $ tokens ->currentTokenIndex ();
158177
159178 try {
160179 $ tokens ->pushSavePoint ();
@@ -284,12 +303,18 @@ public function parseTagValue(TokenIterator $tokens, string $tag): Ast\PhpDoc\Ph
284303 }
285304
286305 $ endLine = $ tokens ->currentTokenLine ();
306+ $ endIndex = $ tokens ->currentTokenIndex ();
287307
288308 if ($ this ->useLinesAttributes ) {
289309 $ tagValue ->setAttribute (Ast \Attribute::START_LINE , $ startLine );
290310 $ tagValue ->setAttribute (Ast \Attribute::END_LINE , $ endLine );
291311 }
292312
313+ if ($ this ->useIndexAttributes ) {
314+ $ tagValue ->setAttribute (Ast \Attribute::START_INDEX , $ startIndex );
315+ $ tagValue ->setAttribute (Ast \Attribute::END_INDEX , $ endIndex );
316+ }
317+
293318 return $ tagValue ;
294319 }
295320
0 commit comments