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

Side by Side 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, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library fasta.parser.parser; 5 library fasta.parser.parser;
6 6
7 import '../fasta_codes.dart' 7 import '../fasta_codes.dart'
8 show 8 show
9 FastaCode, 9 FastaCode,
10 FastaMessage, 10 FastaMessage,
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 } else { 510 } else {
511 token = parseLiteralStringOrRecoverExpression(token); 511 token = parseLiteralStringOrRecoverExpression(token);
512 } 512 }
513 Token semicolon = token; 513 Token semicolon = token;
514 token = expect(';', token); 514 token = expect(';', token);
515 listener.endPartOf(partKeyword, semicolon, hasName); 515 listener.endPartOf(partKeyword, semicolon, hasName);
516 return token; 516 return token;
517 } 517 }
518 518
519 Token parseMetadataStar(Token token, {bool forParameter: false}) { 519 Token parseMetadataStar(Token token, {bool forParameter: false}) {
520 token = listener.injectGenericCommentTypeAssign(token);
520 listener.beginMetadataStar(token); 521 listener.beginMetadataStar(token);
521 int count = 0; 522 int count = 0;
522 while (optional('@', token)) { 523 while (optional('@', token)) {
523 token = parseMetadata(token); 524 token = parseMetadata(token);
524 count++; 525 count++;
525 } 526 }
526 listener.endMetadataStar(count, forParameter); 527 listener.endMetadataStar(count, forParameter);
527 return token; 528 return token;
528 } 529 }
529 530
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
1135 token, IdentifierContext.typeReferenceContinuation); 1136 token, IdentifierContext.typeReferenceContinuation);
1136 } else { 1137 } else {
1137 token = 1138 token =
1138 reportUnrecoverableErrorCodeWithToken(token, codeExpectedType).next; 1139 reportUnrecoverableErrorCodeWithToken(token, codeExpectedType).next;
1139 listener.handleInvalidTypeReference(token); 1140 listener.handleInvalidTypeReference(token);
1140 } 1141 }
1141 token = parseTypeArgumentsOpt(token); 1142 token = parseTypeArgumentsOpt(token);
1142 listener.handleType(begin, token); 1143 listener.handleType(begin, token);
1143 } 1144 }
1144 1145
1146 {
1147 Token newBegin =
1148 listener.replaceTokenWithGenericCommentTypeAssign(begin, token);
1149 if (!identical(newBegin, begin)) {
1150 listener.discardTypeReplacedWithCommentTypeAssign();
1151 return parseType(newBegin);
1152 }
1153 }
1154
1145 // While we see a `Function(` treat the pushed type as return type. 1155 // While we see a `Function(` treat the pushed type as return type.
1146 // For example: `int Function() Function(int) Function(String x)`. 1156 // For example: `int Function() Function(int) Function(String x)`.
1147 while (isGeneralizedFunctionType(token)) { 1157 while (isGeneralizedFunctionType(token)) {
1148 token = parseFunctionType(token); 1158 token = parseFunctionType(token);
1149 } 1159 }
1150 return token; 1160 return token;
1151 } 1161 }
1152 1162
1153 /// Parses a generalized function type. 1163 /// Parses a generalized function type.
1154 /// 1164 ///
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
1538 return listener.handleMemberName(identifiers); 1548 return listener.handleMemberName(identifiers);
1539 } else if (optional("=", token) || 1549 } else if (optional("=", token) ||
1540 optional(";", token) || 1550 optional(";", token) ||
1541 optional(",", token)) { 1551 optional(",", token)) {
1542 // A field or abstract getter. 1552 // A field or abstract getter.
1543 identifiers = identifiers.prepend(token); 1553 identifiers = identifiers.prepend(token);
1544 return listener.handleMemberName(identifiers); 1554 return listener.handleMemberName(identifiers);
1545 } else if (isGetter) { 1555 } else if (isGetter) {
1546 hasName = true; 1556 hasName = true;
1547 } 1557 }
1558 token = listener.injectGenericCommentTypeAssign(token);
1548 identifiers = identifiers.prepend(token); 1559 identifiers = identifiers.prepend(token);
1549 1560
1550 if (!isGeneralizedFunctionType(token)) { 1561 if (!isGeneralizedFunctionType(token)) {
1551 // Read a potential return type. 1562 // Read a potential return type.
1552 if (isValidTypeReference(token)) { 1563 if (isValidTypeReference(token)) {
1564 Token type = token;
1553 // type ... 1565 // type ...
1554 if (optional('.', token.next)) { 1566 if (optional('.', token.next)) {
1555 // type '.' ... 1567 // type '.' ...
1556 if (token.next.next.isIdentifier) { 1568 if (token.next.next.isIdentifier) {
1557 // type '.' identifier 1569 // type '.' identifier
1558 token = token.next.next; 1570 token = token.next.next;
1559 } 1571 }
1560 } 1572 }
1561 if (optional('<', token.next)) { 1573 if (optional('<', token.next)) {
1562 if (token.next is BeginGroupToken) { 1574 if (token.next is BeginGroupToken) {
1563 BeginGroupToken beginGroup = token.next; 1575 BeginGroupToken beginGroup = token.next;
1564 if (beginGroup.endGroup == null) { 1576 if (beginGroup.endGroup == null) {
1565 token = reportUnmatchedToken(beginGroup).next; 1577 token = reportUnmatchedToken(beginGroup).next;
1566 } else { 1578 } else {
1567 token = beginGroup.endGroup; 1579 token = beginGroup.endGroup;
1568 } 1580 }
1569 } 1581 }
1570 } 1582 }
1583 // If the next token after a type has a type substitution comment
1584 // /*=T*/, then the previous type tokens and the reference to them
1585 // from the link should be replaced.
1586 {
1587 Token newType = listener.replaceTokenWithGenericCommentTypeAssign(
1588 type, token.next);
1589 if (!identical(newType, type)) {
1590 identifiers = identifiers.tail;
1591 token = newType;
1592 continue;
1593 }
1594 }
1571 } 1595 }
1572 token = token.next; 1596 token = token.next;
1573 } 1597 }
1574 while (isGeneralizedFunctionType(token)) { 1598 while (isGeneralizedFunctionType(token)) {
1575 token = token.next; 1599 token = token.next;
1576 if (optional('<', token)) { 1600 if (optional('<', token)) {
1577 if (token is BeginGroupToken) { 1601 if (token is BeginGroupToken) {
1578 BeginGroupToken beginGroup = token; 1602 BeginGroupToken beginGroup = token;
1579 if (beginGroup.endGroup == null) { 1603 if (beginGroup.endGroup == null) {
1580 token = reportUnmatchedToken(beginGroup).next; 1604 token = reportUnmatchedToken(beginGroup).next;
(...skipping 2312 matching lines...) Expand 10 before | Expand all | Expand 10 after
3893 return reportUnrecoverableError( 3917 return reportUnrecoverableError(
3894 token, () => code.format(uri, token.charOffset, string)); 3918 token, () => code.format(uri, token.charOffset, string));
3895 } 3919 }
3896 } 3920 }
3897 3921
3898 typedef FastaMessage NoArgument(Uri uri, int charOffset); 3922 typedef FastaMessage NoArgument(Uri uri, int charOffset);
3899 3923
3900 typedef FastaMessage TokenArgument(Uri uri, int charOffset, Token token); 3924 typedef FastaMessage TokenArgument(Uri uri, int charOffset, Token token);
3901 3925
3902 typedef FastaMessage StringArgument(Uri uri, int charOffset, String string); 3926 typedef FastaMessage StringArgument(Uri uri, int charOffset, String string);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698