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

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

Issue 2817753002: More parser fixes for generic function types (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
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/parser_test.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 ea555a569a305cacc769e3b6a14d38730087a094..64aa175f734e3855fd87a69cb5cf48acd896c4c0 100644
--- a/pkg/analyzer/lib/src/generated/parser.dart
+++ b/pkg/analyzer/lib/src/generated/parser.dart
@@ -424,6 +424,10 @@ class Parser {
return true;
}
Token afterReturnType = skipTypeName(_currentToken);
+ if (afterReturnType != null &&
+ _tokenMatchesKeyword(afterReturnType, Keyword.FUNCTION)) {
+ afterReturnType = skipGenericFunctionTypeAfterReturnType(afterReturnType);
+ }
if (afterReturnType == null) {
// There was no return type, but it is optional, so go back to where we
// started.
@@ -538,6 +542,9 @@ class Parser {
// There was no type name, so this can't be a declaration.
return false;
}
+ if (_tokenMatchesKeyword(token, Keyword.FUNCTION)) {
+ token = skipGenericFunctionTypeAfterReturnType(token);
+ }
if (token.type != TokenType.IDENTIFIER) {
allowAdditionalTokens = false;
}
@@ -1272,28 +1279,25 @@ class Parser {
_validateModifiersForGetterOrSetterOrMethod(modifiers);
return _parseMethodDeclarationAfterReturnType(commentAndMetadata,
modifiers.externalKeyword, modifiers.staticKeyword, returnType);
- } else {
- //
- // We have found an error of some kind. Try to recover.
- //
- if (_matchesIdentifier()) {
- if (_peek().matchesAny(const <TokenType>[
+ } else if (_matchesIdentifier() &&
+ _peek().matchesAny(const <TokenType>[
TokenType.EQ,
TokenType.COMMA,
TokenType.SEMICOLON
])) {
- //
- // We appear to have a variable declaration with a type of "void".
- //
- _reportErrorForNode(ParserErrorCode.VOID_VARIABLE, returnType);
- return parseInitializedIdentifierList(
- commentAndMetadata,
- modifiers.staticKeyword,
- modifiers.covariantKeyword,
- _validateModifiersForField(modifiers),
- returnType);
- }
+ if (returnType is! GenericFunctionType) {
+ _reportErrorForNode(ParserErrorCode.VOID_VARIABLE, returnType);
}
+ return parseInitializedIdentifierList(
+ commentAndMetadata,
+ modifiers.staticKeyword,
+ modifiers.covariantKeyword,
+ _validateModifiersForField(modifiers),
+ returnType);
+ } else {
+ //
+ // We have found an error of some kind. Try to recover.
+ //
if (_isOperator(_currentToken)) {
//
// We appear to have found an operator declaration without the
@@ -2078,28 +2082,25 @@ class Parser {
_validateModifiersForTopLevelFunction(modifiers);
return parseFunctionDeclaration(
commentAndMetadata, modifiers.externalKeyword, returnType);
- } else {
- //
- // We have found an error of some kind. Try to recover.
- //
- if (_matchesIdentifier()) {
- if (next.matchesAny(const <TokenType>[
+ } else if (_matchesIdentifier() &&
+ next.matchesAny(const <TokenType>[
TokenType.EQ,
TokenType.COMMA,
TokenType.SEMICOLON
])) {
- //
- // We appear to have a variable declaration with a type of "void".
- //
- _reportErrorForNode(ParserErrorCode.VOID_VARIABLE, returnType);
- return astFactory.topLevelVariableDeclaration(
- commentAndMetadata.comment,
- commentAndMetadata.metadata,
- parseVariableDeclarationListAfterType(null,
- _validateModifiersForTopLevelVariable(modifiers), null),
- _expect(TokenType.SEMICOLON));
- }
+ if (returnType is! GenericFunctionType) {
+ _reportErrorForNode(ParserErrorCode.VOID_VARIABLE, returnType);
}
+ return astFactory.topLevelVariableDeclaration(
+ commentAndMetadata.comment,
+ commentAndMetadata.metadata,
+ parseVariableDeclarationListAfterType(
+ null, _validateModifiersForTopLevelVariable(modifiers), null),
+ _expect(TokenType.SEMICOLON));
+ } else {
+ //
+ // We have found an error of some kind. Try to recover.
+ //
_reportErrorForToken(
ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken);
return null;
@@ -4138,24 +4139,22 @@ class Parser {
])) {
return _parseFunctionDeclarationStatementAfterReturnType(
commentAndMetadata, returnType);
- } else {
- //
- // We have found an error of some kind. Try to recover.
- //
- if (_matchesIdentifier()) {
- if (next.matchesAny(const <TokenType>[
+ } else if (_matchesIdentifier() &&
+ next.matchesAny(const <TokenType>[
TokenType.EQ,
TokenType.COMMA,
TokenType.SEMICOLON
])) {
- //
- // We appear to have a variable declaration with a type of "void".
- //
- _reportErrorForNode(ParserErrorCode.VOID_VARIABLE, returnType);
- return parseVariableDeclarationStatementAfterMetadata(
- commentAndMetadata);
- }
- } else if (_matches(TokenType.CLOSE_CURLY_BRACKET)) {
+ if (returnType is! GenericFunctionType) {
+ _reportErrorForNode(ParserErrorCode.VOID_VARIABLE, returnType);
+ }
+ return _parseVariableDeclarationStatementAfterType(
+ commentAndMetadata, null, returnType);
+ } else {
+ //
+ // We have found an error of some kind. Try to recover.
+ //
+ if (_matches(TokenType.CLOSE_CURLY_BRACKET)) {
//
// We appear to have found an incomplete statement at the end of a
// block. Parse it as a variable declaration.
@@ -5484,7 +5483,7 @@ class Parser {
if (!_tokenMatches(startToken, TokenType.OPEN_PAREN)) {
return null;
}
- return (startToken as BeginToken).endToken;
+ return (startToken as BeginToken).endToken.next;
}
/**
@@ -7597,7 +7596,9 @@ class Parser {
* variableDeclarationList ';'
*/
VariableDeclarationStatement _parseVariableDeclarationStatementAfterType(
- CommentAndMetadata commentAndMetadata, Token keyword, TypeName type) {
+ CommentAndMetadata commentAndMetadata,
+ Token keyword,
+ TypeAnnotation type) {
VariableDeclarationList variableList =
parseVariableDeclarationListAfterType(
commentAndMetadata, keyword, type);
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/parser_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698