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

Side by Side Diff: pkg/analyzer/lib/src/generated/parser.dart

Issue 692303003: Fix for issue 19100 - better recovery (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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 | Annotate | Revision Log
« 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 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine.parser; 8 library engine.parser;
9 9
10 import 'dart:collection'; 10 import 'dart:collection';
(...skipping 2273 matching lines...) Expand 10 before | Expand all | Expand 10 after
2284 * </pre> 2284 * </pre>
2285 * 2285 *
2286 * @return the formal parameters that were parsed 2286 * @return the formal parameters that were parsed
2287 */ 2287 */
2288 FormalParameterList parseFormalParameterList() { 2288 FormalParameterList parseFormalParameterList() {
2289 Token leftParenthesis = _expect(TokenType.OPEN_PAREN); 2289 Token leftParenthesis = _expect(TokenType.OPEN_PAREN);
2290 if (_matches(TokenType.CLOSE_PAREN)) { 2290 if (_matches(TokenType.CLOSE_PAREN)) {
2291 return new FormalParameterList(leftParenthesis, null, null, null, andAdvan ce); 2291 return new FormalParameterList(leftParenthesis, null, null, null, andAdvan ce);
2292 } 2292 }
2293 // 2293 //
2294 // Even though it is invalid to have default parameters outside of brackets, required parameters 2294 // Even though it is invalid to have default parameters outside of brackets,
2295 // inside of brackets, or multiple groups of default and named parameters, w e allow all of these 2295 // required parameters inside of brackets, or multiple groups of default and
2296 // cases so that we can recover better. 2296 // named parameters, we allow all of these cases so that we can recover
2297 // better.
2297 // 2298 //
2298 List<FormalParameter> parameters = new List<FormalParameter>(); 2299 List<FormalParameter> parameters = new List<FormalParameter>();
2299 List<FormalParameter> normalParameters = new List<FormalParameter>(); 2300 List<FormalParameter> normalParameters = new List<FormalParameter>();
2300 List<FormalParameter> positionalParameters = new List<FormalParameter>(); 2301 List<FormalParameter> positionalParameters = new List<FormalParameter>();
2301 List<FormalParameter> namedParameters = new List<FormalParameter>(); 2302 List<FormalParameter> namedParameters = new List<FormalParameter>();
2302 List<FormalParameter> currentParameters = normalParameters; 2303 List<FormalParameter> currentParameters = normalParameters;
2303 Token leftSquareBracket = null; 2304 Token leftSquareBracket = null;
2304 Token rightSquareBracket = null; 2305 Token rightSquareBracket = null;
2305 Token leftCurlyBracket = null; 2306 Token leftCurlyBracket = null;
2306 Token rightCurlyBracket = null; 2307 Token rightCurlyBracket = null;
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
2520 * @return the map literal entry that was parsed 2521 * @return the map literal entry that was parsed
2521 */ 2522 */
2522 MapLiteralEntry parseMapLiteralEntry() { 2523 MapLiteralEntry parseMapLiteralEntry() {
2523 Expression key = parseExpression2(); 2524 Expression key = parseExpression2();
2524 Token separator = _expect(TokenType.COLON); 2525 Token separator = _expect(TokenType.COLON);
2525 Expression value = parseExpression2(); 2526 Expression value = parseExpression2();
2526 return new MapLiteralEntry(key, separator, value); 2527 return new MapLiteralEntry(key, separator, value);
2527 } 2528 }
2528 2529
2529 /** 2530 /**
2530 * Parse a normal formal parameter. 2531 * Parse a normal formal parameter and return the normal formal parameter that
2532 * was parsed.
2531 * 2533 *
2532 * <pre> 2534 * <pre>
2533 * normalFormalParameter ::= 2535 * normalFormalParameter ::=
2534 * functionSignature 2536 * functionSignature
2535 * | fieldFormalParameter 2537 * | fieldFormalParameter
2536 * | simpleFormalParameter 2538 * | simpleFormalParameter
2537 * 2539 *
2538 * functionSignature: 2540 * functionSignature:
2539 * metadata returnType? identifier formalParameterList 2541 * metadata returnType? identifier formalParameterList
2540 * 2542 *
2541 * fieldFormalParameter ::= 2543 * fieldFormalParameter ::=
2542 * metadata finalConstVarOrType? 'this' '.' identifier 2544 * metadata finalConstVarOrType? 'this' '.' identifier
2543 * 2545 *
2544 * simpleFormalParameter ::= 2546 * simpleFormalParameter ::=
2545 * declaredIdentifier 2547 * declaredIdentifier
2546 * | metadata identifier 2548 * | metadata identifier
2547 * </pre> 2549 * </pre>
2548 *
2549 * @return the normal formal parameter that was parsed
2550 */ 2550 */
2551 NormalFormalParameter parseNormalFormalParameter() { 2551 NormalFormalParameter parseNormalFormalParameter() {
2552 CommentAndMetadata commentAndMetadata = _parseCommentAndMetadata(); 2552 CommentAndMetadata commentAndMetadata = _parseCommentAndMetadata();
2553 FinalConstVarOrType holder = _parseFinalConstVarOrType(true); 2553 FinalConstVarOrType holder = _parseFinalConstVarOrType(true);
2554 Token thisKeyword = null; 2554 Token thisKeyword = null;
2555 Token period = null; 2555 Token period = null;
2556 if (_matchesKeyword(Keyword.THIS)) { 2556 if (_matchesKeyword(Keyword.THIS)) {
2557 thisKeyword = andAdvance; 2557 thisKeyword = andAdvance;
2558 period = _expect(TokenType.PERIOD); 2558 period = _expect(TokenType.PERIOD);
2559 } 2559 }
(...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after
3393 token = token.next.next; 3393 token = token.next.next;
3394 } 3394 }
3395 if (token.type == TokenType.KEYWORD) { 3395 if (token.type == TokenType.KEYWORD) {
3396 Keyword keyword = (token as KeywordToken).keyword; 3396 Keyword keyword = (token as KeywordToken).keyword;
3397 return keyword == Keyword.CASE || keyword == Keyword.DEFAULT; 3397 return keyword == Keyword.CASE || keyword == Keyword.DEFAULT;
3398 } 3398 }
3399 return false; 3399 return false;
3400 } 3400 }
3401 3401
3402 /** 3402 /**
3403 * Return `true` if the given token appears to be the first token of a type na me that is 3403 * Return `true` if the [startToken] appears to be the first token of a type
3404 * followed by a variable or field formal parameter. 3404 * name that is followed by a variable or field formal parameter.
3405 *
3406 * @param startToken the first token of the sequence being checked
3407 * @return `true` if there is a type name and variable starting at the given t oken
3408 */ 3405 */
3409 bool _isTypedIdentifier(Token startToken) { 3406 bool _isTypedIdentifier(Token startToken) {
3410 Token token = _skipReturnType(startToken); 3407 Token token = _skipReturnType(startToken);
3411 if (token == null) { 3408 if (token == null) {
3412 return false; 3409 return false;
3413 } else if (_tokenMatchesIdentifier(token)) { 3410 } else if (_tokenMatchesIdentifier(token)) {
3414 return true; 3411 return true;
3415 } else if (_tokenMatchesKeyword(token, Keyword.THIS) && _tokenMatches(token. next, TokenType.PERIOD) && _tokenMatchesIdentifier(token.next.next)) { 3412 } else if (_tokenMatchesKeyword(token, Keyword.THIS)
3413 && _tokenMatches(token.next, TokenType.PERIOD)
3414 && _tokenMatchesIdentifier(token.next.next)) {
3415 return true;
3416 } else if (_tokenMatchesKeyword(startToken, Keyword.VOID)) {
3417 // The keyword 'void' isn't a valid identifier, so it should be assumed to
3418 // be a type name.
3419 return true;
3420 } else if (startToken.next != token) {
3421 // The type is more than a simple identifier, so it should be assumed to
3422 // be a type name.
3416 return true; 3423 return true;
3417 } 3424 }
3418 return false; 3425 return false;
3419 } 3426 }
3420 3427
3421 /** 3428 /**
3422 * Compare the given tokens to find the token that appears first in the source being parsed. That 3429 * Compare the given tokens to find the token that appears first in the source being parsed. That
3423 * is, return the left-most of all of the tokens. The arguments are allowed to be `null`. 3430 * is, return the left-most of all of the tokens. The arguments are allowed to be `null`.
3424 * Return the token with the smallest offset, or `null` if there are no argume nts or if all 3431 * Return the token with the smallest offset, or `null` if there are no argume nts or if all
3425 * of the arguments are `null`. 3432 * of the arguments are `null`.
(...skipping 6524 matching lines...) Expand 10 before | Expand all | Expand 10 after
9950 return trampoline(target, arguments[0], arguments[1]); 9957 return trampoline(target, arguments[0], arguments[1]);
9951 case 3: 9958 case 3:
9952 return trampoline(target, arguments[0], arguments[1], arguments[2]); 9959 return trampoline(target, arguments[0], arguments[1], arguments[2]);
9953 case 4: 9960 case 4:
9954 return trampoline(target, arguments[0], arguments[1], arguments[2], argu ments[3]); 9961 return trampoline(target, arguments[0], arguments[1], arguments[2], argu ments[3]);
9955 default: 9962 default:
9956 throw new IllegalArgumentException("Not implemented for > 4 arguments"); 9963 throw new IllegalArgumentException("Not implemented for > 4 arguments");
9957 } 9964 }
9958 } 9965 }
9959 } 9966 }
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