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 7e913103634855449dd58c091f34a7a6a2990b6f..1fa0959b1eaed845565fa9e5a8d300e31990b500 100644 |
--- a/pkg/analyzer/lib/src/generated/parser.dart |
+++ b/pkg/analyzer/lib/src/generated/parser.dart |
@@ -3964,7 +3964,7 @@ class Parser { |
* | fieldFormalParameter |
* | simpleFormalParameter |
* |
- * functionSignature: |
+ * legacyFunctionSignature: |
* metadata returnType? identifier typeParameters? formalParameterList |
* |
* fieldFormalParameter ::= |
@@ -4823,10 +4823,20 @@ class Parser { |
* qualified withClause implementsClause? ';' |
* |
* functionTypeAlias ::= |
+ * legacyFunctionTypeAlias | |
+ * newFunctionTypeAlias |
+ * |
+ * legacyFunctionTypeAlias ::= |
* functionPrefix typeParameterList? formalParameterList ';' |
* |
* functionPrefix ::= |
* returnType? name |
+ * |
+ * newFunctionTypeAlias ::= |
+ * identifier typeParameters? '=' functionType ';' |
+ * |
+ * functionType ::= typeParameterList? formalParameterList '-' '>' returnType |
Lasse Reichstein Nielsen
2016/10/20 19:36:44
I assume you use '-' '>' instead of '->' because i
floitsch
2016/10/21 12:24:34
correct.
|
+ * |
*/ |
TypeAlias parseTypeAlias(CommentAndMetadata commentAndMetadata) { |
Token keyword = getAndAdvance(); |
@@ -4835,6 +4845,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( |
@@ -4842,6 +4864,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( |
@@ -5322,7 +5355,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(); |
Lasse Reichstein Nielsen
2016/10/20 19:36:44
Using the old formal-parameter list, so a single i
floitsch
2016/10/21 12:24:34
Right.
I wanted to see how hard it would be to ch
|
+ } 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); |
} |