@@ -133,7 +133,7 @@ class CommentReferenceParser {
133
133
if (suffixResult.type == _SuffixResultType .notSuffix) {
134
134
// Invalid trailing junk; reject the reference.
135
135
return [];
136
- } else if (suffixResult.type == _SuffixResultType .parsedConstructorHint ) {
136
+ } else if (suffixResult.type == _SuffixResultType .parsedCallableHint ) {
137
137
children.add (suffixResult.node);
138
138
}
139
139
@@ -142,7 +142,6 @@ class CommentReferenceParser {
142
142
}
143
143
144
144
static const _constructorHintPrefix = 'new' ;
145
-
146
145
static const _ignorePrefixes = ['const' , 'final' , 'var' ];
147
146
148
147
/// Implement parsing a prefix to a comment reference.
@@ -153,17 +152,19 @@ class CommentReferenceParser {
153
152
///
154
153
/// <constructorPrefixHint> ::= 'new '
155
154
///
156
- /// <leadingJunk> ::= ('const' | 'final' | 'var' | 'operator' )(' '+)
155
+ /// <leadingJunk> ::= ('const' | 'final' | 'var')(' '+)
157
156
/// ```
158
157
_PrefixParseResult _parsePrefix () {
159
158
if (_atEnd) {
160
159
return _PrefixParseResult .endOfFile;
161
160
}
162
- if (_tryMatchLiteral (_constructorHintPrefix)) {
161
+ if (_tryMatchLiteral (_constructorHintPrefix,
162
+ requireTrailingNonidentifier: true )) {
163
163
return _PrefixParseResult .ok (
164
164
ConstructorHintStartNode (_constructorHintPrefix));
165
165
}
166
- if (_ignorePrefixes.any ((p) => _tryMatchLiteral (p))) {
166
+ if (_ignorePrefixes
167
+ .any ((p) => _tryMatchLiteral (p, requireTrailingNonidentifier: true ))) {
167
168
return _PrefixParseResult .junk;
168
169
}
169
170
@@ -234,10 +235,10 @@ class CommentReferenceParser {
234
235
IdentifierNode (codeRef.substring (startIndex, _index)));
235
236
}
236
237
237
- static const _constructorHintSuffix = '()' ;
238
+ static const _callableHintSuffix = '()' ;
238
239
239
240
/// ```text
240
- /// <suffix> ::= <constructorPostfixHint >
241
+ /// <suffix> ::= <callableHintSuffix >
241
242
/// | <trailingJunk>
242
243
///
243
244
/// <trailingJunk> ::= '<'<CHARACTER>*'>'
@@ -246,18 +247,18 @@ class CommentReferenceParser {
246
247
/// | '?'
247
248
/// | '!'
248
249
///
249
- /// <constructorPostfixHint > ::= '()'
250
+ /// <callableHintSuffix > ::= '()'
250
251
/// ```
251
252
_SuffixParseResult _parseSuffix () {
252
253
var startIndex = _index;
253
254
_walkPastWhitespace ();
254
255
if (_atEnd) {
255
256
return _SuffixParseResult .missing;
256
257
}
257
- if (_tryMatchLiteral (_constructorHintSuffix )) {
258
+ if (_tryMatchLiteral (_callableHintSuffix )) {
258
259
if (_atEnd) {
259
260
return _SuffixParseResult .ok (
260
- ConstructorHintEndNode (codeRef.substring (startIndex, _index)));
261
+ CallableHintEndNode (codeRef.substring (startIndex, _index)));
261
262
}
262
263
return _SuffixParseResult .notSuffix;
263
264
}
@@ -278,10 +279,12 @@ class CommentReferenceParser {
278
279
279
280
/// Advances [_index] on match, preserves on non-match.
280
281
bool _tryMatchLiteral (String characters,
281
- {bool acceptTrailingWhitespace = true }) {
282
+ {bool acceptTrailingWhitespace = true ,
283
+ bool requireTrailingNonidentifier = false }) {
282
284
assert (acceptTrailingWhitespace != null );
283
285
if (characters.length + _index > _referenceLength) return false ;
284
- for (var startIndex = _index;
286
+ int startIndex;
287
+ for (startIndex = _index;
285
288
_index - startIndex < characters.length;
286
289
_index++ ) {
287
290
if (codeRef.codeUnitAt (_index) !=
@@ -290,6 +293,12 @@ class CommentReferenceParser {
290
293
return false ;
291
294
}
292
295
}
296
+ if (requireTrailingNonidentifier) {
297
+ if (_atEnd || ! _nonIdentifierChars.contains (_thisChar)) {
298
+ _index = startIndex;
299
+ return false ;
300
+ }
301
+ }
293
302
if (acceptTrailingWhitespace) _walkPastWhitespace ();
294
303
return true ;
295
304
}
@@ -386,10 +395,10 @@ enum _SuffixResultType {
386
395
junk, // Found known types of junk it is OK to ignore.
387
396
missing, // There is no suffix here. Same as EOF as this is a suffix.
388
397
notSuffix, // Found something, but not a valid suffix.
389
- parsedConstructorHint , // Parsed a [ConstructorHintEndNode ].
398
+ parsedCallableHint , // Parsed a [CallableHintEndNode ].
390
399
}
391
400
392
- /// The result of attempting to parse a prefix to a comment reference.
401
+ /// The result of attempting to parse a suffix to a comment reference.
393
402
class _SuffixParseResult {
394
403
final _SuffixResultType type;
395
404
@@ -398,7 +407,7 @@ class _SuffixParseResult {
398
407
const _SuffixParseResult ._(this .type, this .node);
399
408
400
409
factory _SuffixParseResult .ok (CommentReferenceNode node) =>
401
- _SuffixParseResult ._(_SuffixResultType .parsedConstructorHint , node);
410
+ _SuffixParseResult ._(_SuffixResultType .parsedCallableHint , node);
402
411
403
412
static const _SuffixParseResult junk =
404
413
_SuffixParseResult ._(_SuffixResultType .junk, null );
@@ -426,14 +435,14 @@ class ConstructorHintStartNode extends CommentReferenceNode {
426
435
String toString () => 'ConstructorHintStartNode["$text "]' ;
427
436
}
428
437
429
- class ConstructorHintEndNode extends CommentReferenceNode {
438
+ class CallableHintEndNode extends CommentReferenceNode {
430
439
@override
431
440
final String text;
432
441
433
- ConstructorHintEndNode (this .text);
442
+ CallableHintEndNode (this .text);
434
443
435
444
@override
436
- String toString () => 'ConstructorHintEndNode ["$text "]' ;
445
+ String toString () => 'CallableHintEndNode ["$text "]' ;
437
446
}
438
447
439
448
/// Represents an identifier.
0 commit comments