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

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

Issue 2116853002: Parser support for trailing commas (#26647). (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 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 a49b8ead214852ea0275c6931d8d04f0ab8b9b62..ab3b05e0f98e02ddc4bb3dbf527a9c6c91003a10 100644
--- a/pkg/analyzer/lib/src/generated/parser.dart
+++ b/pkg/analyzer/lib/src/generated/parser.dart
@@ -2330,6 +2330,9 @@ class Parser {
bool foundNamedArgument = argument is NamedExpression;
bool generatedError = false;
while (_optional(TokenType.COMMA)) {
+ if (parseTrailingCommas && _matches(TokenType.CLOSE_PAREN)) {
+ break;
+ }
argument = parseArgument();
arguments.add(argument);
if (argument is NamedExpression) {
@@ -6118,6 +6121,21 @@ class Parser {
// TODO(brianwilkerson) Improve the detection and reporting of missing and
// mismatched delimiters.
type = _currentToken.type;
+
+ // Advance past trailing commas as appropriate.
+ if (parseTrailingCommas && type == TokenType.COMMA) {
+ // Only parse commas trailing normal (non-positional/named) params.
+ if (rightSquareBracket == null && rightCurlyBracket == null) {
+ Token next = _peek();
+ if (next.type == TokenType.CLOSE_PAREN ||
+ next.type == TokenType.CLOSE_CURLY_BRACKET ||
+ next.type == TokenType.CLOSE_SQUARE_BRACKET) {
+ _advance();
+ type = _currentToken.type;
+ }
+ }
+ }
+
if (type == TokenType.CLOSE_SQUARE_BRACKET) {
rightSquareBracket = getAndAdvance();
if (leftSquareBracket == null) {
« 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