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

Side by Side 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 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 667 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 * 678 *
679 * argumentList ::= 679 * argumentList ::=
680 * namedArgument (',' namedArgument)* 680 * namedArgument (',' namedArgument)*
681 * | expressionList (',' namedArgument)* 681 * | expressionList (',' namedArgument)*
682 */ 682 */
683 ArgumentList parseArgumentList() { 683 ArgumentList parseArgumentList() {
684 Token leftParenthesis = getAndAdvance(); 684 Token leftParenthesis = getAndAdvance();
685 if (_matches(TokenType.CLOSE_PAREN)) { 685 if (_matches(TokenType.CLOSE_PAREN)) {
686 return astFactory.argumentList(leftParenthesis, null, getAndAdvance()); 686 return astFactory.argumentList(leftParenthesis, null, getAndAdvance());
687 } 687 }
688
689 /**
690 * Return `true` if the parser appears to be at the beginning of an argument
691 * even though there was no comma. This is a special case of the more
692 * general recovery technique described below.
693 */
694 bool isLikelyMissingComma() {
695 if (_matchesIdentifier() &&
696 _tokenMatches(_currentToken.next, TokenType.COLON) &&
697 leftParenthesis is BeginToken &&
698 leftParenthesis.endToken != null) {
699 _reportErrorForToken(
700 ParserErrorCode.EXPECTED_TOKEN, _currentToken.previous, [',']);
701 return true;
702 }
703 return false;
704 }
705
688 // 706 //
689 // Even though unnamed arguments must all appear before any named arguments, 707 // Even though unnamed arguments must all appear before any named arguments,
690 // we allow them to appear in any order so that we can recover faster. 708 // we allow them to appear in any order so that we can recover faster.
691 // 709 //
692 bool wasInInitializer = _inInitializer; 710 bool wasInInitializer = _inInitializer;
693 _inInitializer = false; 711 _inInitializer = false;
694 try { 712 try {
713 Token previousStartOfArgument = _currentToken;
695 Expression argument = parseArgument(); 714 Expression argument = parseArgument();
696 List<Expression> arguments = <Expression>[argument]; 715 List<Expression> arguments = <Expression>[argument];
697 bool foundNamedArgument = argument is NamedExpression; 716 bool foundNamedArgument = argument is NamedExpression;
698 bool generatedError = false; 717 bool generatedError = false;
699 while (_optional(TokenType.COMMA)) { 718 while (_optional(TokenType.COMMA) ||
719 (isLikelyMissingComma() &&
720 previousStartOfArgument != _currentToken)) {
700 if (_matches(TokenType.CLOSE_PAREN)) { 721 if (_matches(TokenType.CLOSE_PAREN)) {
701 break; 722 break;
702 } 723 }
724 previousStartOfArgument = _currentToken;
703 argument = parseArgument(); 725 argument = parseArgument();
704 arguments.add(argument); 726 arguments.add(argument);
705 if (argument is NamedExpression) { 727 if (argument is NamedExpression) {
706 foundNamedArgument = true; 728 foundNamedArgument = true;
707 } else if (foundNamedArgument) { 729 } else if (foundNamedArgument) {
708 if (!generatedError) { 730 if (!generatedError) {
709 if (!argument.isSynthetic) { 731 if (!argument.isSynthetic) {
710 // Report the error, once, but allow the arguments to be in any 732 // Report the error, once, but allow the arguments to be in any
711 // order in the AST. 733 // order in the AST.
712 _reportErrorForCurrentToken( 734 _reportErrorForCurrentToken(
(...skipping 7781 matching lines...) Expand 10 before | Expand all | Expand 10 after
8494 */ 8516 */
8495 Parser_SyntheticKeywordToken(Keyword keyword, int offset) 8517 Parser_SyntheticKeywordToken(Keyword keyword, int offset)
8496 : super(keyword, offset); 8518 : super(keyword, offset);
8497 8519
8498 @override 8520 @override
8499 int get length => 0; 8521 int get length => 0;
8500 8522
8501 @override 8523 @override
8502 Token copy() => new Parser_SyntheticKeywordToken(keyword, offset); 8524 Token copy() => new Parser_SyntheticKeywordToken(keyword, offset);
8503 } 8525 }
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