Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(704)

Unified Diff: pkg/front_end/lib/src/fasta/parser/parser.dart

Issue 2856463004: New tests and improvements for generics in comments parsing. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/front_end/lib/src/fasta/parser/parser.dart
diff --git a/pkg/front_end/lib/src/fasta/parser/parser.dart b/pkg/front_end/lib/src/fasta/parser/parser.dart
index acec92be80e8ae60b02522adc03bb84f7705175b..f1cf87e4b4b12e43085c0b7fbda53a6b45c56033 100644
--- a/pkg/front_end/lib/src/fasta/parser/parser.dart
+++ b/pkg/front_end/lib/src/fasta/parser/parser.dart
@@ -517,6 +517,7 @@ class Parser {
}
Token parseMetadataStar(Token token, {bool forParameter: false}) {
+ token = listener.injectGenericCommentTypeAssign(token);
listener.beginMetadataStar(token);
int count = 0;
while (optional('@', token)) {
@@ -1142,6 +1143,15 @@ class Parser {
listener.handleType(begin, token);
}
+ {
+ Token newBegin =
+ listener.replaceTokenWithGenericCommentTypeAssign(begin, token);
+ if (!identical(newBegin, begin)) {
+ listener.discardTypeReplacedWithCommentTypeAssign();
+ return parseType(newBegin);
+ }
+ }
+
// While we see a `Function(` treat the pushed type as return type.
// For example: `int Function() Function(int) Function(String x)`.
while (isGeneralizedFunctionType(token)) {
@@ -1545,11 +1555,13 @@ class Parser {
} else if (isGetter) {
hasName = true;
}
+ token = listener.injectGenericCommentTypeAssign(token);
identifiers = identifiers.prepend(token);
if (!isGeneralizedFunctionType(token)) {
// Read a potential return type.
if (isValidTypeReference(token)) {
+ Token type = token;
// type ...
if (optional('.', token.next)) {
// type '.' ...
@@ -1568,6 +1580,18 @@ class Parser {
}
}
}
+ // If the next token after a type has a type substitution comment
+ // /*=T*/, then the previous type tokens and the reference to them
+ // from the link should be replaced.
+ {
+ Token newType = listener.replaceTokenWithGenericCommentTypeAssign(
+ type, token.next);
+ if (!identical(newType, type)) {
+ identifiers = identifiers.tail;
+ token = newType;
+ continue;
+ }
+ }
}
token = token.next;
}

Powered by Google App Engine
This is Rietveld 408576698