@@ -34,8 +34,11 @@ class PhpDocParser
34
34
/** @var bool */
35
35
private $ useLinesAttributes ;
36
36
37
+ /** @var bool */
38
+ private $ useIndexAttributes ;
39
+
37
40
/**
38
- * @param array{lines?: bool} $usedAttributes
41
+ * @param array{lines?: bool, indexes?: bool } $usedAttributes
39
42
*/
40
43
public function __construct (
41
44
TypeParser $ typeParser ,
@@ -50,6 +53,7 @@ public function __construct(
50
53
$ this ->requireWhitespaceBeforeDescription = $ requireWhitespaceBeforeDescription ;
51
54
$ this ->preserveTypeAliasesWithInvalidTypes = $ preserveTypeAliasesWithInvalidTypes ;
52
55
$ this ->useLinesAttributes = $ usedAttributes ['lines ' ] ?? false ;
56
+ $ this ->useIndexAttributes = $ usedAttributes ['indexes ' ] ?? false ;
53
57
}
54
58
55
59
@@ -91,26 +95,40 @@ private function parseChild(TokenIterator $tokens): Ast\PhpDoc\PhpDocChildNode
91
95
{
92
96
if ($ tokens ->isCurrentTokenType (Lexer::TOKEN_PHPDOC_TAG )) {
93
97
$ startLine = $ tokens ->currentTokenLine ();
98
+ $ startIndex = $ tokens ->currentTokenIndex ();
94
99
$ tag = $ this ->parseTag ($ tokens );
95
100
$ endLine = $ tokens ->currentTokenLine ();
101
+ $ endIndex = $ tokens ->currentTokenIndex ();
96
102
97
103
if ($ this ->useLinesAttributes ) {
98
104
$ tag ->setAttribute (Ast \Attribute::START_LINE , $ startLine );
99
105
$ tag ->setAttribute (Ast \Attribute::END_LINE , $ endLine );
100
106
}
101
107
108
+ if ($ this ->useIndexAttributes ) {
109
+ $ tag ->setAttribute (Ast \Attribute::START_INDEX , $ startIndex );
110
+ $ tag ->setAttribute (Ast \Attribute::END_INDEX , $ endIndex );
111
+ }
112
+
102
113
return $ tag ;
103
114
}
104
115
105
116
$ startLine = $ tokens ->currentTokenLine ();
117
+ $ startIndex = $ tokens ->currentTokenIndex ();
106
118
$ text = $ this ->parseText ($ tokens );
107
119
$ endLine = $ tokens ->currentTokenLine ();
120
+ $ endIndex = $ tokens ->currentTokenIndex ();
108
121
109
122
if ($ this ->useLinesAttributes ) {
110
123
$ text ->setAttribute (Ast \Attribute::START_LINE , $ startLine );
111
124
$ text ->setAttribute (Ast \Attribute::END_LINE , $ endLine );
112
125
}
113
126
127
+ if ($ this ->useIndexAttributes ) {
128
+ $ text ->setAttribute (Ast \Attribute::START_INDEX , $ startIndex );
129
+ $ text ->setAttribute (Ast \Attribute::END_INDEX , $ endIndex );
130
+ }
131
+
114
132
return $ text ;
115
133
}
116
134
@@ -155,6 +173,7 @@ public function parseTag(TokenIterator $tokens): Ast\PhpDoc\PhpDocTagNode
155
173
public function parseTagValue (TokenIterator $ tokens , string $ tag ): Ast \PhpDoc \PhpDocTagValueNode
156
174
{
157
175
$ startLine = $ tokens ->currentTokenLine ();
176
+ $ startIndex = $ tokens ->currentTokenIndex ();
158
177
159
178
try {
160
179
$ tokens ->pushSavePoint ();
@@ -284,12 +303,18 @@ public function parseTagValue(TokenIterator $tokens, string $tag): Ast\PhpDoc\Ph
284
303
}
285
304
286
305
$ endLine = $ tokens ->currentTokenLine ();
306
+ $ endIndex = $ tokens ->currentTokenIndex ();
287
307
288
308
if ($ this ->useLinesAttributes ) {
289
309
$ tagValue ->setAttribute (Ast \Attribute::START_LINE , $ startLine );
290
310
$ tagValue ->setAttribute (Ast \Attribute::END_LINE , $ endLine );
291
311
}
292
312
313
+ if ($ this ->useIndexAttributes ) {
314
+ $ tagValue ->setAttribute (Ast \Attribute::START_INDEX , $ startIndex );
315
+ $ tagValue ->setAttribute (Ast \Attribute::END_INDEX , $ endIndex );
316
+ }
317
+
293
318
return $ tagValue ;
294
319
}
295
320
0 commit comments