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

Unified Diff: pkg/analyzer/lib/src/generated/parser.dart

Issue 2466393002: Change to <- for types.
Patch Set: Fixes. Created 4 years, 1 month 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
« no previous file with comments | « no previous file | pkg/compiler/lib/compiler.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/generated/parser.dart
diff --git a/pkg/analyzer/lib/src/generated/parser.dart b/pkg/analyzer/lib/src/generated/parser.dart
index d9e8d6e841f1b31a9f959bb4a71b9d2db07fa5e2..d57c1e92e68ecc720b280d3d196409bb4601280c 100644
--- a/pkg/analyzer/lib/src/generated/parser.dart
+++ b/pkg/analyzer/lib/src/generated/parser.dart
@@ -3961,7 +3961,7 @@ class Parser {
* | fieldFormalParameter
* | simpleFormalParameter
*
- * functionSignature:
+ * legacyFunctionSignature:
* metadata returnType? identifier typeParameters? formalParameterList
*
* fieldFormalParameter ::=
@@ -4822,10 +4822,20 @@ class Parser {
* qualified withClause implementsClause? ';'
*
* functionTypeAlias ::=
+ * legacyFunctionTypeAlias |
+ * newFunctionTypeAlias
+ *
+ * legacyFunctionTypeAlias ::=
* functionPrefix typeParameterList? formalParameterList ';'
*
* functionPrefix ::=
* returnType? name
+ *
+ * newFunctionTypeAlias ::=
+ * identifier typeParameters? '=' functionType ';'
+ *
+ * functionType ::= typeParameterList? formalParameterList '-' '>' returnType
+ *
*/
TypeAlias parseTypeAlias(CommentAndMetadata commentAndMetadata) {
Token keyword = getAndAdvance();
@@ -4834,6 +4844,18 @@ class Parser {
if (_tokenMatches(next, TokenType.LT)) {
next = _skipTypeParameterList(next);
if (next != null && _tokenMatches(next, TokenType.EQ)) {
+ next = next.next;
+ if (next != null &&
+ (_tokenMatches(next, TokenType.LT) ||
+ _tokenMatches(next, TokenType.OPEN_PAREN))) {
+ return _parseNewFunctionTypeAlias(commentAndMetadata, keyword);
+ }
+ if (next != null && _tokenMatches(next, TokenType.IDENTIFIER)) {
+ next = next.next;
+ if (next != null && _tokenMatches(next, TokenType.MINUS)) {
+ return _parseNewFunctionTypeAlias(commentAndMetadata, keyword);
+ }
+ }
TypeAlias typeAlias =
parseClassTypeAlias(commentAndMetadata, null, keyword);
_reportErrorForToken(
@@ -4841,6 +4863,17 @@ class Parser {
return typeAlias;
}
} else if (_tokenMatches(next, TokenType.EQ)) {
+ next = next.next;
+ if (next != null &&
+ (_tokenMatches(next, TokenType.LT) ||
+ _tokenMatches(next, TokenType.OPEN_PAREN))) {
+ return _parseNewFunctionTypeAlias(commentAndMetadata, keyword);
+ } else if (next != null && _tokenMatches(next, TokenType.IDENTIFIER)) {
+ next = next.next;
+ if (next != null && _tokenMatches(next, TokenType.MINUS)) {
+ return _parseNewFunctionTypeAlias(commentAndMetadata, keyword);
+ }
+ }
TypeAlias typeAlias =
parseClassTypeAlias(commentAndMetadata, null, keyword);
_reportErrorForToken(
@@ -5321,7 +5354,20 @@ class Parser {
* qualified typeArguments?
*/
Token skipTypeName(Token startToken) {
- Token token = skipPrefixedIdentifier(startToken);
+ Token token;
+ if (_tokenMatches(startToken, TokenType.LT)) {
+ token = skipTypeArgumentList(token);
+ if (token == null) return null;
+ token = _skipFormalParameterList(token);
+ if (token == null) return null;
+ if (!_tokenMatches(token, TokenType.MINUS)) return null;
+ token = token.next;
+ if (token == null) return null;
+ if (!_tokenMatches(token, TokenType.GT)) return null;
+ return skipTypeName(token);
+ }
+
+ token = skipPrefixedIdentifier(startToken);
if (token == null) {
return null;
}
@@ -6517,6 +6563,68 @@ class Parser {
return new FunctionDeclarationStatement(declaration);
}
+ FunctionTypeAlias _parseNewFunctionTypeAlias(CommentAndMetadata commentAndMetadata, Token keyword) {
+ SimpleIdentifier name = parseSimpleIdentifier(isDeclaration: true);
+ TypeParameterList typeParameters = null;
+ if (_matches(TokenType.LT)) {
+ typeParameters = parseTypeParameterList();
+ }
+
+ _expect(TokenType.EQ); // TODO(floitsch): store the sign in the node.
+
+ if (_matches(TokenType.LT)) {
+ parseTypeParameterList(); // TODO(floitsch): store the generic arguments.
+ }
+
+
+ TokenType type = _currentToken.type;
+
+ if (type == TokenType.OPEN_PAREN || type == TokenType.IDENTIFIER) {
+ FormalParameterList parameters;
+ if (type == TokenType.OPEN_PAREN) {
+ parameters = _parseFormalParameterListUnchecked();
+ } else {
+ var parameter = parseNormalFormalParameter();
+ parameters = new FormalParameterList(
+ _createSyntheticToken(TokenType.OPEN_PAREN),
+ [parameter], null, null,
+ _createSyntheticToken(TokenType.CLOSE_PAREN));
+ }
+ _validateFormalParameterList(parameters);
+
+ _expect(TokenType.MINUS);
+ _expect(TokenType.GT);
+
+ TypeName returnType = parseReturnType();
+
+ Token semicolon = _expect(TokenType.SEMICOLON);
+ return new FunctionTypeAlias(
+ commentAndMetadata.comment,
+ commentAndMetadata.metadata,
+ keyword,
+ returnType,
+ name,
+ typeParameters,
+ parameters,
+ semicolon);
+ } else {
+ _reportErrorForCurrentToken(ParserErrorCode.MISSING_TYPEDEF_PARAMETERS);
+ // Recovery: At the very least we should skip to the start of the next
+ // valid compilation unit member, allowing for the possibility of finding
+ // the typedef parameters before that point.
+ return new FunctionTypeAlias(
+ commentAndMetadata.comment,
+ commentAndMetadata.metadata,
+ keyword,
+ null,
+ name,
+ typeParameters,
+ new FormalParameterList(_createSyntheticToken(TokenType.OPEN_PAREN),
+ null, null, null, _createSyntheticToken(TokenType.CLOSE_PAREN)),
+ _createSyntheticToken(TokenType.SEMICOLON));
+ }
+ }
+
/**
* Parse a function type alias. The [commentAndMetadata] is the metadata to be
* associated with the member. The [keyword] is the token representing the
@@ -7231,6 +7339,7 @@ class Parser {
*/
void _reportErrorForCurrentToken(ParserErrorCode errorCode,
[List<Object> arguments]) {
+ print("error ${StackTrace.current}");
_reportErrorForToken(errorCode, _currentToken, arguments);
}
« no previous file with comments | « no previous file | pkg/compiler/lib/compiler.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698