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

Side by Side 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, 5 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 unified diff | Download patch
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/parser_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analyzer.src.generated.parser; 5 library analyzer.src.generated.parser;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import "dart:math" as math; 8 import "dart:math" as math;
9 9
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 2312 matching lines...) Expand 10 before | Expand all | Expand 10 after
2323 // we allow them to appear in any order so that we can recover faster. 2323 // we allow them to appear in any order so that we can recover faster.
2324 // 2324 //
2325 bool wasInInitializer = _inInitializer; 2325 bool wasInInitializer = _inInitializer;
2326 _inInitializer = false; 2326 _inInitializer = false;
2327 try { 2327 try {
2328 Expression argument = parseArgument(); 2328 Expression argument = parseArgument();
2329 List<Expression> arguments = <Expression>[argument]; 2329 List<Expression> arguments = <Expression>[argument];
2330 bool foundNamedArgument = argument is NamedExpression; 2330 bool foundNamedArgument = argument is NamedExpression;
2331 bool generatedError = false; 2331 bool generatedError = false;
2332 while (_optional(TokenType.COMMA)) { 2332 while (_optional(TokenType.COMMA)) {
2333 if (parseTrailingCommas && _matches(TokenType.CLOSE_PAREN)) {
2334 break;
2335 }
2333 argument = parseArgument(); 2336 argument = parseArgument();
2334 arguments.add(argument); 2337 arguments.add(argument);
2335 if (argument is NamedExpression) { 2338 if (argument is NamedExpression) {
2336 foundNamedArgument = true; 2339 foundNamedArgument = true;
2337 } else if (foundNamedArgument) { 2340 } else if (foundNamedArgument) {
2338 if (!generatedError) { 2341 if (!generatedError) {
2339 if (!argument.isSynthetic) { 2342 if (!argument.isSynthetic) {
2340 // Report the error, once, but allow the arguments to be in any 2343 // Report the error, once, but allow the arguments to be in any
2341 // order in the AST. 2344 // order in the AST.
2342 _reportErrorForCurrentToken( 2345 _reportErrorForCurrentToken(
(...skipping 3768 matching lines...) Expand 10 before | Expand all | Expand 10 after
6111 if (kind == ParameterKind.REQUIRED && wasOptionalParameter) { 6114 if (kind == ParameterKind.REQUIRED && wasOptionalParameter) {
6112 _reportErrorForNode( 6115 _reportErrorForNode(
6113 ParserErrorCode.NORMAL_BEFORE_OPTIONAL_PARAMETERS, parameter); 6116 ParserErrorCode.NORMAL_BEFORE_OPTIONAL_PARAMETERS, parameter);
6114 } 6117 }
6115 // 6118 //
6116 // Handle the end of parameter groups. 6119 // Handle the end of parameter groups.
6117 // 6120 //
6118 // TODO(brianwilkerson) Improve the detection and reporting of missing and 6121 // TODO(brianwilkerson) Improve the detection and reporting of missing and
6119 // mismatched delimiters. 6122 // mismatched delimiters.
6120 type = _currentToken.type; 6123 type = _currentToken.type;
6124
6125 // Advance past trailing commas as appropriate.
6126 if (parseTrailingCommas && type == TokenType.COMMA) {
6127 // Only parse commas trailing normal (non-positional/named) params.
6128 if (rightSquareBracket == null && rightCurlyBracket == null) {
6129 Token next = _peek();
6130 if (next.type == TokenType.CLOSE_PAREN ||
6131 next.type == TokenType.CLOSE_CURLY_BRACKET ||
6132 next.type == TokenType.CLOSE_SQUARE_BRACKET) {
6133 _advance();
6134 type = _currentToken.type;
6135 }
6136 }
6137 }
6138
6121 if (type == TokenType.CLOSE_SQUARE_BRACKET) { 6139 if (type == TokenType.CLOSE_SQUARE_BRACKET) {
6122 rightSquareBracket = getAndAdvance(); 6140 rightSquareBracket = getAndAdvance();
6123 if (leftSquareBracket == null) { 6141 if (leftSquareBracket == null) {
6124 if (leftCurlyBracket != null) { 6142 if (leftCurlyBracket != null) {
6125 _reportErrorForCurrentToken( 6143 _reportErrorForCurrentToken(
6126 ParserErrorCode.WRONG_TERMINATOR_FOR_PARAMETER_GROUP, ["}"]); 6144 ParserErrorCode.WRONG_TERMINATOR_FOR_PARAMETER_GROUP, ["}"]);
6127 rightCurlyBracket = rightSquareBracket; 6145 rightCurlyBracket = rightSquareBracket;
6128 rightSquareBracket = null; 6146 rightSquareBracket = null;
6129 } else { 6147 } else {
6130 _reportErrorForCurrentToken( 6148 _reportErrorForCurrentToken(
(...skipping 4329 matching lines...) Expand 10 before | Expand all | Expand 10 after
10460 */ 10478 */
10461 const ParserErrorCode(String name, String message, [String correction]) 10479 const ParserErrorCode(String name, String message, [String correction])
10462 : super(name, message, correction); 10480 : super(name, message, correction);
10463 10481
10464 @override 10482 @override
10465 ErrorSeverity get errorSeverity => ErrorSeverity.ERROR; 10483 ErrorSeverity get errorSeverity => ErrorSeverity.ERROR;
10466 10484
10467 @override 10485 @override
10468 ErrorType get type => ErrorType.SYNTACTIC_ERROR; 10486 ErrorType get type => ErrorType.SYNTACTIC_ERROR;
10469 } 10487 }
OLDNEW
« 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