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

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

Issue 2744043002: Improve recovery in argument lists when missing a comma before a named argument (issue 29005) (Closed)
Patch Set: Created 3 years, 9 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 1ccc89f9ecd4cb8b8fbc2d7de39d1319a3b055c9..54ee4aba13e23e22618a9eb4036c239bb23cf5e9 100644
--- a/pkg/analyzer/lib/src/generated/parser.dart
+++ b/pkg/analyzer/lib/src/generated/parser.dart
@@ -685,6 +685,24 @@ class Parser {
if (_matches(TokenType.CLOSE_PAREN)) {
return astFactory.argumentList(leftParenthesis, null, getAndAdvance());
}
+
+ /**
+ * Return `true` if the parser appears to be at the beginning of an argument
+ * even though there was no comma. This is a special case of the more
+ * general recovery technique described below.
+ */
+ bool isLikelyMissingComma() {
+ if (_matchesIdentifier() &&
+ _tokenMatches(_currentToken.next, TokenType.COLON) &&
+ leftParenthesis is BeginToken &&
+ leftParenthesis.endToken != null) {
+ _reportErrorForToken(
+ ParserErrorCode.EXPECTED_TOKEN, _currentToken.previous, [',']);
+ return true;
+ }
+ return false;
+ }
+
//
// Even though unnamed arguments must all appear before any named arguments,
// we allow them to appear in any order so that we can recover faster.
@@ -692,14 +710,18 @@ class Parser {
bool wasInInitializer = _inInitializer;
_inInitializer = false;
try {
+ Token previousStartOfArgument = _currentToken;
Expression argument = parseArgument();
List<Expression> arguments = <Expression>[argument];
bool foundNamedArgument = argument is NamedExpression;
bool generatedError = false;
- while (_optional(TokenType.COMMA)) {
+ while (_optional(TokenType.COMMA) ||
+ (isLikelyMissingComma() &&
+ previousStartOfArgument != _currentToken)) {
if (_matches(TokenType.CLOSE_PAREN)) {
break;
}
+ previousStartOfArgument = _currentToken;
argument = parseArgument();
arguments.add(argument);
if (argument is NamedExpression) {
« 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