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

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

Issue 786653002: Rename method (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years 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 | no next file » | 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:math" as math; 10 import "dart:math" as math;
(...skipping 2310 matching lines...) Expand 10 before | Expand all | Expand 10 after
2321 2321
2322 /** 2322 /**
2323 * Initialize a newly created parser. 2323 * Initialize a newly created parser.
2324 * 2324 *
2325 * @param source the source being parsed 2325 * @param source the source being parsed
2326 * @param errorListener the error listener that will be informed of any errors that are found 2326 * @param errorListener the error listener that will be informed of any errors that are found
2327 * during the parse 2327 * during the parse
2328 */ 2328 */
2329 Parser(this._source, this._errorListener); 2329 Parser(this._source, this._errorListener);
2330 2330
2331 /**
2332 * Advance to the next token in the token stream, making it the new current to ken.
2333 *
2334 * @return the token that was current before this method was invoked
2335 */
2336 Token get andAdvance {
2337 Token token = _currentToken;
2338 _advance();
2339 return token;
2340 }
2341
2342 void set currentToken(Token currentToken) { 2331 void set currentToken(Token currentToken) {
2343 this._currentToken = currentToken; 2332 this._currentToken = currentToken;
2344 } 2333 }
2345 2334
2346 /** 2335 /**
2336 * Advance to the next token in the token stream, making it the new current
2337 * token and return the token that was current before this method was invoked.
2338 */
2339 Token getAndAdvance() {
2340 Token token = _currentToken;
2341 _advance();
2342 return token;
2343 }
2344
2345 /**
2347 * Return `true` if the current token is the first token of a return type that is followed 2346 * Return `true` if the current token is the first token of a return type that is followed
2348 * by an identifier, possibly followed by a list of type parameters, followed by a 2347 * by an identifier, possibly followed by a list of type parameters, followed by a
2349 * left-parenthesis. This is used by parseTypeAlias to determine whether or no t to parse a return 2348 * left-parenthesis. This is used by parseTypeAlias to determine whether or no t to parse a return
2350 * type. 2349 * type.
2351 * 2350 *
2352 * @return `true` if we can successfully parse the rest of a type alias if we first parse a 2351 * @return `true` if we can successfully parse the rest of a type alias if we first parse a
2353 * return type. 2352 * return type.
2354 */ 2353 */
2355 bool get hasReturnTypeInTypeAlias { 2354 bool get hasReturnTypeInTypeAlias {
2356 Token next = _skipReturnType(_currentToken); 2355 Token next = _skipReturnType(_currentToken);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
2405 * </pre> 2404 * </pre>
2406 * 2405 *
2407 * @return the annotation that was parsed 2406 * @return the annotation that was parsed
2408 */ 2407 */
2409 Annotation parseAnnotation() { 2408 Annotation parseAnnotation() {
2410 Token atSign = _expect(TokenType.AT); 2409 Token atSign = _expect(TokenType.AT);
2411 Identifier name = parsePrefixedIdentifier(); 2410 Identifier name = parsePrefixedIdentifier();
2412 Token period = null; 2411 Token period = null;
2413 SimpleIdentifier constructorName = null; 2412 SimpleIdentifier constructorName = null;
2414 if (_matches(TokenType.PERIOD)) { 2413 if (_matches(TokenType.PERIOD)) {
2415 period = andAdvance; 2414 period = getAndAdvance();
2416 constructorName = parseSimpleIdentifier(); 2415 constructorName = parseSimpleIdentifier();
2417 } 2416 }
2418 ArgumentList arguments = null; 2417 ArgumentList arguments = null;
2419 if (_matches(TokenType.OPEN_PAREN)) { 2418 if (_matches(TokenType.OPEN_PAREN)) {
2420 arguments = parseArgumentList(); 2419 arguments = parseArgumentList();
2421 } 2420 }
2422 return new Annotation(atSign, name, period, constructorName, arguments); 2421 return new Annotation(atSign, name, period, constructorName, arguments);
2423 } 2422 }
2424 2423
2425 /** 2424 /**
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2459 * namedArgument (',' namedArgument)* 2458 * namedArgument (',' namedArgument)*
2460 * | expressionList (',' namedArgument)* 2459 * | expressionList (',' namedArgument)*
2461 * </pre> 2460 * </pre>
2462 * 2461 *
2463 * @return the argument list that was parsed 2462 * @return the argument list that was parsed
2464 */ 2463 */
2465 ArgumentList parseArgumentList() { 2464 ArgumentList parseArgumentList() {
2466 Token leftParenthesis = _expect(TokenType.OPEN_PAREN); 2465 Token leftParenthesis = _expect(TokenType.OPEN_PAREN);
2467 List<Expression> arguments = new List<Expression>(); 2466 List<Expression> arguments = new List<Expression>();
2468 if (_matches(TokenType.CLOSE_PAREN)) { 2467 if (_matches(TokenType.CLOSE_PAREN)) {
2469 return new ArgumentList(leftParenthesis, arguments, andAdvance); 2468 return new ArgumentList(leftParenthesis, arguments, getAndAdvance());
2470 } 2469 }
2471 // 2470 //
2472 // Even though unnamed arguments must all appear before any named arguments, 2471 // Even though unnamed arguments must all appear before any named arguments,
2473 // we allow them to appear in any order so that we can recover faster. 2472 // we allow them to appear in any order so that we can recover faster.
2474 // 2473 //
2475 bool wasInInitializer = _inInitializer; 2474 bool wasInInitializer = _inInitializer;
2476 _inInitializer = false; 2475 _inInitializer = false;
2477 try { 2476 try {
2478 Expression argument = parseArgument(); 2477 Expression argument = parseArgument();
2479 arguments.add(argument); 2478 arguments.add(argument);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
2516 * bitwiseXorExpression ('|' bitwiseXorExpression)* 2515 * bitwiseXorExpression ('|' bitwiseXorExpression)*
2517 * | 'super' ('|' bitwiseXorExpression)+ 2516 * | 'super' ('|' bitwiseXorExpression)+
2518 * </pre> 2517 * </pre>
2519 * 2518 *
2520 * @return the bitwise or expression that was parsed 2519 * @return the bitwise or expression that was parsed
2521 */ 2520 */
2522 Expression parseBitwiseOrExpression() { 2521 Expression parseBitwiseOrExpression() {
2523 Expression expression; 2522 Expression expression;
2524 if (_matchesKeyword(Keyword.SUPER) && 2523 if (_matchesKeyword(Keyword.SUPER) &&
2525 _tokenMatches(_peek(), TokenType.BAR)) { 2524 _tokenMatches(_peek(), TokenType.BAR)) {
2526 expression = new SuperExpression(andAdvance); 2525 expression = new SuperExpression(getAndAdvance());
2527 } else { 2526 } else {
2528 expression = _parseBitwiseXorExpression(); 2527 expression = _parseBitwiseXorExpression();
2529 } 2528 }
2530 while (_matches(TokenType.BAR)) { 2529 while (_matches(TokenType.BAR)) {
2531 Token operator = andAdvance; 2530 Token operator = getAndAdvance();
2532 expression = 2531 expression =
2533 new BinaryExpression(expression, operator, _parseBitwiseXorExpression( )); 2532 new BinaryExpression(expression, operator, _parseBitwiseXorExpression( ));
2534 } 2533 }
2535 return expression; 2534 return expression;
2536 } 2535 }
2537 2536
2538 /** 2537 /**
2539 * Parse a block. 2538 * Parse a block.
2540 * 2539 *
2541 * <pre> 2540 * <pre>
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
2680 if (_matchesKeyword(Keyword.CLASS)) { 2679 if (_matchesKeyword(Keyword.CLASS)) {
2681 _reportErrorForCurrentToken(ParserErrorCode.CLASS_IN_CLASS); 2680 _reportErrorForCurrentToken(ParserErrorCode.CLASS_IN_CLASS);
2682 // TODO(brianwilkerson) We don't currently have any way to capture the 2681 // TODO(brianwilkerson) We don't currently have any way to capture the
2683 // class that was parsed. 2682 // class that was parsed.
2684 _parseClassDeclaration(commentAndMetadata, null); 2683 _parseClassDeclaration(commentAndMetadata, null);
2685 return null; 2684 return null;
2686 } else if (_matchesKeyword(Keyword.ABSTRACT) && _tokenMatchesKeyword(_peek (), Keyword.CLASS)) { 2685 } else if (_matchesKeyword(Keyword.ABSTRACT) && _tokenMatchesKeyword(_peek (), Keyword.CLASS)) {
2687 _reportErrorForToken(ParserErrorCode.CLASS_IN_CLASS, _peek()); 2686 _reportErrorForToken(ParserErrorCode.CLASS_IN_CLASS, _peek());
2688 // TODO(brianwilkerson) We don't currently have any way to capture the 2687 // TODO(brianwilkerson) We don't currently have any way to capture the
2689 // class that was parsed. 2688 // class that was parsed.
2690 _parseClassDeclaration(commentAndMetadata, andAdvance); 2689 _parseClassDeclaration(commentAndMetadata, getAndAdvance());
2691 return null; 2690 return null;
2692 } else if (_isOperator(_currentToken)) { 2691 } else if (_isOperator(_currentToken)) {
2693 // 2692 //
2694 // We appear to have found an operator declaration without the 2693 // We appear to have found an operator declaration without the
2695 // 'operator' keyword. 2694 // 'operator' keyword.
2696 // 2695 //
2697 _validateModifiersForOperator(modifiers); 2696 _validateModifiersForOperator(modifiers);
2698 return _parseOperator( 2697 return _parseOperator(
2699 commentAndMetadata, 2698 commentAndMetadata,
2700 modifiers.externalKeyword, 2699 modifiers.externalKeyword,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
2748 return null; 2747 return null;
2749 } else if (_tokenMatches(_peek(), TokenType.PERIOD) && 2748 } else if (_tokenMatches(_peek(), TokenType.PERIOD) &&
2750 _tokenMatchesIdentifier(_peekAt(2)) && 2749 _tokenMatchesIdentifier(_peekAt(2)) &&
2751 _tokenMatches(_peekAt(3), TokenType.OPEN_PAREN)) { 2750 _tokenMatches(_peekAt(3), TokenType.OPEN_PAREN)) {
2752 return _parseConstructor( 2751 return _parseConstructor(
2753 commentAndMetadata, 2752 commentAndMetadata,
2754 modifiers.externalKeyword, 2753 modifiers.externalKeyword,
2755 _validateModifiersForConstructor(modifiers), 2754 _validateModifiersForConstructor(modifiers),
2756 modifiers.factoryKeyword, 2755 modifiers.factoryKeyword,
2757 parseSimpleIdentifier(), 2756 parseSimpleIdentifier(),
2758 andAdvance, 2757 getAndAdvance(),
2759 parseSimpleIdentifier(), 2758 parseSimpleIdentifier(),
2760 parseFormalParameterList()); 2759 parseFormalParameterList());
2761 } else if (_tokenMatches(_peek(), TokenType.OPEN_PAREN)) { 2760 } else if (_tokenMatches(_peek(), TokenType.OPEN_PAREN)) {
2762 SimpleIdentifier methodName = parseSimpleIdentifier(); 2761 SimpleIdentifier methodName = parseSimpleIdentifier();
2763 FormalParameterList parameters = parseFormalParameterList(); 2762 FormalParameterList parameters = parseFormalParameterList();
2764 if (_matches(TokenType.COLON) || 2763 if (_matches(TokenType.COLON) ||
2765 modifiers.factoryKeyword != null || 2764 modifiers.factoryKeyword != null ||
2766 methodName.name == className) { 2765 methodName.name == className) {
2767 return _parseConstructor( 2766 return _parseConstructor(
2768 commentAndMetadata, 2767 commentAndMetadata,
(...skipping 24 matching lines...) Expand all
2793 } 2792 }
2794 return _parseInitializedIdentifierList( 2793 return _parseInitializedIdentifierList(
2795 commentAndMetadata, 2794 commentAndMetadata,
2796 modifiers.staticKeyword, 2795 modifiers.staticKeyword,
2797 _validateModifiersForField(modifiers), 2796 _validateModifiersForField(modifiers),
2798 null); 2797 null);
2799 } else if (_matchesKeyword(Keyword.TYPEDEF)) { 2798 } else if (_matchesKeyword(Keyword.TYPEDEF)) {
2800 _reportErrorForCurrentToken(ParserErrorCode.TYPEDEF_IN_CLASS); 2799 _reportErrorForCurrentToken(ParserErrorCode.TYPEDEF_IN_CLASS);
2801 // TODO(brianwilkerson) We don't currently have any way to capture the 2800 // TODO(brianwilkerson) We don't currently have any way to capture the
2802 // function type alias that was parsed. 2801 // function type alias that was parsed.
2803 _parseFunctionTypeAlias(commentAndMetadata, andAdvance); 2802 _parseFunctionTypeAlias(commentAndMetadata, getAndAdvance());
2804 return null; 2803 return null;
2805 } 2804 }
2806 TypeName type = parseTypeName(); 2805 TypeName type = parseTypeName();
2807 if (_matchesKeyword(Keyword.GET) && _tokenMatchesIdentifier(_peek())) { 2806 if (_matchesKeyword(Keyword.GET) && _tokenMatchesIdentifier(_peek())) {
2808 _validateModifiersForGetterOrSetterOrMethod(modifiers); 2807 _validateModifiersForGetterOrSetterOrMethod(modifiers);
2809 return _parseGetter( 2808 return _parseGetter(
2810 commentAndMetadata, 2809 commentAndMetadata,
2811 modifiers.externalKeyword, 2810 modifiers.externalKeyword,
2812 modifiers.staticKeyword, 2811 modifiers.staticKeyword,
2813 type); 2812 type);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
2916 * `null`. 2915 * `null`.
2917 * 2916 *
2918 * <pre> 2917 * <pre>
2919 * combinator ::= 2918 * combinator ::=
2920 * 'show' identifier (',' identifier)* 2919 * 'show' identifier (',' identifier)*
2921 * | 'hide' identifier (',' identifier)* 2920 * | 'hide' identifier (',' identifier)*
2922 * </pre> 2921 * </pre>
2923 */ 2922 */
2924 Combinator parseCombinator() { 2923 Combinator parseCombinator() {
2925 if (_matchesString(_SHOW) || _matchesString(_HIDE)) { 2924 if (_matchesString(_SHOW) || _matchesString(_HIDE)) {
2926 Token keyword = andAdvance; 2925 Token keyword = getAndAdvance();
2927 List<SimpleIdentifier> names = _parseIdentifierList(); 2926 List<SimpleIdentifier> names = _parseIdentifierList();
2928 if (keyword.lexeme == _SHOW) { 2927 if (keyword.lexeme == _SHOW) {
2929 return new ShowCombinator(keyword, names); 2928 return new ShowCombinator(keyword, names);
2930 } else { 2929 } else {
2931 return new HideCombinator(keyword, names); 2930 return new HideCombinator(keyword, names);
2932 } 2931 }
2933 } 2932 }
2934 return null; 2933 return null;
2935 } 2934 }
2936 2935
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
2971 * directive 2970 * directive
2972 * | topLevelDeclaration 2971 * | topLevelDeclaration
2973 * </pre> 2972 * </pre>
2974 * 2973 *
2975 * @return the compilation unit that was parsed 2974 * @return the compilation unit that was parsed
2976 */ 2975 */
2977 CompilationUnit parseCompilationUnit2() { 2976 CompilationUnit parseCompilationUnit2() {
2978 Token firstToken = _currentToken; 2977 Token firstToken = _currentToken;
2979 ScriptTag scriptTag = null; 2978 ScriptTag scriptTag = null;
2980 if (_matches(TokenType.SCRIPT_TAG)) { 2979 if (_matches(TokenType.SCRIPT_TAG)) {
2981 scriptTag = new ScriptTag(andAdvance); 2980 scriptTag = new ScriptTag(getAndAdvance());
2982 } 2981 }
2983 // 2982 //
2984 // Even though all directives must appear before declarations and must occur 2983 // Even though all directives must appear before declarations and must occur
2985 // in a given order, we allow directives and declarations to occur in any 2984 // in a given order, we allow directives and declarations to occur in any
2986 // order so that we can recover better. 2985 // order so that we can recover better.
2987 // 2986 //
2988 bool libraryDirectiveFound = false; 2987 bool libraryDirectiveFound = false;
2989 bool partOfDirectiveFound = false; 2988 bool partOfDirectiveFound = false;
2990 bool partDirectiveFound = false; 2989 bool partDirectiveFound = false;
2991 bool directiveFoundAfterDeclaration = false; 2990 bool directiveFoundAfterDeclaration = false;
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
3096 * logicalOrExpression ('?' expressionWithoutCascade ':' expressionWithout Cascade)? 3095 * logicalOrExpression ('?' expressionWithoutCascade ':' expressionWithout Cascade)?
3097 * </pre> 3096 * </pre>
3098 * 3097 *
3099 * @return the conditional expression that was parsed 3098 * @return the conditional expression that was parsed
3100 */ 3099 */
3101 Expression parseConditionalExpression() { 3100 Expression parseConditionalExpression() {
3102 Expression condition = parseLogicalOrExpression(); 3101 Expression condition = parseLogicalOrExpression();
3103 if (!_matches(TokenType.QUESTION)) { 3102 if (!_matches(TokenType.QUESTION)) {
3104 return condition; 3103 return condition;
3105 } 3104 }
3106 Token question = andAdvance; 3105 Token question = getAndAdvance();
3107 Expression thenExpression = parseExpressionWithoutCascade(); 3106 Expression thenExpression = parseExpressionWithoutCascade();
3108 Token colon = _expect(TokenType.COLON); 3107 Token colon = _expect(TokenType.COLON);
3109 Expression elseExpression = parseExpressionWithoutCascade(); 3108 Expression elseExpression = parseExpressionWithoutCascade();
3110 return new ConditionalExpression( 3109 return new ConditionalExpression(
3111 condition, 3110 condition,
3112 question, 3111 question,
3113 thenExpression, 3112 thenExpression,
3114 colon, 3113 colon,
3115 elseExpression); 3114 elseExpression);
3116 } 3115 }
3117 3116
3118 /** 3117 /**
3119 * Parse the name of a constructor. 3118 * Parse the name of a constructor.
3120 * 3119 *
3121 * <pre> 3120 * <pre>
3122 * constructorName: 3121 * constructorName:
3123 * type ('.' identifier)? 3122 * type ('.' identifier)?
3124 * </pre> 3123 * </pre>
3125 * 3124 *
3126 * @return the constructor name that was parsed 3125 * @return the constructor name that was parsed
3127 */ 3126 */
3128 ConstructorName parseConstructorName() { 3127 ConstructorName parseConstructorName() {
3129 TypeName type = parseTypeName(); 3128 TypeName type = parseTypeName();
3130 Token period = null; 3129 Token period = null;
3131 SimpleIdentifier name = null; 3130 SimpleIdentifier name = null;
3132 if (_matches(TokenType.PERIOD)) { 3131 if (_matches(TokenType.PERIOD)) {
3133 period = andAdvance; 3132 period = getAndAdvance();
3134 name = parseSimpleIdentifier(); 3133 name = parseSimpleIdentifier();
3135 } 3134 }
3136 return new ConstructorName(type, period, name); 3135 return new ConstructorName(type, period, name);
3137 } 3136 }
3138 3137
3139 /** 3138 /**
3140 * Parse the script tag and directives in a compilation unit, starting with th e given token, until 3139 * Parse the script tag and directives in a compilation unit, starting with th e given token, until
3141 * the first non-directive is encountered. The remainder of the compilation un it will not be 3140 * the first non-directive is encountered. The remainder of the compilation un it will not be
3142 * parsed. Specifically, if there are directives later in the file, they will not be parsed. 3141 * parsed. Specifically, if there are directives later in the file, they will not be parsed.
3143 * 3142 *
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
3206 List<Expression> cascadeSections = new List<Expression>(); 3205 List<Expression> cascadeSections = new List<Expression>();
3207 while (tokenType == TokenType.PERIOD_PERIOD) { 3206 while (tokenType == TokenType.PERIOD_PERIOD) {
3208 Expression section = _parseCascadeSection(); 3207 Expression section = _parseCascadeSection();
3209 if (section != null) { 3208 if (section != null) {
3210 cascadeSections.add(section); 3209 cascadeSections.add(section);
3211 } 3210 }
3212 tokenType = _currentToken.type; 3211 tokenType = _currentToken.type;
3213 } 3212 }
3214 return new CascadeExpression(expression, cascadeSections); 3213 return new CascadeExpression(expression, cascadeSections);
3215 } else if (tokenType.isAssignmentOperator) { 3214 } else if (tokenType.isAssignmentOperator) {
3216 Token operator = andAdvance; 3215 Token operator = getAndAdvance();
3217 _ensureAssignable(expression); 3216 _ensureAssignable(expression);
3218 return new AssignmentExpression(expression, operator, parseExpression2()); 3217 return new AssignmentExpression(expression, operator, parseExpression2());
3219 } 3218 }
3220 return expression; 3219 return expression;
3221 } 3220 }
3222 3221
3223 /** 3222 /**
3224 * Parse an expression that does not contain any cascades. 3223 * Parse an expression that does not contain any cascades.
3225 * 3224 *
3226 * <pre> 3225 * <pre>
(...skipping 12 matching lines...) Expand all
3239 return _parseRethrowExpression(); 3238 return _parseRethrowExpression();
3240 } 3239 }
3241 // 3240 //
3242 // assignableExpression is a subset of conditionalExpression, so we can 3241 // assignableExpression is a subset of conditionalExpression, so we can
3243 // parse a conditional expression and then determine whether it is followed 3242 // parse a conditional expression and then determine whether it is followed
3244 // by an assignmentOperator, checking for conformance to the restricted 3243 // by an assignmentOperator, checking for conformance to the restricted
3245 // grammar after making that determination. 3244 // grammar after making that determination.
3246 // 3245 //
3247 Expression expression = parseConditionalExpression(); 3246 Expression expression = parseConditionalExpression();
3248 if (_currentToken.type.isAssignmentOperator) { 3247 if (_currentToken.type.isAssignmentOperator) {
3249 Token operator = andAdvance; 3248 Token operator = getAndAdvance();
3250 _ensureAssignable(expression); 3249 _ensureAssignable(expression);
3251 expression = new AssignmentExpression( 3250 expression = new AssignmentExpression(
3252 expression, 3251 expression,
3253 operator, 3252 operator,
3254 parseExpressionWithoutCascade()); 3253 parseExpressionWithoutCascade());
3255 } 3254 }
3256 return expression; 3255 return expression;
3257 } 3256 }
3258 3257
3259 /** 3258 /**
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
3298 * @return the formal parameters that were parsed 3297 * @return the formal parameters that were parsed
3299 */ 3298 */
3300 FormalParameterList parseFormalParameterList() { 3299 FormalParameterList parseFormalParameterList() {
3301 Token leftParenthesis = _expect(TokenType.OPEN_PAREN); 3300 Token leftParenthesis = _expect(TokenType.OPEN_PAREN);
3302 if (_matches(TokenType.CLOSE_PAREN)) { 3301 if (_matches(TokenType.CLOSE_PAREN)) {
3303 return new FormalParameterList( 3302 return new FormalParameterList(
3304 leftParenthesis, 3303 leftParenthesis,
3305 null, 3304 null,
3306 null, 3305 null,
3307 null, 3306 null,
3308 andAdvance); 3307 getAndAdvance());
3309 } 3308 }
3310 // 3309 //
3311 // Even though it is invalid to have default parameters outside of brackets, 3310 // Even though it is invalid to have default parameters outside of brackets,
3312 // required parameters inside of brackets, or multiple groups of default and 3311 // required parameters inside of brackets, or multiple groups of default and
3313 // named parameters, we allow all of these cases so that we can recover 3312 // named parameters, we allow all of these cases so that we can recover
3314 // better. 3313 // better.
3315 // 3314 //
3316 List<FormalParameter> parameters = new List<FormalParameter>(); 3315 List<FormalParameter> parameters = new List<FormalParameter>();
3317 List<FormalParameter> normalParameters = new List<FormalParameter>(); 3316 List<FormalParameter> normalParameters = new List<FormalParameter>();
3318 List<FormalParameter> positionalParameters = new List<FormalParameter>(); 3317 List<FormalParameter> positionalParameters = new List<FormalParameter>();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
3354 wasOptionalParameter = true; 3353 wasOptionalParameter = true;
3355 if (leftSquareBracket != null && !reportedMuliplePositionalGroups) { 3354 if (leftSquareBracket != null && !reportedMuliplePositionalGroups) {
3356 _reportErrorForCurrentToken( 3355 _reportErrorForCurrentToken(
3357 ParserErrorCode.MULTIPLE_POSITIONAL_PARAMETER_GROUPS); 3356 ParserErrorCode.MULTIPLE_POSITIONAL_PARAMETER_GROUPS);
3358 reportedMuliplePositionalGroups = true; 3357 reportedMuliplePositionalGroups = true;
3359 } 3358 }
3360 if (leftCurlyBracket != null && !reportedMixedGroups) { 3359 if (leftCurlyBracket != null && !reportedMixedGroups) {
3361 _reportErrorForCurrentToken(ParserErrorCode.MIXED_PARAMETER_GROUPS); 3360 _reportErrorForCurrentToken(ParserErrorCode.MIXED_PARAMETER_GROUPS);
3362 reportedMixedGroups = true; 3361 reportedMixedGroups = true;
3363 } 3362 }
3364 leftSquareBracket = andAdvance; 3363 leftSquareBracket = getAndAdvance();
3365 currentParameters = positionalParameters; 3364 currentParameters = positionalParameters;
3366 kind = ParameterKind.POSITIONAL; 3365 kind = ParameterKind.POSITIONAL;
3367 } else if (_matches(TokenType.OPEN_CURLY_BRACKET)) { 3366 } else if (_matches(TokenType.OPEN_CURLY_BRACKET)) {
3368 wasOptionalParameter = true; 3367 wasOptionalParameter = true;
3369 if (leftCurlyBracket != null && !reportedMulipleNamedGroups) { 3368 if (leftCurlyBracket != null && !reportedMulipleNamedGroups) {
3370 _reportErrorForCurrentToken( 3369 _reportErrorForCurrentToken(
3371 ParserErrorCode.MULTIPLE_NAMED_PARAMETER_GROUPS); 3370 ParserErrorCode.MULTIPLE_NAMED_PARAMETER_GROUPS);
3372 reportedMulipleNamedGroups = true; 3371 reportedMulipleNamedGroups = true;
3373 } 3372 }
3374 if (leftSquareBracket != null && !reportedMixedGroups) { 3373 if (leftSquareBracket != null && !reportedMixedGroups) {
3375 _reportErrorForCurrentToken(ParserErrorCode.MIXED_PARAMETER_GROUPS); 3374 _reportErrorForCurrentToken(ParserErrorCode.MIXED_PARAMETER_GROUPS);
3376 reportedMixedGroups = true; 3375 reportedMixedGroups = true;
3377 } 3376 }
3378 leftCurlyBracket = andAdvance; 3377 leftCurlyBracket = getAndAdvance();
3379 currentParameters = namedParameters; 3378 currentParameters = namedParameters;
3380 kind = ParameterKind.NAMED; 3379 kind = ParameterKind.NAMED;
3381 } 3380 }
3382 // 3381 //
3383 // Parse and record the parameter. 3382 // Parse and record the parameter.
3384 // 3383 //
3385 FormalParameter parameter = _parseFormalParameter(kind); 3384 FormalParameter parameter = _parseFormalParameter(kind);
3386 parameters.add(parameter); 3385 parameters.add(parameter);
3387 currentParameters.add(parameter); 3386 currentParameters.add(parameter);
3388 if (kind == ParameterKind.REQUIRED && wasOptionalParameter) { 3387 if (kind == ParameterKind.REQUIRED && wasOptionalParameter) {
3389 _reportErrorForNode( 3388 _reportErrorForNode(
3390 ParserErrorCode.NORMAL_BEFORE_OPTIONAL_PARAMETERS, 3389 ParserErrorCode.NORMAL_BEFORE_OPTIONAL_PARAMETERS,
3391 parameter); 3390 parameter);
3392 } 3391 }
3393 // 3392 //
3394 // Handle the end of parameter groups. 3393 // Handle the end of parameter groups.
3395 // 3394 //
3396 // TODO(brianwilkerson) Improve the detection and reporting of missing and 3395 // TODO(brianwilkerson) Improve the detection and reporting of missing and
3397 // mismatched delimiters. 3396 // mismatched delimiters.
3398 if (_matches(TokenType.CLOSE_SQUARE_BRACKET)) { 3397 if (_matches(TokenType.CLOSE_SQUARE_BRACKET)) {
3399 rightSquareBracket = andAdvance; 3398 rightSquareBracket = getAndAdvance();
3400 currentParameters = normalParameters; 3399 currentParameters = normalParameters;
3401 if (leftSquareBracket == null) { 3400 if (leftSquareBracket == null) {
3402 if (leftCurlyBracket != null) { 3401 if (leftCurlyBracket != null) {
3403 _reportErrorForCurrentToken( 3402 _reportErrorForCurrentToken(
3404 ParserErrorCode.WRONG_TERMINATOR_FOR_PARAMETER_GROUP, 3403 ParserErrorCode.WRONG_TERMINATOR_FOR_PARAMETER_GROUP,
3405 ["}"]); 3404 ["}"]);
3406 rightCurlyBracket = rightSquareBracket; 3405 rightCurlyBracket = rightSquareBracket;
3407 rightSquareBracket = null; 3406 rightSquareBracket = null;
3408 } else { 3407 } else {
3409 _reportErrorForCurrentToken( 3408 _reportErrorForCurrentToken(
3410 ParserErrorCode.UNEXPECTED_TERMINATOR_FOR_PARAMETER_GROUP, 3409 ParserErrorCode.UNEXPECTED_TERMINATOR_FOR_PARAMETER_GROUP,
3411 ["["]); 3410 ["["]);
3412 } 3411 }
3413 } 3412 }
3414 kind = ParameterKind.REQUIRED; 3413 kind = ParameterKind.REQUIRED;
3415 } else if (_matches(TokenType.CLOSE_CURLY_BRACKET)) { 3414 } else if (_matches(TokenType.CLOSE_CURLY_BRACKET)) {
3416 rightCurlyBracket = andAdvance; 3415 rightCurlyBracket = getAndAdvance();
3417 currentParameters = normalParameters; 3416 currentParameters = normalParameters;
3418 if (leftCurlyBracket == null) { 3417 if (leftCurlyBracket == null) {
3419 if (leftSquareBracket != null) { 3418 if (leftSquareBracket != null) {
3420 _reportErrorForCurrentToken( 3419 _reportErrorForCurrentToken(
3421 ParserErrorCode.WRONG_TERMINATOR_FOR_PARAMETER_GROUP, 3420 ParserErrorCode.WRONG_TERMINATOR_FOR_PARAMETER_GROUP,
3422 ["]"]); 3421 ["]"]);
3423 rightSquareBracket = rightCurlyBracket; 3422 rightSquareBracket = rightCurlyBracket;
3424 rightCurlyBracket = null; 3423 rightCurlyBracket = null;
3425 } else { 3424 } else {
3426 _reportErrorForCurrentToken( 3425 _reportErrorForCurrentToken(
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
3543 * <pre> 3542 * <pre>
3544 * logicalOrExpression ::= 3543 * logicalOrExpression ::=
3545 * logicalAndExpression ('||' logicalAndExpression)* 3544 * logicalAndExpression ('||' logicalAndExpression)*
3546 * </pre> 3545 * </pre>
3547 * 3546 *
3548 * @return the logical or expression that was parsed 3547 * @return the logical or expression that was parsed
3549 */ 3548 */
3550 Expression parseLogicalOrExpression() { 3549 Expression parseLogicalOrExpression() {
3551 Expression expression = _parseLogicalAndExpression(); 3550 Expression expression = _parseLogicalAndExpression();
3552 while (_matches(TokenType.BAR_BAR)) { 3551 while (_matches(TokenType.BAR_BAR)) {
3553 Token operator = andAdvance; 3552 Token operator = getAndAdvance();
3554 expression = 3553 expression =
3555 new BinaryExpression(expression, operator, _parseLogicalAndExpression( )); 3554 new BinaryExpression(expression, operator, _parseLogicalAndExpression( ));
3556 } 3555 }
3557 return expression; 3556 return expression;
3558 } 3557 }
3559 3558
3560 /** 3559 /**
3561 * Parse a map literal entry. 3560 * Parse a map literal entry.
3562 * 3561 *
3563 * <pre> 3562 * <pre>
(...skipping 30 matching lines...) Expand all
3594 * declaredIdentifier 3593 * declaredIdentifier
3595 * | metadata identifier 3594 * | metadata identifier
3596 * </pre> 3595 * </pre>
3597 */ 3596 */
3598 NormalFormalParameter parseNormalFormalParameter() { 3597 NormalFormalParameter parseNormalFormalParameter() {
3599 CommentAndMetadata commentAndMetadata = _parseCommentAndMetadata(); 3598 CommentAndMetadata commentAndMetadata = _parseCommentAndMetadata();
3600 FinalConstVarOrType holder = _parseFinalConstVarOrType(true); 3599 FinalConstVarOrType holder = _parseFinalConstVarOrType(true);
3601 Token thisKeyword = null; 3600 Token thisKeyword = null;
3602 Token period = null; 3601 Token period = null;
3603 if (_matchesKeyword(Keyword.THIS)) { 3602 if (_matchesKeyword(Keyword.THIS)) {
3604 thisKeyword = andAdvance; 3603 thisKeyword = getAndAdvance();
3605 period = _expect(TokenType.PERIOD); 3604 period = _expect(TokenType.PERIOD);
3606 } 3605 }
3607 SimpleIdentifier identifier = parseSimpleIdentifier(); 3606 SimpleIdentifier identifier = parseSimpleIdentifier();
3608 if (_matches(TokenType.OPEN_PAREN)) { 3607 if (_matches(TokenType.OPEN_PAREN)) {
3609 FormalParameterList parameters = parseFormalParameterList(); 3608 FormalParameterList parameters = parseFormalParameterList();
3610 if (thisKeyword == null) { 3609 if (thisKeyword == null) {
3611 if (holder.keyword != null) { 3610 if (holder.keyword != null) {
3612 _reportErrorForToken( 3611 _reportErrorForToken(
3613 ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR, 3612 ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR,
3614 holder.keyword); 3613 holder.keyword);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
3669 * identifier ('.' identifier)? 3668 * identifier ('.' identifier)?
3670 * </pre> 3669 * </pre>
3671 * 3670 *
3672 * @return the prefixed identifier that was parsed 3671 * @return the prefixed identifier that was parsed
3673 */ 3672 */
3674 Identifier parsePrefixedIdentifier() { 3673 Identifier parsePrefixedIdentifier() {
3675 SimpleIdentifier qualifier = parseSimpleIdentifier(); 3674 SimpleIdentifier qualifier = parseSimpleIdentifier();
3676 if (!_matches(TokenType.PERIOD)) { 3675 if (!_matches(TokenType.PERIOD)) {
3677 return qualifier; 3676 return qualifier;
3678 } 3677 }
3679 Token period = andAdvance; 3678 Token period = getAndAdvance();
3680 SimpleIdentifier qualified = parseSimpleIdentifier(); 3679 SimpleIdentifier qualified = parseSimpleIdentifier();
3681 return new PrefixedIdentifier(qualifier, period, qualified); 3680 return new PrefixedIdentifier(qualifier, period, qualified);
3682 } 3681 }
3683 3682
3684 /** 3683 /**
3685 * Parse a return type. 3684 * Parse a return type.
3686 * 3685 *
3687 * <pre> 3686 * <pre>
3688 * returnType ::= 3687 * returnType ::=
3689 * 'void' 3688 * 'void'
3690 * | type 3689 * | type
3691 * </pre> 3690 * </pre>
3692 * 3691 *
3693 * @return the return type that was parsed 3692 * @return the return type that was parsed
3694 */ 3693 */
3695 TypeName parseReturnType() { 3694 TypeName parseReturnType() {
3696 if (_matchesKeyword(Keyword.VOID)) { 3695 if (_matchesKeyword(Keyword.VOID)) {
3697 return new TypeName(new SimpleIdentifier(andAdvance), null); 3696 return new TypeName(new SimpleIdentifier(getAndAdvance()), null);
3698 } else { 3697 } else {
3699 return parseTypeName(); 3698 return parseTypeName();
3700 } 3699 }
3701 } 3700 }
3702 3701
3703 /** 3702 /**
3704 * Parse a simple identifier. 3703 * Parse a simple identifier.
3705 * 3704 *
3706 * <pre> 3705 * <pre>
3707 * identifier ::= 3706 * identifier ::=
3708 * IDENTIFIER 3707 * IDENTIFIER
3709 * </pre> 3708 * </pre>
3710 * 3709 *
3711 * @return the simple identifier that was parsed 3710 * @return the simple identifier that was parsed
3712 */ 3711 */
3713 SimpleIdentifier parseSimpleIdentifier() { 3712 SimpleIdentifier parseSimpleIdentifier() {
3714 if (_matchesIdentifier()) { 3713 if (_matchesIdentifier()) {
3715 return new SimpleIdentifier(andAdvance); 3714 return new SimpleIdentifier(getAndAdvance());
3716 } 3715 }
3717 _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER); 3716 _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER);
3718 return _createSyntheticIdentifier(); 3717 return _createSyntheticIdentifier();
3719 } 3718 }
3720 3719
3721 /** 3720 /**
3722 * Parse a statement, starting with the given token. 3721 * Parse a statement, starting with the given token.
3723 * 3722 *
3724 * @param token the first token of the statement 3723 * @param token the first token of the statement
3725 * @return the statement that was parsed, or `null` if the tokens do not repre sent a 3724 * @return the statement that was parsed, or `null` if the tokens do not repre sent a
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
3785 * stringLiteral ::= 3784 * stringLiteral ::=
3786 * MULTI_LINE_STRING+ 3785 * MULTI_LINE_STRING+
3787 * | SINGLE_LINE_STRING+ 3786 * | SINGLE_LINE_STRING+
3788 * </pre> 3787 * </pre>
3789 * 3788 *
3790 * @return the string literal that was parsed 3789 * @return the string literal that was parsed
3791 */ 3790 */
3792 StringLiteral parseStringLiteral() { 3791 StringLiteral parseStringLiteral() {
3793 List<StringLiteral> strings = new List<StringLiteral>(); 3792 List<StringLiteral> strings = new List<StringLiteral>();
3794 while (_matches(TokenType.STRING)) { 3793 while (_matches(TokenType.STRING)) {
3795 Token string = andAdvance; 3794 Token string = getAndAdvance();
3796 if (_matches(TokenType.STRING_INTERPOLATION_EXPRESSION) || 3795 if (_matches(TokenType.STRING_INTERPOLATION_EXPRESSION) ||
3797 _matches(TokenType.STRING_INTERPOLATION_IDENTIFIER)) { 3796 _matches(TokenType.STRING_INTERPOLATION_IDENTIFIER)) {
3798 strings.add(_parseStringInterpolation(string)); 3797 strings.add(_parseStringInterpolation(string));
3799 } else { 3798 } else {
3800 strings.add( 3799 strings.add(
3801 new SimpleStringLiteral( 3800 new SimpleStringLiteral(
3802 string, 3801 string,
3803 _computeStringValue(string.lexeme, true, true))); 3802 _computeStringValue(string.lexeme, true, true)));
3804 } 3803 }
3805 } 3804 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
3844 * type ::= 3843 * type ::=
3845 * qualified typeArguments? 3844 * qualified typeArguments?
3846 * </pre> 3845 * </pre>
3847 * 3846 *
3848 * @return the type name that was parsed 3847 * @return the type name that was parsed
3849 */ 3848 */
3850 TypeName parseTypeName() { 3849 TypeName parseTypeName() {
3851 Identifier typeName; 3850 Identifier typeName;
3852 if (_matchesKeyword(Keyword.VAR)) { 3851 if (_matchesKeyword(Keyword.VAR)) {
3853 _reportErrorForCurrentToken(ParserErrorCode.VAR_AS_TYPE_NAME); 3852 _reportErrorForCurrentToken(ParserErrorCode.VAR_AS_TYPE_NAME);
3854 typeName = new SimpleIdentifier(andAdvance); 3853 typeName = new SimpleIdentifier(getAndAdvance());
3855 } else if (_matchesIdentifier()) { 3854 } else if (_matchesIdentifier()) {
3856 typeName = parsePrefixedIdentifier(); 3855 typeName = parsePrefixedIdentifier();
3857 } else { 3856 } else {
3858 typeName = _createSyntheticIdentifier(); 3857 typeName = _createSyntheticIdentifier();
3859 _reportErrorForCurrentToken(ParserErrorCode.EXPECTED_TYPE_NAME); 3858 _reportErrorForCurrentToken(ParserErrorCode.EXPECTED_TYPE_NAME);
3860 } 3859 }
3861 TypeArgumentList typeArguments = null; 3860 TypeArgumentList typeArguments = null;
3862 if (_matches(TokenType.LT)) { 3861 if (_matches(TokenType.LT)) {
3863 typeArguments = parseTypeArgumentList(); 3862 typeArguments = parseTypeArgumentList();
3864 } 3863 }
3865 return new TypeName(typeName, typeArguments); 3864 return new TypeName(typeName, typeArguments);
3866 } 3865 }
3867 3866
3868 /** 3867 /**
3869 * Parse a type parameter. 3868 * Parse a type parameter.
3870 * 3869 *
3871 * <pre> 3870 * <pre>
3872 * typeParameter ::= 3871 * typeParameter ::=
3873 * metadata name ('extends' bound)? 3872 * metadata name ('extends' bound)?
3874 * </pre> 3873 * </pre>
3875 * 3874 *
3876 * @return the type parameter that was parsed 3875 * @return the type parameter that was parsed
3877 */ 3876 */
3878 TypeParameter parseTypeParameter() { 3877 TypeParameter parseTypeParameter() {
3879 CommentAndMetadata commentAndMetadata = _parseCommentAndMetadata(); 3878 CommentAndMetadata commentAndMetadata = _parseCommentAndMetadata();
3880 SimpleIdentifier name = parseSimpleIdentifier(); 3879 SimpleIdentifier name = parseSimpleIdentifier();
3881 if (_matchesKeyword(Keyword.EXTENDS)) { 3880 if (_matchesKeyword(Keyword.EXTENDS)) {
3882 Token keyword = andAdvance; 3881 Token keyword = getAndAdvance();
3883 TypeName bound = parseTypeName(); 3882 TypeName bound = parseTypeName();
3884 return new TypeParameter( 3883 return new TypeParameter(
3885 commentAndMetadata.comment, 3884 commentAndMetadata.comment,
3886 commentAndMetadata.metadata, 3885 commentAndMetadata.metadata,
3887 name, 3886 name,
3888 keyword, 3887 keyword,
3889 bound); 3888 bound);
3890 } 3889 }
3891 return new TypeParameter( 3890 return new TypeParameter(
3892 commentAndMetadata.comment, 3891 commentAndMetadata.comment,
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
4168 * the next token. Otherwise report an error and return the current token 4167 * the next token. Otherwise report an error and return the current token
4169 * without advancing. 4168 * without advancing.
4170 * 4169 *
4171 * Note that the method [_expectGt] should be used if the argument to this 4170 * Note that the method [_expectGt] should be used if the argument to this
4172 * method would be [TokenType.GT]. 4171 * method would be [TokenType.GT].
4173 * 4172 *
4174 * The [type] is the type of token that is expected. 4173 * The [type] is the type of token that is expected.
4175 */ 4174 */
4176 Token _expect(TokenType type) { 4175 Token _expect(TokenType type) {
4177 if (_matches(type)) { 4176 if (_matches(type)) {
4178 return andAdvance; 4177 return getAndAdvance();
4179 } 4178 }
4180 // Remove uses of this method in favor of matches? 4179 // Remove uses of this method in favor of matches?
4181 // Pass in the error code to use to report the error? 4180 // Pass in the error code to use to report the error?
4182 if (type == TokenType.SEMICOLON) { 4181 if (type == TokenType.SEMICOLON) {
4183 if (_tokenMatches(_currentToken.next, TokenType.SEMICOLON)) { 4182 if (_tokenMatches(_currentToken.next, TokenType.SEMICOLON)) {
4184 _reportErrorForCurrentToken( 4183 _reportErrorForCurrentToken(
4185 ParserErrorCode.UNEXPECTED_TOKEN, 4184 ParserErrorCode.UNEXPECTED_TOKEN,
4186 [_currentToken.lexeme]); 4185 [_currentToken.lexeme]);
4187 _advance(); 4186 _advance();
4188 return andAdvance; 4187 return getAndAdvance();
4189 } 4188 }
4190 _reportErrorForToken( 4189 _reportErrorForToken(
4191 ParserErrorCode.EXPECTED_TOKEN, 4190 ParserErrorCode.EXPECTED_TOKEN,
4192 _currentToken.previous, 4191 _currentToken.previous,
4193 [type.lexeme]); 4192 [type.lexeme]);
4194 } else { 4193 } else {
4195 _reportErrorForCurrentToken( 4194 _reportErrorForCurrentToken(
4196 ParserErrorCode.EXPECTED_TOKEN, 4195 ParserErrorCode.EXPECTED_TOKEN,
4197 [type.lexeme]); 4196 [type.lexeme]);
4198 } 4197 }
4199 return _currentToken; 4198 return _currentToken;
4200 } 4199 }
4201 4200
4202 /** 4201 /**
4203 * If the current token has the type [TokenType.GT], return it after advancing to the next 4202 * If the current token has the type [TokenType.GT], return it after advancing to the next
4204 * token. Otherwise report an error and return the current token without advan cing. 4203 * token. Otherwise report an error and return the current token without advan cing.
4205 * 4204 *
4206 * @return the token that matched the given type 4205 * @return the token that matched the given type
4207 */ 4206 */
4208 Token _expectGt() { 4207 Token _expectGt() {
4209 if (_matchesGt()) { 4208 if (_matchesGt()) {
4210 return andAdvance; 4209 return getAndAdvance();
4211 } 4210 }
4212 _reportErrorForCurrentToken( 4211 _reportErrorForCurrentToken(
4213 ParserErrorCode.EXPECTED_TOKEN, 4212 ParserErrorCode.EXPECTED_TOKEN,
4214 [TokenType.GT.lexeme]); 4213 [TokenType.GT.lexeme]);
4215 return _currentToken; 4214 return _currentToken;
4216 } 4215 }
4217 4216
4218 /** 4217 /**
4219 * If the current token is a keyword matching the given string, return it afte r advancing to the 4218 * If the current token is a keyword matching the given string, return it afte r advancing to the
4220 * next token. Otherwise report an error and return the current token without advancing. 4219 * next token. Otherwise report an error and return the current token without advancing.
4221 * 4220 *
4222 * @param keyword the keyword that is expected 4221 * @param keyword the keyword that is expected
4223 * @return the token that matched the given type 4222 * @return the token that matched the given type
4224 */ 4223 */
4225 Token _expectKeyword(Keyword keyword) { 4224 Token _expectKeyword(Keyword keyword) {
4226 if (_matchesKeyword(keyword)) { 4225 if (_matchesKeyword(keyword)) {
4227 return andAdvance; 4226 return getAndAdvance();
4228 } 4227 }
4229 // Remove uses of this method in favor of matches? 4228 // Remove uses of this method in favor of matches?
4230 // Pass in the error code to use to report the error? 4229 // Pass in the error code to use to report the error?
4231 _reportErrorForCurrentToken( 4230 _reportErrorForCurrentToken(
4232 ParserErrorCode.EXPECTED_TOKEN, 4231 ParserErrorCode.EXPECTED_TOKEN,
4233 [keyword.syntax]); 4232 [keyword.syntax]);
4234 return _currentToken; 4233 return _currentToken;
4235 } 4234 }
4236 4235
4237 /** 4236 /**
4238 * If [currentToken] is a semicolon, returns it; otherwise reports error and c reates a 4237 * If [currentToken] is a semicolon, returns it; otherwise reports error and c reates a
4239 * synthetic one. 4238 * synthetic one.
4240 * 4239 *
4241 * TODO(scheglov) consider pushing this into [expect] 4240 * TODO(scheglov) consider pushing this into [expect]
4242 */ 4241 */
4243 Token _expectSemicolon() { 4242 Token _expectSemicolon() {
4244 if (_matches(TokenType.SEMICOLON)) { 4243 if (_matches(TokenType.SEMICOLON)) {
4245 return andAdvance; 4244 return getAndAdvance();
4246 } else { 4245 } else {
4247 _reportErrorForToken( 4246 _reportErrorForToken(
4248 ParserErrorCode.EXPECTED_TOKEN, 4247 ParserErrorCode.EXPECTED_TOKEN,
4249 _currentToken.previous, 4248 _currentToken.previous,
4250 [";"]); 4249 [";"]);
4251 return _createSyntheticToken(TokenType.SEMICOLON); 4250 return _createSyntheticToken(TokenType.SEMICOLON);
4252 } 4251 }
4253 } 4252 }
4254 4253
4255 /** 4254 /**
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
4724 * multiplicativeExpression (additiveOperator multiplicativeExpression)* 4723 * multiplicativeExpression (additiveOperator multiplicativeExpression)*
4725 * | 'super' (additiveOperator multiplicativeExpression)+ 4724 * | 'super' (additiveOperator multiplicativeExpression)+
4726 * </pre> 4725 * </pre>
4727 * 4726 *
4728 * @return the additive expression that was parsed 4727 * @return the additive expression that was parsed
4729 */ 4728 */
4730 Expression _parseAdditiveExpression() { 4729 Expression _parseAdditiveExpression() {
4731 Expression expression; 4730 Expression expression;
4732 if (_matchesKeyword(Keyword.SUPER) && 4731 if (_matchesKeyword(Keyword.SUPER) &&
4733 _currentToken.next.type.isAdditiveOperator) { 4732 _currentToken.next.type.isAdditiveOperator) {
4734 expression = new SuperExpression(andAdvance); 4733 expression = new SuperExpression(getAndAdvance());
4735 } else { 4734 } else {
4736 expression = _parseMultiplicativeExpression(); 4735 expression = _parseMultiplicativeExpression();
4737 } 4736 }
4738 while (_currentToken.type.isAdditiveOperator) { 4737 while (_currentToken.type.isAdditiveOperator) {
4739 Token operator = andAdvance; 4738 Token operator = getAndAdvance();
4740 expression = 4739 expression =
4741 new BinaryExpression(expression, operator, _parseMultiplicativeExpress ion()); 4740 new BinaryExpression(expression, operator, _parseMultiplicativeExpress ion());
4742 } 4741 }
4743 return expression; 4742 return expression;
4744 } 4743 }
4745 4744
4746 /** 4745 /**
4747 * Parse an assert statement. 4746 * Parse an assert statement.
4748 * 4747 *
4749 * <pre> 4748 * <pre>
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
4793 * | 'super' assignableSelector 4792 * | 'super' assignableSelector
4794 * | identifier 4793 * | identifier
4795 * </pre> 4794 * </pre>
4796 * 4795 *
4797 * @param primaryAllowed `true` if the expression is allowed to be a primary w ithout any 4796 * @param primaryAllowed `true` if the expression is allowed to be a primary w ithout any
4798 * assignable selector 4797 * assignable selector
4799 * @return the assignable expression that was parsed 4798 * @return the assignable expression that was parsed
4800 */ 4799 */
4801 Expression _parseAssignableExpression(bool primaryAllowed) { 4800 Expression _parseAssignableExpression(bool primaryAllowed) {
4802 if (_matchesKeyword(Keyword.SUPER)) { 4801 if (_matchesKeyword(Keyword.SUPER)) {
4803 return _parseAssignableSelector(new SuperExpression(andAdvance), false); 4802 return _parseAssignableSelector(new SuperExpression(getAndAdvance()), fals e);
4804 } 4803 }
4805 // 4804 //
4806 // A primary expression can start with an identifier. We resolve the 4805 // A primary expression can start with an identifier. We resolve the
4807 // ambiguity by determining whether the primary consists of anything other 4806 // ambiguity by determining whether the primary consists of anything other
4808 // than an identifier and/or is followed by an assignableSelector. 4807 // than an identifier and/or is followed by an assignableSelector.
4809 // 4808 //
4810 Expression expression = _parsePrimaryExpression(); 4809 Expression expression = _parsePrimaryExpression();
4811 bool isOptional = primaryAllowed || expression is SimpleIdentifier; 4810 bool isOptional = primaryAllowed || expression is SimpleIdentifier;
4812 while (true) { 4811 while (true) {
4813 while (_matches(TokenType.OPEN_PAREN)) { 4812 while (_matches(TokenType.OPEN_PAREN)) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
4864 * | '.' identifier 4863 * | '.' identifier
4865 * </pre> 4864 * </pre>
4866 * 4865 *
4867 * @param prefix the expression preceding the selector 4866 * @param prefix the expression preceding the selector
4868 * @param optional `true` if the selector is optional 4867 * @param optional `true` if the selector is optional
4869 * @return the assignable selector that was parsed, or the original prefix if there was no 4868 * @return the assignable selector that was parsed, or the original prefix if there was no
4870 * assignable selector 4869 * assignable selector
4871 */ 4870 */
4872 Expression _parseAssignableSelector(Expression prefix, bool optional) { 4871 Expression _parseAssignableSelector(Expression prefix, bool optional) {
4873 if (_matches(TokenType.OPEN_SQUARE_BRACKET)) { 4872 if (_matches(TokenType.OPEN_SQUARE_BRACKET)) {
4874 Token leftBracket = andAdvance; 4873 Token leftBracket = getAndAdvance();
4875 bool wasInInitializer = _inInitializer; 4874 bool wasInInitializer = _inInitializer;
4876 _inInitializer = false; 4875 _inInitializer = false;
4877 try { 4876 try {
4878 Expression index = parseExpression2(); 4877 Expression index = parseExpression2();
4879 Token rightBracket = _expect(TokenType.CLOSE_SQUARE_BRACKET); 4878 Token rightBracket = _expect(TokenType.CLOSE_SQUARE_BRACKET);
4880 return new IndexExpression.forTarget( 4879 return new IndexExpression.forTarget(
4881 prefix, 4880 prefix,
4882 leftBracket, 4881 leftBracket,
4883 index, 4882 index,
4884 rightBracket); 4883 rightBracket);
4885 } finally { 4884 } finally {
4886 _inInitializer = wasInInitializer; 4885 _inInitializer = wasInInitializer;
4887 } 4886 }
4888 } else if (_matches(TokenType.PERIOD)) { 4887 } else if (_matches(TokenType.PERIOD)) {
4889 Token period = andAdvance; 4888 Token period = getAndAdvance();
4890 return new PropertyAccess(prefix, period, parseSimpleIdentifier()); 4889 return new PropertyAccess(prefix, period, parseSimpleIdentifier());
4891 } else { 4890 } else {
4892 if (!optional) { 4891 if (!optional) {
4893 // Report the missing selector. 4892 // Report the missing selector.
4894 _reportErrorForCurrentToken( 4893 _reportErrorForCurrentToken(
4895 ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR); 4894 ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR);
4896 } 4895 }
4897 return prefix; 4896 return prefix;
4898 } 4897 }
4899 } 4898 }
4900 4899
4901 /** 4900 /**
4902 * Parse a await expression. 4901 * Parse a await expression.
4903 * 4902 *
4904 * <pre> 4903 * <pre>
4905 * awaitExpression ::= 4904 * awaitExpression ::=
4906 * 'await' unaryExpression 4905 * 'await' unaryExpression
4907 * </pre> 4906 * </pre>
4908 * 4907 *
4909 * @return the await expression that was parsed 4908 * @return the await expression that was parsed
4910 */ 4909 */
4911 AwaitExpression _parseAwaitExpression() { 4910 AwaitExpression _parseAwaitExpression() {
4912 Token awaitToken = andAdvance; 4911 Token awaitToken = getAndAdvance();
4913 Expression expression = _parseUnaryExpression(); 4912 Expression expression = _parseUnaryExpression();
4914 return new AwaitExpression(awaitToken, expression); 4913 return new AwaitExpression(awaitToken, expression);
4915 } 4914 }
4916 4915
4917 /** 4916 /**
4918 * Parse a bitwise and expression. 4917 * Parse a bitwise and expression.
4919 * 4918 *
4920 * <pre> 4919 * <pre>
4921 * bitwiseAndExpression ::= 4920 * bitwiseAndExpression ::=
4922 * shiftExpression ('&' shiftExpression)* 4921 * shiftExpression ('&' shiftExpression)*
4923 * | 'super' ('&' shiftExpression)+ 4922 * | 'super' ('&' shiftExpression)+
4924 * </pre> 4923 * </pre>
4925 * 4924 *
4926 * @return the bitwise and expression that was parsed 4925 * @return the bitwise and expression that was parsed
4927 */ 4926 */
4928 Expression _parseBitwiseAndExpression() { 4927 Expression _parseBitwiseAndExpression() {
4929 Expression expression; 4928 Expression expression;
4930 if (_matchesKeyword(Keyword.SUPER) && 4929 if (_matchesKeyword(Keyword.SUPER) &&
4931 _tokenMatches(_peek(), TokenType.AMPERSAND)) { 4930 _tokenMatches(_peek(), TokenType.AMPERSAND)) {
4932 expression = new SuperExpression(andAdvance); 4931 expression = new SuperExpression(getAndAdvance());
4933 } else { 4932 } else {
4934 expression = _parseShiftExpression(); 4933 expression = _parseShiftExpression();
4935 } 4934 }
4936 while (_matches(TokenType.AMPERSAND)) { 4935 while (_matches(TokenType.AMPERSAND)) {
4937 Token operator = andAdvance; 4936 Token operator = getAndAdvance();
4938 expression = 4937 expression =
4939 new BinaryExpression(expression, operator, _parseShiftExpression()); 4938 new BinaryExpression(expression, operator, _parseShiftExpression());
4940 } 4939 }
4941 return expression; 4940 return expression;
4942 } 4941 }
4943 4942
4944 /** 4943 /**
4945 * Parse a bitwise exclusive-or expression. 4944 * Parse a bitwise exclusive-or expression.
4946 * 4945 *
4947 * <pre> 4946 * <pre>
4948 * bitwiseXorExpression ::= 4947 * bitwiseXorExpression ::=
4949 * bitwiseAndExpression ('^' bitwiseAndExpression)* 4948 * bitwiseAndExpression ('^' bitwiseAndExpression)*
4950 * | 'super' ('^' bitwiseAndExpression)+ 4949 * | 'super' ('^' bitwiseAndExpression)+
4951 * </pre> 4950 * </pre>
4952 * 4951 *
4953 * @return the bitwise exclusive-or expression that was parsed 4952 * @return the bitwise exclusive-or expression that was parsed
4954 */ 4953 */
4955 Expression _parseBitwiseXorExpression() { 4954 Expression _parseBitwiseXorExpression() {
4956 Expression expression; 4955 Expression expression;
4957 if (_matchesKeyword(Keyword.SUPER) && 4956 if (_matchesKeyword(Keyword.SUPER) &&
4958 _tokenMatches(_peek(), TokenType.CARET)) { 4957 _tokenMatches(_peek(), TokenType.CARET)) {
4959 expression = new SuperExpression(andAdvance); 4958 expression = new SuperExpression(getAndAdvance());
4960 } else { 4959 } else {
4961 expression = _parseBitwiseAndExpression(); 4960 expression = _parseBitwiseAndExpression();
4962 } 4961 }
4963 while (_matches(TokenType.CARET)) { 4962 while (_matches(TokenType.CARET)) {
4964 Token operator = andAdvance; 4963 Token operator = getAndAdvance();
4965 expression = 4964 expression =
4966 new BinaryExpression(expression, operator, _parseBitwiseAndExpression( )); 4965 new BinaryExpression(expression, operator, _parseBitwiseAndExpression( ));
4967 } 4966 }
4968 return expression; 4967 return expression;
4969 } 4968 }
4970 4969
4971 /** 4970 /**
4972 * Parse a break statement. 4971 * Parse a break statement.
4973 * 4972 *
4974 * <pre> 4973 * <pre>
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
5008 * 5007 *
5009 * @return the expression representing the cascaded method invocation 5008 * @return the expression representing the cascaded method invocation
5010 */ 5009 */
5011 Expression _parseCascadeSection() { 5010 Expression _parseCascadeSection() {
5012 Token period = _expect(TokenType.PERIOD_PERIOD); 5011 Token period = _expect(TokenType.PERIOD_PERIOD);
5013 Expression expression = null; 5012 Expression expression = null;
5014 SimpleIdentifier functionName = null; 5013 SimpleIdentifier functionName = null;
5015 if (_matchesIdentifier()) { 5014 if (_matchesIdentifier()) {
5016 functionName = parseSimpleIdentifier(); 5015 functionName = parseSimpleIdentifier();
5017 } else if (_currentToken.type == TokenType.OPEN_SQUARE_BRACKET) { 5016 } else if (_currentToken.type == TokenType.OPEN_SQUARE_BRACKET) {
5018 Token leftBracket = andAdvance; 5017 Token leftBracket = getAndAdvance();
5019 bool wasInInitializer = _inInitializer; 5018 bool wasInInitializer = _inInitializer;
5020 _inInitializer = false; 5019 _inInitializer = false;
5021 try { 5020 try {
5022 Expression index = parseExpression2(); 5021 Expression index = parseExpression2();
5023 Token rightBracket = _expect(TokenType.CLOSE_SQUARE_BRACKET); 5022 Token rightBracket = _expect(TokenType.CLOSE_SQUARE_BRACKET);
5024 expression = 5023 expression =
5025 new IndexExpression.forCascade(period, leftBracket, index, rightBrac ket); 5024 new IndexExpression.forCascade(period, leftBracket, index, rightBrac ket);
5026 period = null; 5025 period = null;
5027 } finally { 5026 } finally {
5028 _inInitializer = wasInInitializer; 5027 _inInitializer = wasInInitializer;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
5076 propertyAccess.propertyName, 5075 propertyAccess.propertyName,
5077 parseArgumentList()); 5076 parseArgumentList());
5078 } else { 5077 } else {
5079 expression = 5078 expression =
5080 new FunctionExpressionInvocation(expression, parseArgumentList() ); 5079 new FunctionExpressionInvocation(expression, parseArgumentList() );
5081 } 5080 }
5082 } 5081 }
5083 } 5082 }
5084 } 5083 }
5085 if (_currentToken.type.isAssignmentOperator) { 5084 if (_currentToken.type.isAssignmentOperator) {
5086 Token operator = andAdvance; 5085 Token operator = getAndAdvance();
5087 _ensureAssignable(expression); 5086 _ensureAssignable(expression);
5088 expression = new AssignmentExpression( 5087 expression = new AssignmentExpression(
5089 expression, 5088 expression,
5090 operator, 5089 operator,
5091 parseExpressionWithoutCascade()); 5090 parseExpressionWithoutCascade());
5092 } 5091 }
5093 return expression; 5092 return expression;
5094 } 5093 }
5095 5094
5096 /** 5095 /**
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
5313 _reportErrorForCurrentToken( 5312 _reportErrorForCurrentToken(
5314 ParserErrorCode.EXPECTED_TOKEN, 5313 ParserErrorCode.EXPECTED_TOKEN,
5315 [Keyword.WITH.syntax]); 5314 [Keyword.WITH.syntax]);
5316 } 5315 }
5317 ImplementsClause implementsClause = null; 5316 ImplementsClause implementsClause = null;
5318 if (_matchesKeyword(Keyword.IMPLEMENTS)) { 5317 if (_matchesKeyword(Keyword.IMPLEMENTS)) {
5319 implementsClause = parseImplementsClause(); 5318 implementsClause = parseImplementsClause();
5320 } 5319 }
5321 Token semicolon; 5320 Token semicolon;
5322 if (_matches(TokenType.SEMICOLON)) { 5321 if (_matches(TokenType.SEMICOLON)) {
5323 semicolon = andAdvance; 5322 semicolon = getAndAdvance();
5324 } else { 5323 } else {
5325 if (_matches(TokenType.OPEN_CURLY_BRACKET)) { 5324 if (_matches(TokenType.OPEN_CURLY_BRACKET)) {
5326 _reportErrorForCurrentToken( 5325 _reportErrorForCurrentToken(
5327 ParserErrorCode.EXPECTED_TOKEN, 5326 ParserErrorCode.EXPECTED_TOKEN,
5328 [TokenType.SEMICOLON.lexeme]); 5327 [TokenType.SEMICOLON.lexeme]);
5329 Token leftBracket = andAdvance; 5328 Token leftBracket = getAndAdvance();
5330 _parseClassMembers(className.name, _getEndToken(leftBracket)); 5329 _parseClassMembers(className.name, _getEndToken(leftBracket));
5331 _expect(TokenType.CLOSE_CURLY_BRACKET); 5330 _expect(TokenType.CLOSE_CURLY_BRACKET);
5332 } else { 5331 } else {
5333 _reportErrorForToken( 5332 _reportErrorForToken(
5334 ParserErrorCode.EXPECTED_TOKEN, 5333 ParserErrorCode.EXPECTED_TOKEN,
5335 _currentToken.previous, 5334 _currentToken.previous,
5336 [TokenType.SEMICOLON.lexeme]); 5335 [TokenType.SEMICOLON.lexeme]);
5337 } 5336 }
5338 semicolon = _createSyntheticToken(TokenType.SEMICOLON); 5337 semicolon = _createSyntheticToken(TokenType.SEMICOLON);
5339 } 5338 }
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
5708 null, 5707 null,
5709 _validateModifiersForTopLevelVariable(modifiers), 5708 _validateModifiersForTopLevelVariable(modifiers),
5710 returnType), 5709 returnType),
5711 _expect(TokenType.SEMICOLON)); 5710 _expect(TokenType.SEMICOLON));
5712 } else if (!_matchesIdentifier()) { 5711 } else if (!_matchesIdentifier()) {
5713 // TODO(brianwilkerson) Generalize this error. We could also be parsing a 5712 // TODO(brianwilkerson) Generalize this error. We could also be parsing a
5714 // top-level variable at this point. 5713 // top-level variable at this point.
5715 _reportErrorForToken(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken); 5714 _reportErrorForToken(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken);
5716 Token semicolon; 5715 Token semicolon;
5717 if (_matches(TokenType.SEMICOLON)) { 5716 if (_matches(TokenType.SEMICOLON)) {
5718 semicolon = andAdvance; 5717 semicolon = getAndAdvance();
5719 } else { 5718 } else {
5720 semicolon = _createSyntheticToken(TokenType.SEMICOLON); 5719 semicolon = _createSyntheticToken(TokenType.SEMICOLON);
5721 } 5720 }
5722 List<VariableDeclaration> variables = new List<VariableDeclaration>(); 5721 List<VariableDeclaration> variables = new List<VariableDeclaration>();
5723 variables.add( 5722 variables.add(
5724 new VariableDeclaration(null, null, _createSyntheticIdentifier(), null , null)); 5723 new VariableDeclaration(null, null, _createSyntheticIdentifier(), null , null));
5725 return new TopLevelVariableDeclaration( 5724 return new TopLevelVariableDeclaration(
5726 commentAndMetadata.comment, 5725 commentAndMetadata.comment,
5727 commentAndMetadata.metadata, 5726 commentAndMetadata.metadata,
5728 new VariableDeclarationList(null, null, null, returnType, variables), 5727 new VariableDeclarationList(null, null, null, returnType, variables),
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
5771 } 5770 }
5772 5771
5773 ConstructorDeclaration 5772 ConstructorDeclaration
5774 _parseConstructor(CommentAndMetadata commentAndMetadata, Token externalKey word, 5773 _parseConstructor(CommentAndMetadata commentAndMetadata, Token externalKey word,
5775 Token constKeyword, Token factoryKeyword, SimpleIdentifier returnType, 5774 Token constKeyword, Token factoryKeyword, SimpleIdentifier returnType,
5776 Token period, SimpleIdentifier name, FormalParameterList parameters) { 5775 Token period, SimpleIdentifier name, FormalParameterList parameters) {
5777 bool bodyAllowed = externalKeyword == null; 5776 bool bodyAllowed = externalKeyword == null;
5778 Token separator = null; 5777 Token separator = null;
5779 List<ConstructorInitializer> initializers = null; 5778 List<ConstructorInitializer> initializers = null;
5780 if (_matches(TokenType.COLON)) { 5779 if (_matches(TokenType.COLON)) {
5781 separator = andAdvance; 5780 separator = getAndAdvance();
5782 initializers = new List<ConstructorInitializer>(); 5781 initializers = new List<ConstructorInitializer>();
5783 do { 5782 do {
5784 if (_matchesKeyword(Keyword.THIS)) { 5783 if (_matchesKeyword(Keyword.THIS)) {
5785 if (_tokenMatches(_peek(), TokenType.OPEN_PAREN)) { 5784 if (_tokenMatches(_peek(), TokenType.OPEN_PAREN)) {
5786 bodyAllowed = false; 5785 bodyAllowed = false;
5787 initializers.add(_parseRedirectingConstructorInvocation()); 5786 initializers.add(_parseRedirectingConstructorInvocation());
5788 } else if (_tokenMatches(_peek(), TokenType.PERIOD) && 5787 } else if (_tokenMatches(_peek(), TokenType.PERIOD) &&
5789 _tokenMatches(_peekAt(3), TokenType.OPEN_PAREN)) { 5788 _tokenMatches(_peekAt(3), TokenType.OPEN_PAREN)) {
5790 bodyAllowed = false; 5789 bodyAllowed = false;
5791 initializers.add(_parseRedirectingConstructorInvocation()); 5790 initializers.add(_parseRedirectingConstructorInvocation());
(...skipping 11 matching lines...) Expand all
5803 } while (_optional(TokenType.COMMA)); 5802 } while (_optional(TokenType.COMMA));
5804 if (factoryKeyword != null) { 5803 if (factoryKeyword != null) {
5805 _reportErrorForToken( 5804 _reportErrorForToken(
5806 ParserErrorCode.FACTORY_WITH_INITIALIZERS, 5805 ParserErrorCode.FACTORY_WITH_INITIALIZERS,
5807 factoryKeyword); 5806 factoryKeyword);
5808 } 5807 }
5809 } 5808 }
5810 ConstructorName redirectedConstructor = null; 5809 ConstructorName redirectedConstructor = null;
5811 FunctionBody body; 5810 FunctionBody body;
5812 if (_matches(TokenType.EQ)) { 5811 if (_matches(TokenType.EQ)) {
5813 separator = andAdvance; 5812 separator = getAndAdvance();
5814 redirectedConstructor = parseConstructorName(); 5813 redirectedConstructor = parseConstructorName();
5815 body = new EmptyFunctionBody(_expect(TokenType.SEMICOLON)); 5814 body = new EmptyFunctionBody(_expect(TokenType.SEMICOLON));
5816 if (factoryKeyword == null) { 5815 if (factoryKeyword == null) {
5817 _reportErrorForNode( 5816 _reportErrorForNode(
5818 ParserErrorCode.REDIRECTION_IN_NON_FACTORY_CONSTRUCTOR, 5817 ParserErrorCode.REDIRECTION_IN_NON_FACTORY_CONSTRUCTOR,
5819 redirectedConstructor); 5818 redirectedConstructor);
5820 } 5819 }
5821 } else { 5820 } else {
5822 body = 5821 body =
5823 _parseFunctionBody(true, ParserErrorCode.MISSING_FUNCTION_BODY, false) ; 5822 _parseFunctionBody(true, ParserErrorCode.MISSING_FUNCTION_BODY, false) ;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
5866 * fieldInitializer: 5865 * fieldInitializer:
5867 * ('this' '.')? identifier '=' conditionalExpression cascadeSection* 5866 * ('this' '.')? identifier '=' conditionalExpression cascadeSection*
5868 * </pre> 5867 * </pre>
5869 * 5868 *
5870 * @return the field initializer that was parsed 5869 * @return the field initializer that was parsed
5871 */ 5870 */
5872 ConstructorFieldInitializer _parseConstructorFieldInitializer() { 5871 ConstructorFieldInitializer _parseConstructorFieldInitializer() {
5873 Token keyword = null; 5872 Token keyword = null;
5874 Token period = null; 5873 Token period = null;
5875 if (_matchesKeyword(Keyword.THIS)) { 5874 if (_matchesKeyword(Keyword.THIS)) {
5876 keyword = andAdvance; 5875 keyword = getAndAdvance();
5877 period = _expect(TokenType.PERIOD); 5876 period = _expect(TokenType.PERIOD);
5878 } 5877 }
5879 SimpleIdentifier fieldName = parseSimpleIdentifier(); 5878 SimpleIdentifier fieldName = parseSimpleIdentifier();
5880 Token equals = null; 5879 Token equals = null;
5881 if (_matches(TokenType.EQ)) { 5880 if (_matches(TokenType.EQ)) {
5882 equals = andAdvance; 5881 equals = getAndAdvance();
5883 } else if (!_matchesKeyword(Keyword.THIS) && 5882 } else if (!_matchesKeyword(Keyword.THIS) &&
5884 !_matchesKeyword(Keyword.SUPER) && 5883 !_matchesKeyword(Keyword.SUPER) &&
5885 !_matches(TokenType.OPEN_CURLY_BRACKET) && 5884 !_matches(TokenType.OPEN_CURLY_BRACKET) &&
5886 !_matches(TokenType.FUNCTION)) { 5885 !_matches(TokenType.FUNCTION)) {
5887 _reportErrorForCurrentToken( 5886 _reportErrorForCurrentToken(
5888 ParserErrorCode.MISSING_ASSIGNMENT_IN_INITIALIZER); 5887 ParserErrorCode.MISSING_ASSIGNMENT_IN_INITIALIZER);
5889 equals = _createSyntheticToken(TokenType.EQ); 5888 equals = _createSyntheticToken(TokenType.EQ);
5890 } else { 5889 } else {
5891 _reportErrorForCurrentToken( 5890 _reportErrorForCurrentToken(
5892 ParserErrorCode.MISSING_ASSIGNMENT_IN_INITIALIZER); 5891 ParserErrorCode.MISSING_ASSIGNMENT_IN_INITIALIZER);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
5994 * compilationUnit ::= 5993 * compilationUnit ::=
5995 * scriptTag? directive* 5994 * scriptTag? directive*
5996 * </pre> 5995 * </pre>
5997 * 5996 *
5998 * @return the compilation unit that was parsed 5997 * @return the compilation unit that was parsed
5999 */ 5998 */
6000 CompilationUnit _parseDirectives() { 5999 CompilationUnit _parseDirectives() {
6001 Token firstToken = _currentToken; 6000 Token firstToken = _currentToken;
6002 ScriptTag scriptTag = null; 6001 ScriptTag scriptTag = null;
6003 if (_matches(TokenType.SCRIPT_TAG)) { 6002 if (_matches(TokenType.SCRIPT_TAG)) {
6004 scriptTag = new ScriptTag(andAdvance); 6003 scriptTag = new ScriptTag(getAndAdvance());
6005 } 6004 }
6006 List<Directive> directives = new List<Directive>(); 6005 List<Directive> directives = new List<Directive>();
6007 while (!_matches(TokenType.EOF)) { 6006 while (!_matches(TokenType.EOF)) {
6008 CommentAndMetadata commentAndMetadata = _parseCommentAndMetadata(); 6007 CommentAndMetadata commentAndMetadata = _parseCommentAndMetadata();
6009 if ((_matchesKeyword(Keyword.IMPORT) || 6008 if ((_matchesKeyword(Keyword.IMPORT) ||
6010 _matchesKeyword(Keyword.EXPORT) || 6009 _matchesKeyword(Keyword.EXPORT) ||
6011 _matchesKeyword(Keyword.LIBRARY) || 6010 _matchesKeyword(Keyword.LIBRARY) ||
6012 _matchesKeyword(Keyword.PART)) && 6011 _matchesKeyword(Keyword.PART)) &&
6013 !_tokenMatches(_peek(), TokenType.PERIOD) && 6012 !_tokenMatches(_peek(), TokenType.PERIOD) &&
6014 !_tokenMatches(_peek(), TokenType.LT) && 6013 !_tokenMatches(_peek(), TokenType.LT) &&
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
6114 /** 6113 /**
6115 * Parse an empty statement. 6114 * Parse an empty statement.
6116 * 6115 *
6117 * <pre> 6116 * <pre>
6118 * emptyStatement ::= 6117 * emptyStatement ::=
6119 * ';' 6118 * ';'
6120 * </pre> 6119 * </pre>
6121 * 6120 *
6122 * @return the empty statement that was parsed 6121 * @return the empty statement that was parsed
6123 */ 6122 */
6124 Statement _parseEmptyStatement() => new EmptyStatement(andAdvance); 6123 Statement _parseEmptyStatement() => new EmptyStatement(getAndAdvance());
6125 6124
6126 EnumConstantDeclaration _parseEnumConstantDeclaration() { 6125 EnumConstantDeclaration _parseEnumConstantDeclaration() {
6127 CommentAndMetadata commentAndMetadata = _parseCommentAndMetadata(); 6126 CommentAndMetadata commentAndMetadata = _parseCommentAndMetadata();
6128 SimpleIdentifier name; 6127 SimpleIdentifier name;
6129 if (_matchesIdentifier()) { 6128 if (_matchesIdentifier()) {
6130 name = parseSimpleIdentifier(); 6129 name = parseSimpleIdentifier();
6131 } else { 6130 } else {
6132 name = _createSyntheticIdentifier(); 6131 name = _createSyntheticIdentifier();
6133 } 6132 }
6134 return new EnumConstantDeclaration( 6133 return new EnumConstantDeclaration(
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
6197 * relationalExpression (equalityOperator relationalExpression)? 6196 * relationalExpression (equalityOperator relationalExpression)?
6198 * | 'super' equalityOperator relationalExpression 6197 * | 'super' equalityOperator relationalExpression
6199 * </pre> 6198 * </pre>
6200 * 6199 *
6201 * @return the equality expression that was parsed 6200 * @return the equality expression that was parsed
6202 */ 6201 */
6203 Expression _parseEqualityExpression() { 6202 Expression _parseEqualityExpression() {
6204 Expression expression; 6203 Expression expression;
6205 if (_matchesKeyword(Keyword.SUPER) && 6204 if (_matchesKeyword(Keyword.SUPER) &&
6206 _currentToken.next.type.isEqualityOperator) { 6205 _currentToken.next.type.isEqualityOperator) {
6207 expression = new SuperExpression(andAdvance); 6206 expression = new SuperExpression(getAndAdvance());
6208 } else { 6207 } else {
6209 expression = _parseRelationalExpression(); 6208 expression = _parseRelationalExpression();
6210 } 6209 }
6211 bool leftEqualityExpression = false; 6210 bool leftEqualityExpression = false;
6212 while (_currentToken.type.isEqualityOperator) { 6211 while (_currentToken.type.isEqualityOperator) {
6213 Token operator = andAdvance; 6212 Token operator = getAndAdvance();
6214 if (leftEqualityExpression) { 6213 if (leftEqualityExpression) {
6215 _reportErrorForNode( 6214 _reportErrorForNode(
6216 ParserErrorCode.EQUALITY_CANNOT_BE_EQUALITY_OPERAND, 6215 ParserErrorCode.EQUALITY_CANNOT_BE_EQUALITY_OPERAND,
6217 expression); 6216 expression);
6218 } 6217 }
6219 expression = 6218 expression =
6220 new BinaryExpression(expression, operator, _parseRelationalExpression( )); 6219 new BinaryExpression(expression, operator, _parseRelationalExpression( ));
6221 leftEqualityExpression = true; 6220 leftEqualityExpression = true;
6222 } 6221 }
6223 return expression; 6222 return expression;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
6278 * | type 6277 * | type
6279 * </pre> 6278 * </pre>
6280 * 6279 *
6281 * @param optional `true` if the keyword and type are optional 6280 * @param optional `true` if the keyword and type are optional
6282 * @return the 'final', 'const', 'var' or type that was parsed 6281 * @return the 'final', 'const', 'var' or type that was parsed
6283 */ 6282 */
6284 FinalConstVarOrType _parseFinalConstVarOrType(bool optional) { 6283 FinalConstVarOrType _parseFinalConstVarOrType(bool optional) {
6285 Token keyword = null; 6284 Token keyword = null;
6286 TypeName type = null; 6285 TypeName type = null;
6287 if (_matchesKeyword(Keyword.FINAL) || _matchesKeyword(Keyword.CONST)) { 6286 if (_matchesKeyword(Keyword.FINAL) || _matchesKeyword(Keyword.CONST)) {
6288 keyword = andAdvance; 6287 keyword = getAndAdvance();
6289 if (_isTypedIdentifier(_currentToken)) { 6288 if (_isTypedIdentifier(_currentToken)) {
6290 type = parseTypeName(); 6289 type = parseTypeName();
6291 } 6290 }
6292 } else if (_matchesKeyword(Keyword.VAR)) { 6291 } else if (_matchesKeyword(Keyword.VAR)) {
6293 keyword = andAdvance; 6292 keyword = getAndAdvance();
6294 } else { 6293 } else {
6295 if (_isTypedIdentifier(_currentToken)) { 6294 if (_isTypedIdentifier(_currentToken)) {
6296 type = parseReturnType(); 6295 type = parseReturnType();
6297 } else if (!optional) { 6296 } else if (!optional) {
6298 _reportErrorForCurrentToken( 6297 _reportErrorForCurrentToken(
6299 ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE); 6298 ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE);
6300 } 6299 }
6301 } 6300 }
6302 return new FinalConstVarOrType(keyword, type); 6301 return new FinalConstVarOrType(keyword, type);
6303 } 6302 }
(...skipping 10 matching lines...) Expand all
6314 * normalFormalParameter (':' expression)? 6313 * normalFormalParameter (':' expression)?
6315 * </pre> 6314 * </pre>
6316 * 6315 *
6317 * @param kind the kind of parameter being expected based on the presence or a bsence of group 6316 * @param kind the kind of parameter being expected based on the presence or a bsence of group
6318 * delimiters 6317 * delimiters
6319 * @return the formal parameter that was parsed 6318 * @return the formal parameter that was parsed
6320 */ 6319 */
6321 FormalParameter _parseFormalParameter(ParameterKind kind) { 6320 FormalParameter _parseFormalParameter(ParameterKind kind) {
6322 NormalFormalParameter parameter = parseNormalFormalParameter(); 6321 NormalFormalParameter parameter = parseNormalFormalParameter();
6323 if (_matches(TokenType.EQ)) { 6322 if (_matches(TokenType.EQ)) {
6324 Token seperator = andAdvance; 6323 Token seperator = getAndAdvance();
6325 Expression defaultValue = parseExpression2(); 6324 Expression defaultValue = parseExpression2();
6326 if (kind == ParameterKind.NAMED) { 6325 if (kind == ParameterKind.NAMED) {
6327 _reportErrorForToken( 6326 _reportErrorForToken(
6328 ParserErrorCode.WRONG_SEPARATOR_FOR_NAMED_PARAMETER, 6327 ParserErrorCode.WRONG_SEPARATOR_FOR_NAMED_PARAMETER,
6329 seperator); 6328 seperator);
6330 } else if (kind == ParameterKind.REQUIRED) { 6329 } else if (kind == ParameterKind.REQUIRED) {
6331 _reportErrorForNode( 6330 _reportErrorForNode(
6332 ParserErrorCode.POSITIONAL_PARAMETER_OUTSIDE_GROUP, 6331 ParserErrorCode.POSITIONAL_PARAMETER_OUTSIDE_GROUP,
6333 parameter); 6332 parameter);
6334 } 6333 }
6335 return new DefaultFormalParameter( 6334 return new DefaultFormalParameter(
6336 parameter, 6335 parameter,
6337 kind, 6336 kind,
6338 seperator, 6337 seperator,
6339 defaultValue); 6338 defaultValue);
6340 } else if (_matches(TokenType.COLON)) { 6339 } else if (_matches(TokenType.COLON)) {
6341 Token seperator = andAdvance; 6340 Token seperator = getAndAdvance();
6342 Expression defaultValue = parseExpression2(); 6341 Expression defaultValue = parseExpression2();
6343 if (kind == ParameterKind.POSITIONAL) { 6342 if (kind == ParameterKind.POSITIONAL) {
6344 _reportErrorForToken( 6343 _reportErrorForToken(
6345 ParserErrorCode.WRONG_SEPARATOR_FOR_POSITIONAL_PARAMETER, 6344 ParserErrorCode.WRONG_SEPARATOR_FOR_POSITIONAL_PARAMETER,
6346 seperator); 6345 seperator);
6347 } else if (kind == ParameterKind.REQUIRED) { 6346 } else if (kind == ParameterKind.REQUIRED) {
6348 _reportErrorForNode( 6347 _reportErrorForNode(
6349 ParserErrorCode.NAMED_PARAMETER_OUTSIDE_GROUP, 6348 ParserErrorCode.NAMED_PARAMETER_OUTSIDE_GROUP,
6350 parameter); 6349 parameter);
6351 } 6350 }
(...skipping 26 matching lines...) Expand all
6378 * </pre> 6377 * </pre>
6379 * 6378 *
6380 * @return the for statement that was parsed 6379 * @return the for statement that was parsed
6381 */ 6380 */
6382 Statement _parseForStatement() { 6381 Statement _parseForStatement() {
6383 bool wasInLoop = _inLoop; 6382 bool wasInLoop = _inLoop;
6384 _inLoop = true; 6383 _inLoop = true;
6385 try { 6384 try {
6386 Token awaitKeyword = null; 6385 Token awaitKeyword = null;
6387 if (_matchesString(_AWAIT)) { 6386 if (_matchesString(_AWAIT)) {
6388 awaitKeyword = andAdvance; 6387 awaitKeyword = getAndAdvance();
6389 } 6388 }
6390 Token forKeyword = _expectKeyword(Keyword.FOR); 6389 Token forKeyword = _expectKeyword(Keyword.FOR);
6391 Token leftParenthesis = _expect(TokenType.OPEN_PAREN); 6390 Token leftParenthesis = _expect(TokenType.OPEN_PAREN);
6392 VariableDeclarationList variableList = null; 6391 VariableDeclarationList variableList = null;
6393 Expression initialization = null; 6392 Expression initialization = null;
6394 if (!_matches(TokenType.SEMICOLON)) { 6393 if (!_matches(TokenType.SEMICOLON)) {
6395 CommentAndMetadata commentAndMetadata = _parseCommentAndMetadata(); 6394 CommentAndMetadata commentAndMetadata = _parseCommentAndMetadata();
6396 if (_matchesIdentifier() && (_tokenMatchesKeyword(_peek(), Keyword.IN) | | _tokenMatches(_peek(), TokenType.COLON))) { 6395 if (_matchesIdentifier() && (_tokenMatchesKeyword(_peek(), Keyword.IN) | | _tokenMatches(_peek(), TokenType.COLON))) {
6397 List<VariableDeclaration> variables = new List<VariableDeclaration>(); 6396 List<VariableDeclaration> variables = new List<VariableDeclaration>();
6398 SimpleIdentifier variableName = parseSimpleIdentifier(); 6397 SimpleIdentifier variableName = parseSimpleIdentifier();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
6443 variable.name); 6442 variable.name);
6444 } else { 6443 } else {
6445 if (!commentAndMetadata.metadata.isEmpty) { 6444 if (!commentAndMetadata.metadata.isEmpty) {
6446 // TODO(jwren) metadata isn't allowed before the identifier in 6445 // TODO(jwren) metadata isn't allowed before the identifier in
6447 // "identifier in expression", add warning if commentAndMetadata 6446 // "identifier in expression", add warning if commentAndMetadata
6448 // has content 6447 // has content
6449 } 6448 }
6450 identifier = variable.name; 6449 identifier = variable.name;
6451 } 6450 }
6452 } 6451 }
6453 Token inKeyword = andAdvance; 6452 Token inKeyword = getAndAdvance();
6454 Expression iterator = parseExpression2(); 6453 Expression iterator = parseExpression2();
6455 Token rightParenthesis = _expect(TokenType.CLOSE_PAREN); 6454 Token rightParenthesis = _expect(TokenType.CLOSE_PAREN);
6456 Statement body = parseStatement2(); 6455 Statement body = parseStatement2();
6457 if (loopVariable == null) { 6456 if (loopVariable == null) {
6458 return new ForEachStatement.con2( 6457 return new ForEachStatement.con2(
6459 awaitKeyword, 6458 awaitKeyword,
6460 forKeyword, 6459 forKeyword,
6461 leftParenthesis, 6460 leftParenthesis,
6462 identifier, 6461 identifier,
6463 inKeyword, 6462 inKeyword,
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
6536 bool wasInSwitch = _inSwitch; 6535 bool wasInSwitch = _inSwitch;
6537 _inAsync = false; 6536 _inAsync = false;
6538 _inGenerator = false; 6537 _inGenerator = false;
6539 _inLoop = false; 6538 _inLoop = false;
6540 _inSwitch = false; 6539 _inSwitch = false;
6541 try { 6540 try {
6542 if (_matches(TokenType.SEMICOLON)) { 6541 if (_matches(TokenType.SEMICOLON)) {
6543 if (!mayBeEmpty) { 6542 if (!mayBeEmpty) {
6544 _reportErrorForCurrentToken(emptyErrorCode); 6543 _reportErrorForCurrentToken(emptyErrorCode);
6545 } 6544 }
6546 return new EmptyFunctionBody(andAdvance); 6545 return new EmptyFunctionBody(getAndAdvance());
6547 } else if (_matchesString(_NATIVE)) { 6546 } else if (_matchesString(_NATIVE)) {
6548 Token nativeToken = andAdvance; 6547 Token nativeToken = getAndAdvance();
6549 StringLiteral stringLiteral = null; 6548 StringLiteral stringLiteral = null;
6550 if (_matches(TokenType.STRING)) { 6549 if (_matches(TokenType.STRING)) {
6551 stringLiteral = parseStringLiteral(); 6550 stringLiteral = parseStringLiteral();
6552 } 6551 }
6553 return new NativeFunctionBody( 6552 return new NativeFunctionBody(
6554 nativeToken, 6553 nativeToken,
6555 stringLiteral, 6554 stringLiteral,
6556 _expect(TokenType.SEMICOLON)); 6555 _expect(TokenType.SEMICOLON));
6557 } 6556 }
6558 Token keyword = null; 6557 Token keyword = null;
6559 Token star = null; 6558 Token star = null;
6560 if (_parseAsync) { 6559 if (_parseAsync) {
6561 if (_matchesString(ASYNC)) { 6560 if (_matchesString(ASYNC)) {
6562 keyword = andAdvance; 6561 keyword = getAndAdvance();
6563 if (_matches(TokenType.STAR)) { 6562 if (_matches(TokenType.STAR)) {
6564 star = andAdvance; 6563 star = getAndAdvance();
6565 _inGenerator = true; 6564 _inGenerator = true;
6566 } 6565 }
6567 _inAsync = true; 6566 _inAsync = true;
6568 } else if (_matchesString(SYNC)) { 6567 } else if (_matchesString(SYNC)) {
6569 keyword = andAdvance; 6568 keyword = getAndAdvance();
6570 if (_matches(TokenType.STAR)) { 6569 if (_matches(TokenType.STAR)) {
6571 star = andAdvance; 6570 star = getAndAdvance();
6572 _inGenerator = true; 6571 _inGenerator = true;
6573 } 6572 }
6574 } 6573 }
6575 } 6574 }
6576 if (_matches(TokenType.FUNCTION)) { 6575 if (_matches(TokenType.FUNCTION)) {
6577 if (keyword != null) { 6576 if (keyword != null) {
6578 if (!_tokenMatchesString(keyword, ASYNC)) { 6577 if (!_tokenMatchesString(keyword, ASYNC)) {
6579 _reportErrorForToken(ParserErrorCode.INVALID_SYNC, keyword); 6578 _reportErrorForToken(ParserErrorCode.INVALID_SYNC, keyword);
6580 keyword = null; 6579 keyword = null;
6581 } else if (star != null) { 6580 } else if (star != null) {
6582 _reportErrorForToken( 6581 _reportErrorForToken(
6583 ParserErrorCode.INVALID_STAR_AFTER_ASYNC, 6582 ParserErrorCode.INVALID_STAR_AFTER_ASYNC,
6584 star); 6583 star);
6585 } 6584 }
6586 } 6585 }
6587 Token functionDefinition = andAdvance; 6586 Token functionDefinition = getAndAdvance();
6588 if (_matchesKeyword(Keyword.RETURN)) { 6587 if (_matchesKeyword(Keyword.RETURN)) {
6589 _reportErrorForToken( 6588 _reportErrorForToken(
6590 ParserErrorCode.UNEXPECTED_TOKEN, 6589 ParserErrorCode.UNEXPECTED_TOKEN,
6591 andAdvance); 6590 getAndAdvance());
6592 } 6591 }
6593 Expression expression = parseExpression2(); 6592 Expression expression = parseExpression2();
6594 Token semicolon = null; 6593 Token semicolon = null;
6595 if (!inExpression) { 6594 if (!inExpression) {
6596 semicolon = _expect(TokenType.SEMICOLON); 6595 semicolon = _expect(TokenType.SEMICOLON);
6597 } 6596 }
6598 if (!_parseFunctionBodies) { 6597 if (!_parseFunctionBodies) {
6599 return new EmptyFunctionBody( 6598 return new EmptyFunctionBody(
6600 _createSyntheticToken(TokenType.SEMICOLON)); 6599 _createSyntheticToken(TokenType.SEMICOLON));
6601 } 6600 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
6648 * @param isStatement `true` if the function declaration is being parsed as a statement 6647 * @param isStatement `true` if the function declaration is being parsed as a statement
6649 * @return the function declaration that was parsed 6648 * @return the function declaration that was parsed
6650 */ 6649 */
6651 FunctionDeclaration 6650 FunctionDeclaration
6652 _parseFunctionDeclaration(CommentAndMetadata commentAndMetadata, 6651 _parseFunctionDeclaration(CommentAndMetadata commentAndMetadata,
6653 Token externalKeyword, TypeName returnType) { 6652 Token externalKeyword, TypeName returnType) {
6654 Token keyword = null; 6653 Token keyword = null;
6655 bool isGetter = false; 6654 bool isGetter = false;
6656 if (_matchesKeyword(Keyword.GET) && 6655 if (_matchesKeyword(Keyword.GET) &&
6657 !_tokenMatches(_peek(), TokenType.OPEN_PAREN)) { 6656 !_tokenMatches(_peek(), TokenType.OPEN_PAREN)) {
6658 keyword = andAdvance; 6657 keyword = getAndAdvance();
6659 isGetter = true; 6658 isGetter = true;
6660 } else if (_matchesKeyword(Keyword.SET) && 6659 } else if (_matchesKeyword(Keyword.SET) &&
6661 !_tokenMatches(_peek(), TokenType.OPEN_PAREN)) { 6660 !_tokenMatches(_peek(), TokenType.OPEN_PAREN)) {
6662 keyword = andAdvance; 6661 keyword = getAndAdvance();
6663 } 6662 }
6664 SimpleIdentifier name = parseSimpleIdentifier(); 6663 SimpleIdentifier name = parseSimpleIdentifier();
6665 FormalParameterList parameters = null; 6664 FormalParameterList parameters = null;
6666 if (!isGetter) { 6665 if (!isGetter) {
6667 if (_matches(TokenType.OPEN_PAREN)) { 6666 if (_matches(TokenType.OPEN_PAREN)) {
6668 parameters = parseFormalParameterList(); 6667 parameters = parseFormalParameterList();
6669 _validateFormalParameterList(parameters); 6668 _validateFormalParameterList(parameters);
6670 } else { 6669 } else {
6671 _reportErrorForCurrentToken( 6670 _reportErrorForCurrentToken(
6672 ParserErrorCode.MISSING_FUNCTION_PARAMETERS); 6671 ParserErrorCode.MISSING_FUNCTION_PARAMETERS);
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
6908 */ 6907 */
6909 Statement _parseIfStatement() { 6908 Statement _parseIfStatement() {
6910 Token ifKeyword = _expectKeyword(Keyword.IF); 6909 Token ifKeyword = _expectKeyword(Keyword.IF);
6911 Token leftParenthesis = _expect(TokenType.OPEN_PAREN); 6910 Token leftParenthesis = _expect(TokenType.OPEN_PAREN);
6912 Expression condition = parseExpression2(); 6911 Expression condition = parseExpression2();
6913 Token rightParenthesis = _expect(TokenType.CLOSE_PAREN); 6912 Token rightParenthesis = _expect(TokenType.CLOSE_PAREN);
6914 Statement thenStatement = parseStatement2(); 6913 Statement thenStatement = parseStatement2();
6915 Token elseKeyword = null; 6914 Token elseKeyword = null;
6916 Statement elseStatement = null; 6915 Statement elseStatement = null;
6917 if (_matchesKeyword(Keyword.ELSE)) { 6916 if (_matchesKeyword(Keyword.ELSE)) {
6918 elseKeyword = andAdvance; 6917 elseKeyword = getAndAdvance();
6919 elseStatement = parseStatement2(); 6918 elseStatement = parseStatement2();
6920 } 6919 }
6921 return new IfStatement( 6920 return new IfStatement(
6922 ifKeyword, 6921 ifKeyword,
6923 leftParenthesis, 6922 leftParenthesis,
6924 condition, 6923 condition,
6925 rightParenthesis, 6924 rightParenthesis,
6926 thenStatement, 6925 thenStatement,
6927 elseKeyword, 6926 elseKeyword,
6928 elseStatement); 6927 elseStatement);
(...skipping 11 matching lines...) Expand all
6940 * @return the import directive that was parsed 6939 * @return the import directive that was parsed
6941 */ 6940 */
6942 ImportDirective _parseImportDirective(CommentAndMetadata commentAndMetadata) { 6941 ImportDirective _parseImportDirective(CommentAndMetadata commentAndMetadata) {
6943 Token importKeyword = _expectKeyword(Keyword.IMPORT); 6942 Token importKeyword = _expectKeyword(Keyword.IMPORT);
6944 StringLiteral libraryUri = _parseUri(); 6943 StringLiteral libraryUri = _parseUri();
6945 Token deferredToken = null; 6944 Token deferredToken = null;
6946 Token asToken = null; 6945 Token asToken = null;
6947 SimpleIdentifier prefix = null; 6946 SimpleIdentifier prefix = null;
6948 if (_matchesKeyword(Keyword.DEFERRED)) { 6947 if (_matchesKeyword(Keyword.DEFERRED)) {
6949 if (_parseDeferredLibraries) { 6948 if (_parseDeferredLibraries) {
6950 deferredToken = andAdvance; 6949 deferredToken = getAndAdvance();
6951 } else { 6950 } else {
6952 _reportErrorForCurrentToken( 6951 _reportErrorForCurrentToken(
6953 ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED); 6952 ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED);
6954 _advance(); 6953 _advance();
6955 } 6954 }
6956 } 6955 }
6957 if (_matchesKeyword(Keyword.AS)) { 6956 if (_matchesKeyword(Keyword.AS)) {
6958 asToken = andAdvance; 6957 asToken = getAndAdvance();
6959 prefix = parseSimpleIdentifier(); 6958 prefix = parseSimpleIdentifier();
6960 } else if (deferredToken != null) { 6959 } else if (deferredToken != null) {
6961 _reportErrorForCurrentToken( 6960 _reportErrorForCurrentToken(
6962 ParserErrorCode.MISSING_PREFIX_IN_DEFERRED_IMPORT); 6961 ParserErrorCode.MISSING_PREFIX_IN_DEFERRED_IMPORT);
6963 } 6962 }
6964 List<Combinator> combinators = _parseCombinators(); 6963 List<Combinator> combinators = _parseCombinators();
6965 Token semicolon = _expectSemicolon(); 6964 Token semicolon = _expectSemicolon();
6966 return new ImportDirective( 6965 return new ImportDirective(
6967 commentAndMetadata.comment, 6966 commentAndMetadata.comment,
6968 commentAndMetadata.metadata, 6967 commentAndMetadata.metadata,
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
7122 rightBracket); 7121 rightBracket);
7123 } 7122 }
7124 // open 7123 // open
7125 Token leftBracket = _expect(TokenType.OPEN_SQUARE_BRACKET); 7124 Token leftBracket = _expect(TokenType.OPEN_SQUARE_BRACKET);
7126 if (_matches(TokenType.CLOSE_SQUARE_BRACKET)) { 7125 if (_matches(TokenType.CLOSE_SQUARE_BRACKET)) {
7127 return new ListLiteral( 7126 return new ListLiteral(
7128 modifier, 7127 modifier,
7129 typeArguments, 7128 typeArguments,
7130 leftBracket, 7129 leftBracket,
7131 null, 7130 null,
7132 andAdvance); 7131 getAndAdvance());
7133 } 7132 }
7134 bool wasInInitializer = _inInitializer; 7133 bool wasInInitializer = _inInitializer;
7135 _inInitializer = false; 7134 _inInitializer = false;
7136 try { 7135 try {
7137 List<Expression> elements = new List<Expression>(); 7136 List<Expression> elements = new List<Expression>();
7138 elements.add(parseExpression2()); 7137 elements.add(parseExpression2());
7139 while (_optional(TokenType.COMMA)) { 7138 while (_optional(TokenType.COMMA)) {
7140 if (_matches(TokenType.CLOSE_SQUARE_BRACKET)) { 7139 if (_matches(TokenType.CLOSE_SQUARE_BRACKET)) {
7141 return new ListLiteral( 7140 return new ListLiteral(
7142 modifier, 7141 modifier,
7143 typeArguments, 7142 typeArguments,
7144 leftBracket, 7143 leftBracket,
7145 elements, 7144 elements,
7146 andAdvance); 7145 getAndAdvance());
7147 } 7146 }
7148 elements.add(parseExpression2()); 7147 elements.add(parseExpression2());
7149 } 7148 }
7150 Token rightBracket = _expect(TokenType.CLOSE_SQUARE_BRACKET); 7149 Token rightBracket = _expect(TokenType.CLOSE_SQUARE_BRACKET);
7151 return new ListLiteral( 7150 return new ListLiteral(
7152 modifier, 7151 modifier,
7153 typeArguments, 7152 typeArguments,
7154 leftBracket, 7153 leftBracket,
7155 elements, 7154 elements,
7156 rightBracket); 7155 rightBracket);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
7198 * <pre> 7197 * <pre>
7199 * logicalAndExpression ::= 7198 * logicalAndExpression ::=
7200 * equalityExpression ('&&' equalityExpression)* 7199 * equalityExpression ('&&' equalityExpression)*
7201 * </pre> 7200 * </pre>
7202 * 7201 *
7203 * @return the logical and expression that was parsed 7202 * @return the logical and expression that was parsed
7204 */ 7203 */
7205 Expression _parseLogicalAndExpression() { 7204 Expression _parseLogicalAndExpression() {
7206 Expression expression = _parseEqualityExpression(); 7205 Expression expression = _parseEqualityExpression();
7207 while (_matches(TokenType.AMPERSAND_AMPERSAND)) { 7206 while (_matches(TokenType.AMPERSAND_AMPERSAND)) {
7208 Token operator = andAdvance; 7207 Token operator = getAndAdvance();
7209 expression = 7208 expression =
7210 new BinaryExpression(expression, operator, _parseEqualityExpression()) ; 7209 new BinaryExpression(expression, operator, _parseEqualityExpression()) ;
7211 } 7210 }
7212 return expression; 7211 return expression;
7213 } 7212 }
7214 7213
7215 /** 7214 /**
7216 * Parse a map literal. 7215 * Parse a map literal.
7217 * 7216 *
7218 * <pre> 7217 * <pre>
7219 * mapLiteral ::= 7218 * mapLiteral ::=
7220 * 'const'? typeArguments? '{' (mapLiteralEntry (',' mapLiteralEntry)* ',' ?)? '}' 7219 * 'const'? typeArguments? '{' (mapLiteralEntry (',' mapLiteralEntry)* ',' ?)? '}'
7221 * </pre> 7220 * </pre>
7222 * 7221 *
7223 * @param modifier the 'const' modifier appearing before the literal, or `null ` if there is 7222 * @param modifier the 'const' modifier appearing before the literal, or `null ` if there is
7224 * no modifier 7223 * no modifier
7225 * @param typeArguments the type arguments that were declared, or `null` if th ere are no 7224 * @param typeArguments the type arguments that were declared, or `null` if th ere are no
7226 * type arguments 7225 * type arguments
7227 * @return the map literal that was parsed 7226 * @return the map literal that was parsed
7228 */ 7227 */
7229 MapLiteral _parseMapLiteral(Token modifier, TypeArgumentList typeArguments) { 7228 MapLiteral _parseMapLiteral(Token modifier, TypeArgumentList typeArguments) {
7230 Token leftBracket = _expect(TokenType.OPEN_CURLY_BRACKET); 7229 Token leftBracket = _expect(TokenType.OPEN_CURLY_BRACKET);
7231 List<MapLiteralEntry> entries = new List<MapLiteralEntry>(); 7230 List<MapLiteralEntry> entries = new List<MapLiteralEntry>();
7232 if (_matches(TokenType.CLOSE_CURLY_BRACKET)) { 7231 if (_matches(TokenType.CLOSE_CURLY_BRACKET)) {
7233 return new MapLiteral( 7232 return new MapLiteral(
7234 modifier, 7233 modifier,
7235 typeArguments, 7234 typeArguments,
7236 leftBracket, 7235 leftBracket,
7237 entries, 7236 entries,
7238 andAdvance); 7237 getAndAdvance());
7239 } 7238 }
7240 bool wasInInitializer = _inInitializer; 7239 bool wasInInitializer = _inInitializer;
7241 _inInitializer = false; 7240 _inInitializer = false;
7242 try { 7241 try {
7243 entries.add(parseMapLiteralEntry()); 7242 entries.add(parseMapLiteralEntry());
7244 while (_optional(TokenType.COMMA)) { 7243 while (_optional(TokenType.COMMA)) {
7245 if (_matches(TokenType.CLOSE_CURLY_BRACKET)) { 7244 if (_matches(TokenType.CLOSE_CURLY_BRACKET)) {
7246 return new MapLiteral( 7245 return new MapLiteral(
7247 modifier, 7246 modifier,
7248 typeArguments, 7247 typeArguments,
7249 leftBracket, 7248 leftBracket,
7250 entries, 7249 entries,
7251 andAdvance); 7250 getAndAdvance());
7252 } 7251 }
7253 entries.add(parseMapLiteralEntry()); 7252 entries.add(parseMapLiteralEntry());
7254 } 7253 }
7255 Token rightBracket = _expect(TokenType.CLOSE_CURLY_BRACKET); 7254 Token rightBracket = _expect(TokenType.CLOSE_CURLY_BRACKET);
7256 return new MapLiteral( 7255 return new MapLiteral(
7257 modifier, 7256 modifier,
7258 typeArguments, 7257 typeArguments,
7259 leftBracket, 7258 leftBracket,
7260 entries, 7259 entries,
7261 rightBracket); 7260 rightBracket);
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
7379 _tokenMatches(_peek(), TokenType.OPEN_PAREN)) { 7378 _tokenMatches(_peek(), TokenType.OPEN_PAREN)) {
7380 return modifiers; 7379 return modifiers;
7381 } 7380 }
7382 if (_matchesKeyword(Keyword.ABSTRACT)) { 7381 if (_matchesKeyword(Keyword.ABSTRACT)) {
7383 if (modifiers.abstractKeyword != null) { 7382 if (modifiers.abstractKeyword != null) {
7384 _reportErrorForCurrentToken( 7383 _reportErrorForCurrentToken(
7385 ParserErrorCode.DUPLICATED_MODIFIER, 7384 ParserErrorCode.DUPLICATED_MODIFIER,
7386 [_currentToken.lexeme]); 7385 [_currentToken.lexeme]);
7387 _advance(); 7386 _advance();
7388 } else { 7387 } else {
7389 modifiers.abstractKeyword = andAdvance; 7388 modifiers.abstractKeyword = getAndAdvance();
7390 } 7389 }
7391 } else if (_matchesKeyword(Keyword.CONST)) { 7390 } else if (_matchesKeyword(Keyword.CONST)) {
7392 if (modifiers.constKeyword != null) { 7391 if (modifiers.constKeyword != null) {
7393 _reportErrorForCurrentToken( 7392 _reportErrorForCurrentToken(
7394 ParserErrorCode.DUPLICATED_MODIFIER, 7393 ParserErrorCode.DUPLICATED_MODIFIER,
7395 [_currentToken.lexeme]); 7394 [_currentToken.lexeme]);
7396 _advance(); 7395 _advance();
7397 } else { 7396 } else {
7398 modifiers.constKeyword = andAdvance; 7397 modifiers.constKeyword = getAndAdvance();
7399 } 7398 }
7400 } else if (_matchesKeyword(Keyword.EXTERNAL) && 7399 } else if (_matchesKeyword(Keyword.EXTERNAL) &&
7401 !_tokenMatches(_peek(), TokenType.PERIOD) && 7400 !_tokenMatches(_peek(), TokenType.PERIOD) &&
7402 !_tokenMatches(_peek(), TokenType.LT)) { 7401 !_tokenMatches(_peek(), TokenType.LT)) {
7403 if (modifiers.externalKeyword != null) { 7402 if (modifiers.externalKeyword != null) {
7404 _reportErrorForCurrentToken( 7403 _reportErrorForCurrentToken(
7405 ParserErrorCode.DUPLICATED_MODIFIER, 7404 ParserErrorCode.DUPLICATED_MODIFIER,
7406 [_currentToken.lexeme]); 7405 [_currentToken.lexeme]);
7407 _advance(); 7406 _advance();
7408 } else { 7407 } else {
7409 modifiers.externalKeyword = andAdvance; 7408 modifiers.externalKeyword = getAndAdvance();
7410 } 7409 }
7411 } else if (_matchesKeyword(Keyword.FACTORY) && 7410 } else if (_matchesKeyword(Keyword.FACTORY) &&
7412 !_tokenMatches(_peek(), TokenType.PERIOD) && 7411 !_tokenMatches(_peek(), TokenType.PERIOD) &&
7413 !_tokenMatches(_peek(), TokenType.LT)) { 7412 !_tokenMatches(_peek(), TokenType.LT)) {
7414 if (modifiers.factoryKeyword != null) { 7413 if (modifiers.factoryKeyword != null) {
7415 _reportErrorForCurrentToken( 7414 _reportErrorForCurrentToken(
7416 ParserErrorCode.DUPLICATED_MODIFIER, 7415 ParserErrorCode.DUPLICATED_MODIFIER,
7417 [_currentToken.lexeme]); 7416 [_currentToken.lexeme]);
7418 _advance(); 7417 _advance();
7419 } else { 7418 } else {
7420 modifiers.factoryKeyword = andAdvance; 7419 modifiers.factoryKeyword = getAndAdvance();
7421 } 7420 }
7422 } else if (_matchesKeyword(Keyword.FINAL)) { 7421 } else if (_matchesKeyword(Keyword.FINAL)) {
7423 if (modifiers.finalKeyword != null) { 7422 if (modifiers.finalKeyword != null) {
7424 _reportErrorForCurrentToken( 7423 _reportErrorForCurrentToken(
7425 ParserErrorCode.DUPLICATED_MODIFIER, 7424 ParserErrorCode.DUPLICATED_MODIFIER,
7426 [_currentToken.lexeme]); 7425 [_currentToken.lexeme]);
7427 _advance(); 7426 _advance();
7428 } else { 7427 } else {
7429 modifiers.finalKeyword = andAdvance; 7428 modifiers.finalKeyword = getAndAdvance();
7430 } 7429 }
7431 } else if (_matchesKeyword(Keyword.STATIC) && 7430 } else if (_matchesKeyword(Keyword.STATIC) &&
7432 !_tokenMatches(_peek(), TokenType.PERIOD) && 7431 !_tokenMatches(_peek(), TokenType.PERIOD) &&
7433 !_tokenMatches(_peek(), TokenType.LT)) { 7432 !_tokenMatches(_peek(), TokenType.LT)) {
7434 if (modifiers.staticKeyword != null) { 7433 if (modifiers.staticKeyword != null) {
7435 _reportErrorForCurrentToken( 7434 _reportErrorForCurrentToken(
7436 ParserErrorCode.DUPLICATED_MODIFIER, 7435 ParserErrorCode.DUPLICATED_MODIFIER,
7437 [_currentToken.lexeme]); 7436 [_currentToken.lexeme]);
7438 _advance(); 7437 _advance();
7439 } else { 7438 } else {
7440 modifiers.staticKeyword = andAdvance; 7439 modifiers.staticKeyword = getAndAdvance();
7441 } 7440 }
7442 } else if (_matchesKeyword(Keyword.VAR)) { 7441 } else if (_matchesKeyword(Keyword.VAR)) {
7443 if (modifiers.varKeyword != null) { 7442 if (modifiers.varKeyword != null) {
7444 _reportErrorForCurrentToken( 7443 _reportErrorForCurrentToken(
7445 ParserErrorCode.DUPLICATED_MODIFIER, 7444 ParserErrorCode.DUPLICATED_MODIFIER,
7446 [_currentToken.lexeme]); 7445 [_currentToken.lexeme]);
7447 _advance(); 7446 _advance();
7448 } else { 7447 } else {
7449 modifiers.varKeyword = andAdvance; 7448 modifiers.varKeyword = getAndAdvance();
7450 } 7449 }
7451 } else { 7450 } else {
7452 progress = false; 7451 progress = false;
7453 } 7452 }
7454 } 7453 }
7455 return modifiers; 7454 return modifiers;
7456 } 7455 }
7457 7456
7458 /** 7457 /**
7459 * Parse a multiplicative expression. 7458 * Parse a multiplicative expression.
7460 * 7459 *
7461 * <pre> 7460 * <pre>
7462 * multiplicativeExpression ::= 7461 * multiplicativeExpression ::=
7463 * unaryExpression (multiplicativeOperator unaryExpression)* 7462 * unaryExpression (multiplicativeOperator unaryExpression)*
7464 * | 'super' (multiplicativeOperator unaryExpression)+ 7463 * | 'super' (multiplicativeOperator unaryExpression)+
7465 * </pre> 7464 * </pre>
7466 * 7465 *
7467 * @return the multiplicative expression that was parsed 7466 * @return the multiplicative expression that was parsed
7468 */ 7467 */
7469 Expression _parseMultiplicativeExpression() { 7468 Expression _parseMultiplicativeExpression() {
7470 Expression expression; 7469 Expression expression;
7471 if (_matchesKeyword(Keyword.SUPER) && 7470 if (_matchesKeyword(Keyword.SUPER) &&
7472 _currentToken.next.type.isMultiplicativeOperator) { 7471 _currentToken.next.type.isMultiplicativeOperator) {
7473 expression = new SuperExpression(andAdvance); 7472 expression = new SuperExpression(getAndAdvance());
7474 } else { 7473 } else {
7475 expression = _parseUnaryExpression(); 7474 expression = _parseUnaryExpression();
7476 } 7475 }
7477 while (_currentToken.type.isMultiplicativeOperator) { 7476 while (_currentToken.type.isMultiplicativeOperator) {
7478 Token operator = andAdvance; 7477 Token operator = getAndAdvance();
7479 expression = 7478 expression =
7480 new BinaryExpression(expression, operator, _parseUnaryExpression()); 7479 new BinaryExpression(expression, operator, _parseUnaryExpression());
7481 } 7480 }
7482 return expression; 7481 return expression;
7483 } 7482 }
7484 7483
7485 /** 7484 /**
7486 * Parse a class native clause. 7485 * Parse a class native clause.
7487 * 7486 *
7488 * <pre> 7487 * <pre>
7489 * classNativeClause ::= 7488 * classNativeClause ::=
7490 * 'native' name 7489 * 'native' name
7491 * </pre> 7490 * </pre>
7492 * 7491 *
7493 * @return the class native clause that was parsed 7492 * @return the class native clause that was parsed
7494 */ 7493 */
7495 NativeClause _parseNativeClause() { 7494 NativeClause _parseNativeClause() {
7496 Token keyword = andAdvance; 7495 Token keyword = getAndAdvance();
7497 StringLiteral name = parseStringLiteral(); 7496 StringLiteral name = parseStringLiteral();
7498 return new NativeClause(keyword, name); 7497 return new NativeClause(keyword, name);
7499 } 7498 }
7500 7499
7501 /** 7500 /**
7502 * Parse a new expression. 7501 * Parse a new expression.
7503 * 7502 *
7504 * <pre> 7503 * <pre>
7505 * newExpression ::= 7504 * newExpression ::=
7506 * instanceCreationExpression 7505 * instanceCreationExpression
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
7711 * declaration 7710 * declaration
7712 * @param externalKeyword the 'external' token 7711 * @param externalKeyword the 'external' token
7713 * @param the return type that has already been parsed, or `null` if there was no return 7712 * @param the return type that has already been parsed, or `null` if there was no return
7714 * type 7713 * type
7715 * @return the operator declaration that was parsed 7714 * @return the operator declaration that was parsed
7716 */ 7715 */
7717 MethodDeclaration _parseOperator(CommentAndMetadata commentAndMetadata, 7716 MethodDeclaration _parseOperator(CommentAndMetadata commentAndMetadata,
7718 Token externalKeyword, TypeName returnType) { 7717 Token externalKeyword, TypeName returnType) {
7719 Token operatorKeyword; 7718 Token operatorKeyword;
7720 if (_matchesKeyword(Keyword.OPERATOR)) { 7719 if (_matchesKeyword(Keyword.OPERATOR)) {
7721 operatorKeyword = andAdvance; 7720 operatorKeyword = getAndAdvance();
7722 } else { 7721 } else {
7723 _reportErrorForToken( 7722 _reportErrorForToken(
7724 ParserErrorCode.MISSING_KEYWORD_OPERATOR, 7723 ParserErrorCode.MISSING_KEYWORD_OPERATOR,
7725 _currentToken); 7724 _currentToken);
7726 operatorKeyword = _createSyntheticKeyword(Keyword.OPERATOR); 7725 operatorKeyword = _createSyntheticKeyword(Keyword.OPERATOR);
7727 } 7726 }
7728 if (!_currentToken.isUserDefinableOperator) { 7727 if (!_currentToken.isUserDefinableOperator) {
7729 _reportErrorForCurrentToken( 7728 _reportErrorForCurrentToken(
7730 ParserErrorCode.NON_USER_DEFINABLE_OPERATOR, 7729 ParserErrorCode.NON_USER_DEFINABLE_OPERATOR,
7731 [_currentToken.lexeme]); 7730 [_currentToken.lexeme]);
7732 } 7731 }
7733 SimpleIdentifier name = new SimpleIdentifier(andAdvance); 7732 SimpleIdentifier name = new SimpleIdentifier(getAndAdvance());
7734 if (_matches(TokenType.EQ)) { 7733 if (_matches(TokenType.EQ)) {
7735 Token previous = _currentToken.previous; 7734 Token previous = _currentToken.previous;
7736 if ((_tokenMatches(previous, TokenType.EQ_EQ) || 7735 if ((_tokenMatches(previous, TokenType.EQ_EQ) ||
7737 _tokenMatches(previous, TokenType.BANG_EQ)) && 7736 _tokenMatches(previous, TokenType.BANG_EQ)) &&
7738 _currentToken.offset == previous.offset + 2) { 7737 _currentToken.offset == previous.offset + 2) {
7739 _reportErrorForCurrentToken( 7738 _reportErrorForCurrentToken(
7740 ParserErrorCode.INVALID_OPERATOR, 7739 ParserErrorCode.INVALID_OPERATOR,
7741 ["${previous.lexeme}${_currentToken.lexeme}"]); 7740 ["${previous.lexeme}${_currentToken.lexeme}"]);
7742 _advance(); 7741 _advance();
7743 } 7742 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
7796 * partOfDirective ::= 7795 * partOfDirective ::=
7797 * metadata 'part' 'of' identifier ';' 7796 * metadata 'part' 'of' identifier ';'
7798 * </pre> 7797 * </pre>
7799 * 7798 *
7800 * @param commentAndMetadata the metadata to be associated with the directive 7799 * @param commentAndMetadata the metadata to be associated with the directive
7801 * @return the part or part-of directive that was parsed 7800 * @return the part or part-of directive that was parsed
7802 */ 7801 */
7803 Directive _parsePartDirective(CommentAndMetadata commentAndMetadata) { 7802 Directive _parsePartDirective(CommentAndMetadata commentAndMetadata) {
7804 Token partKeyword = _expectKeyword(Keyword.PART); 7803 Token partKeyword = _expectKeyword(Keyword.PART);
7805 if (_matchesString(_OF)) { 7804 if (_matchesString(_OF)) {
7806 Token ofKeyword = andAdvance; 7805 Token ofKeyword = getAndAdvance();
7807 LibraryIdentifier libraryName = _parseLibraryName( 7806 LibraryIdentifier libraryName = _parseLibraryName(
7808 ParserErrorCode.MISSING_NAME_IN_PART_OF_DIRECTIVE, 7807 ParserErrorCode.MISSING_NAME_IN_PART_OF_DIRECTIVE,
7809 ofKeyword); 7808 ofKeyword);
7810 Token semicolon = _expect(TokenType.SEMICOLON); 7809 Token semicolon = _expect(TokenType.SEMICOLON);
7811 return new PartOfDirective( 7810 return new PartOfDirective(
7812 commentAndMetadata.comment, 7811 commentAndMetadata.comment,
7813 commentAndMetadata.metadata, 7812 commentAndMetadata.metadata,
7814 partKeyword, 7813 partKeyword,
7815 ofKeyword, 7814 ofKeyword,
7816 libraryName, 7815 libraryName,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
7864 } 7863 }
7865 } while (_matches(TokenType.OPEN_SQUARE_BRACKET) || 7864 } while (_matches(TokenType.OPEN_SQUARE_BRACKET) ||
7866 _matches(TokenType.PERIOD) || 7865 _matches(TokenType.PERIOD) ||
7867 _matches(TokenType.OPEN_PAREN)); 7866 _matches(TokenType.OPEN_PAREN));
7868 return operand; 7867 return operand;
7869 } 7868 }
7870 if (!_currentToken.type.isIncrementOperator) { 7869 if (!_currentToken.type.isIncrementOperator) {
7871 return operand; 7870 return operand;
7872 } 7871 }
7873 _ensureAssignable(operand); 7872 _ensureAssignable(operand);
7874 Token operator = andAdvance; 7873 Token operator = getAndAdvance();
7875 return new PostfixExpression(operand, operator); 7874 return new PostfixExpression(operand, operator);
7876 } 7875 }
7877 7876
7878 /** 7877 /**
7879 * Parse a primary expression. 7878 * Parse a primary expression.
7880 * 7879 *
7881 * <pre> 7880 * <pre>
7882 * primary ::= 7881 * primary ::=
7883 * thisExpression 7882 * thisExpression
7884 * | 'super' assignableSelector 7883 * | 'super' assignableSelector
(...skipping 12 matching lines...) Expand all
7897 * | stringLiteral 7896 * | stringLiteral
7898 * | symbolLiteral 7897 * | symbolLiteral
7899 * | mapLiteral 7898 * | mapLiteral
7900 * | listLiteral 7899 * | listLiteral
7901 * </pre> 7900 * </pre>
7902 * 7901 *
7903 * @return the primary expression that was parsed 7902 * @return the primary expression that was parsed
7904 */ 7903 */
7905 Expression _parsePrimaryExpression() { 7904 Expression _parsePrimaryExpression() {
7906 if (_matchesKeyword(Keyword.THIS)) { 7905 if (_matchesKeyword(Keyword.THIS)) {
7907 return new ThisExpression(andAdvance); 7906 return new ThisExpression(getAndAdvance());
7908 } else if (_matchesKeyword(Keyword.SUPER)) { 7907 } else if (_matchesKeyword(Keyword.SUPER)) {
7909 return _parseAssignableSelector(new SuperExpression(andAdvance), false); 7908 return _parseAssignableSelector(new SuperExpression(getAndAdvance()), fals e);
7910 } else if (_matchesKeyword(Keyword.NULL)) { 7909 } else if (_matchesKeyword(Keyword.NULL)) {
7911 return new NullLiteral(andAdvance); 7910 return new NullLiteral(getAndAdvance());
7912 } else if (_matchesKeyword(Keyword.FALSE)) { 7911 } else if (_matchesKeyword(Keyword.FALSE)) {
7913 return new BooleanLiteral(andAdvance, false); 7912 return new BooleanLiteral(getAndAdvance(), false);
7914 } else if (_matchesKeyword(Keyword.TRUE)) { 7913 } else if (_matchesKeyword(Keyword.TRUE)) {
7915 return new BooleanLiteral(andAdvance, true); 7914 return new BooleanLiteral(getAndAdvance(), true);
7916 } else if (_matches(TokenType.DOUBLE)) { 7915 } else if (_matches(TokenType.DOUBLE)) {
7917 Token token = andAdvance; 7916 Token token = getAndAdvance();
7918 double value = 0.0; 7917 double value = 0.0;
7919 try { 7918 try {
7920 value = double.parse(token.lexeme); 7919 value = double.parse(token.lexeme);
7921 } on FormatException catch (exception) { 7920 } on FormatException catch (exception) {
7922 // The invalid format should have been reported by the scanner. 7921 // The invalid format should have been reported by the scanner.
7923 } 7922 }
7924 return new DoubleLiteral(token, value); 7923 return new DoubleLiteral(token, value);
7925 } else if (_matches(TokenType.HEXADECIMAL)) { 7924 } else if (_matches(TokenType.HEXADECIMAL)) {
7926 Token token = andAdvance; 7925 Token token = getAndAdvance();
7927 int value = null; 7926 int value = null;
7928 try { 7927 try {
7929 value = int.parse(token.lexeme.substring(2), radix: 16); 7928 value = int.parse(token.lexeme.substring(2), radix: 16);
7930 } on FormatException catch (exception) { 7929 } on FormatException catch (exception) {
7931 // The invalid format should have been reported by the scanner. 7930 // The invalid format should have been reported by the scanner.
7932 } 7931 }
7933 return new IntegerLiteral(token, value); 7932 return new IntegerLiteral(token, value);
7934 } else if (_matches(TokenType.INT)) { 7933 } else if (_matches(TokenType.INT)) {
7935 Token token = andAdvance; 7934 Token token = getAndAdvance();
7936 int value = null; 7935 int value = null;
7937 try { 7936 try {
7938 value = int.parse(token.lexeme); 7937 value = int.parse(token.lexeme);
7939 } on FormatException catch (exception) { 7938 } on FormatException catch (exception) {
7940 // The invalid format should have been reported by the scanner. 7939 // The invalid format should have been reported by the scanner.
7941 } 7940 }
7942 return new IntegerLiteral(token, value); 7941 return new IntegerLiteral(token, value);
7943 } else if (_matches(TokenType.STRING)) { 7942 } else if (_matches(TokenType.STRING)) {
7944 return parseStringLiteral(); 7943 return parseStringLiteral();
7945 } else if (_matches(TokenType.OPEN_CURLY_BRACKET)) { 7944 } else if (_matches(TokenType.OPEN_CURLY_BRACKET)) {
(...skipping 15 matching lines...) Expand all
7961 // } 7960 // }
7962 return parsePrefixedIdentifier(); 7961 return parsePrefixedIdentifier();
7963 } else if (_matchesKeyword(Keyword.NEW)) { 7962 } else if (_matchesKeyword(Keyword.NEW)) {
7964 return _parseNewExpression(); 7963 return _parseNewExpression();
7965 } else if (_matchesKeyword(Keyword.CONST)) { 7964 } else if (_matchesKeyword(Keyword.CONST)) {
7966 return _parseConstExpression(); 7965 return _parseConstExpression();
7967 } else if (_matches(TokenType.OPEN_PAREN)) { 7966 } else if (_matches(TokenType.OPEN_PAREN)) {
7968 if (_isFunctionExpression(_currentToken)) { 7967 if (_isFunctionExpression(_currentToken)) {
7969 return parseFunctionExpression(); 7968 return parseFunctionExpression();
7970 } 7969 }
7971 Token leftParenthesis = andAdvance; 7970 Token leftParenthesis = getAndAdvance();
7972 bool wasInInitializer = _inInitializer; 7971 bool wasInInitializer = _inInitializer;
7973 _inInitializer = false; 7972 _inInitializer = false;
7974 try { 7973 try {
7975 Expression expression = parseExpression2(); 7974 Expression expression = parseExpression2();
7976 Token rightParenthesis = _expect(TokenType.CLOSE_PAREN); 7975 Token rightParenthesis = _expect(TokenType.CLOSE_PAREN);
7977 return new ParenthesizedExpression( 7976 return new ParenthesizedExpression(
7978 leftParenthesis, 7977 leftParenthesis,
7979 expression, 7978 expression,
7980 rightParenthesis); 7979 rightParenthesis);
7981 } finally { 7980 } finally {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
8017 * 'this' ('.' identifier)? arguments 8016 * 'this' ('.' identifier)? arguments
8018 * </pre> 8017 * </pre>
8019 * 8018 *
8020 * @return the redirecting constructor invocation that was parsed 8019 * @return the redirecting constructor invocation that was parsed
8021 */ 8020 */
8022 RedirectingConstructorInvocation _parseRedirectingConstructorInvocation() { 8021 RedirectingConstructorInvocation _parseRedirectingConstructorInvocation() {
8023 Token keyword = _expectKeyword(Keyword.THIS); 8022 Token keyword = _expectKeyword(Keyword.THIS);
8024 Token period = null; 8023 Token period = null;
8025 SimpleIdentifier constructorName = null; 8024 SimpleIdentifier constructorName = null;
8026 if (_matches(TokenType.PERIOD)) { 8025 if (_matches(TokenType.PERIOD)) {
8027 period = andAdvance; 8026 period = getAndAdvance();
8028 constructorName = parseSimpleIdentifier(); 8027 constructorName = parseSimpleIdentifier();
8029 } 8028 }
8030 ArgumentList argumentList = parseArgumentList(); 8029 ArgumentList argumentList = parseArgumentList();
8031 return new RedirectingConstructorInvocation( 8030 return new RedirectingConstructorInvocation(
8032 keyword, 8031 keyword,
8033 period, 8032 period,
8034 constructorName, 8033 constructorName,
8035 argumentList); 8034 argumentList);
8036 } 8035 }
8037 8036
8038 /** 8037 /**
8039 * Parse a relational expression. 8038 * Parse a relational expression.
8040 * 8039 *
8041 * <pre> 8040 * <pre>
8042 * relationalExpression ::= 8041 * relationalExpression ::=
8043 * bitwiseOrExpression ('is' '!'? type | 'as' type | relationalOperator bi twiseOrExpression)? 8042 * bitwiseOrExpression ('is' '!'? type | 'as' type | relationalOperator bi twiseOrExpression)?
8044 * | 'super' relationalOperator bitwiseOrExpression 8043 * | 'super' relationalOperator bitwiseOrExpression
8045 * </pre> 8044 * </pre>
8046 * 8045 *
8047 * @return the relational expression that was parsed 8046 * @return the relational expression that was parsed
8048 */ 8047 */
8049 Expression _parseRelationalExpression() { 8048 Expression _parseRelationalExpression() {
8050 if (_matchesKeyword(Keyword.SUPER) && 8049 if (_matchesKeyword(Keyword.SUPER) &&
8051 _currentToken.next.type.isRelationalOperator) { 8050 _currentToken.next.type.isRelationalOperator) {
8052 Expression expression = new SuperExpression(andAdvance); 8051 Expression expression = new SuperExpression(getAndAdvance());
8053 Token operator = andAdvance; 8052 Token operator = getAndAdvance();
8054 expression = 8053 expression =
8055 new BinaryExpression(expression, operator, parseBitwiseOrExpression()) ; 8054 new BinaryExpression(expression, operator, parseBitwiseOrExpression()) ;
8056 return expression; 8055 return expression;
8057 } 8056 }
8058 Expression expression = parseBitwiseOrExpression(); 8057 Expression expression = parseBitwiseOrExpression();
8059 if (_matchesKeyword(Keyword.AS)) { 8058 if (_matchesKeyword(Keyword.AS)) {
8060 Token asOperator = andAdvance; 8059 Token asOperator = getAndAdvance();
8061 expression = new AsExpression(expression, asOperator, parseTypeName()); 8060 expression = new AsExpression(expression, asOperator, parseTypeName());
8062 } else if (_matchesKeyword(Keyword.IS)) { 8061 } else if (_matchesKeyword(Keyword.IS)) {
8063 Token isOperator = andAdvance; 8062 Token isOperator = getAndAdvance();
8064 Token notOperator = null; 8063 Token notOperator = null;
8065 if (_matches(TokenType.BANG)) { 8064 if (_matches(TokenType.BANG)) {
8066 notOperator = andAdvance; 8065 notOperator = getAndAdvance();
8067 } 8066 }
8068 expression = 8067 expression =
8069 new IsExpression(expression, isOperator, notOperator, parseTypeName()) ; 8068 new IsExpression(expression, isOperator, notOperator, parseTypeName()) ;
8070 } else if (_currentToken.type.isRelationalOperator) { 8069 } else if (_currentToken.type.isRelationalOperator) {
8071 Token operator = andAdvance; 8070 Token operator = getAndAdvance();
8072 expression = 8071 expression =
8073 new BinaryExpression(expression, operator, parseBitwiseOrExpression()) ; 8072 new BinaryExpression(expression, operator, parseBitwiseOrExpression()) ;
8074 } 8073 }
8075 return expression; 8074 return expression;
8076 } 8075 }
8077 8076
8078 /** 8077 /**
8079 * Parse a rethrow expression. 8078 * Parse a rethrow expression.
8080 * 8079 *
8081 * <pre> 8080 * <pre>
(...skipping 12 matching lines...) Expand all
8094 * <pre> 8093 * <pre>
8095 * returnStatement ::= 8094 * returnStatement ::=
8096 * 'return' expression? ';' 8095 * 'return' expression? ';'
8097 * </pre> 8096 * </pre>
8098 * 8097 *
8099 * @return the return statement that was parsed 8098 * @return the return statement that was parsed
8100 */ 8099 */
8101 Statement _parseReturnStatement() { 8100 Statement _parseReturnStatement() {
8102 Token returnKeyword = _expectKeyword(Keyword.RETURN); 8101 Token returnKeyword = _expectKeyword(Keyword.RETURN);
8103 if (_matches(TokenType.SEMICOLON)) { 8102 if (_matches(TokenType.SEMICOLON)) {
8104 return new ReturnStatement(returnKeyword, null, andAdvance); 8103 return new ReturnStatement(returnKeyword, null, getAndAdvance());
8105 } 8104 }
8106 Expression expression = parseExpression2(); 8105 Expression expression = parseExpression2();
8107 Token semicolon = _expect(TokenType.SEMICOLON); 8106 Token semicolon = _expect(TokenType.SEMICOLON);
8108 return new ReturnStatement(returnKeyword, expression, semicolon); 8107 return new ReturnStatement(returnKeyword, expression, semicolon);
8109 } 8108 }
8110 8109
8111 /** 8110 /**
8112 * Parse a setter. 8111 * Parse a setter.
8113 * 8112 *
8114 * <pre> 8113 * <pre>
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
8161 * additiveExpression (shiftOperator additiveExpression)* 8160 * additiveExpression (shiftOperator additiveExpression)*
8162 * | 'super' (shiftOperator additiveExpression)+ 8161 * | 'super' (shiftOperator additiveExpression)+
8163 * </pre> 8162 * </pre>
8164 * 8163 *
8165 * @return the shift expression that was parsed 8164 * @return the shift expression that was parsed
8166 */ 8165 */
8167 Expression _parseShiftExpression() { 8166 Expression _parseShiftExpression() {
8168 Expression expression; 8167 Expression expression;
8169 if (_matchesKeyword(Keyword.SUPER) && 8168 if (_matchesKeyword(Keyword.SUPER) &&
8170 _currentToken.next.type.isShiftOperator) { 8169 _currentToken.next.type.isShiftOperator) {
8171 expression = new SuperExpression(andAdvance); 8170 expression = new SuperExpression(getAndAdvance());
8172 } else { 8171 } else {
8173 expression = _parseAdditiveExpression(); 8172 expression = _parseAdditiveExpression();
8174 } 8173 }
8175 while (_currentToken.type.isShiftOperator) { 8174 while (_currentToken.type.isShiftOperator) {
8176 Token operator = andAdvance; 8175 Token operator = getAndAdvance();
8177 expression = 8176 expression =
8178 new BinaryExpression(expression, operator, _parseAdditiveExpression()) ; 8177 new BinaryExpression(expression, operator, _parseAdditiveExpression()) ;
8179 } 8178 }
8180 return expression; 8179 return expression;
8181 } 8180 }
8182 8181
8183 /** 8182 /**
8184 * Parse a list of statements within a switch statement. 8183 * Parse a list of statements within a switch statement.
8185 * 8184 *
8186 * <pre> 8185 * <pre>
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
8218 List<InterpolationElement> elements = new List<InterpolationElement>(); 8217 List<InterpolationElement> elements = new List<InterpolationElement>();
8219 bool hasMore = 8218 bool hasMore =
8220 _matches(TokenType.STRING_INTERPOLATION_EXPRESSION) || 8219 _matches(TokenType.STRING_INTERPOLATION_EXPRESSION) ||
8221 _matches(TokenType.STRING_INTERPOLATION_IDENTIFIER); 8220 _matches(TokenType.STRING_INTERPOLATION_IDENTIFIER);
8222 elements.add( 8221 elements.add(
8223 new InterpolationString( 8222 new InterpolationString(
8224 string, 8223 string,
8225 _computeStringValue(string.lexeme, true, !hasMore))); 8224 _computeStringValue(string.lexeme, true, !hasMore)));
8226 while (hasMore) { 8225 while (hasMore) {
8227 if (_matches(TokenType.STRING_INTERPOLATION_EXPRESSION)) { 8226 if (_matches(TokenType.STRING_INTERPOLATION_EXPRESSION)) {
8228 Token openToken = andAdvance; 8227 Token openToken = getAndAdvance();
8229 bool wasInInitializer = _inInitializer; 8228 bool wasInInitializer = _inInitializer;
8230 _inInitializer = false; 8229 _inInitializer = false;
8231 try { 8230 try {
8232 Expression expression = parseExpression2(); 8231 Expression expression = parseExpression2();
8233 Token rightBracket = _expect(TokenType.CLOSE_CURLY_BRACKET); 8232 Token rightBracket = _expect(TokenType.CLOSE_CURLY_BRACKET);
8234 elements.add( 8233 elements.add(
8235 new InterpolationExpression(openToken, expression, rightBracket)); 8234 new InterpolationExpression(openToken, expression, rightBracket));
8236 } finally { 8235 } finally {
8237 _inInitializer = wasInInitializer; 8236 _inInitializer = wasInInitializer;
8238 } 8237 }
8239 } else { 8238 } else {
8240 Token openToken = andAdvance; 8239 Token openToken = getAndAdvance();
8241 Expression expression = null; 8240 Expression expression = null;
8242 if (_matchesKeyword(Keyword.THIS)) { 8241 if (_matchesKeyword(Keyword.THIS)) {
8243 expression = new ThisExpression(andAdvance); 8242 expression = new ThisExpression(getAndAdvance());
8244 } else { 8243 } else {
8245 expression = parseSimpleIdentifier(); 8244 expression = parseSimpleIdentifier();
8246 } 8245 }
8247 elements.add(new InterpolationExpression(openToken, expression, null)); 8246 elements.add(new InterpolationExpression(openToken, expression, null));
8248 } 8247 }
8249 if (_matches(TokenType.STRING)) { 8248 if (_matches(TokenType.STRING)) {
8250 string = andAdvance; 8249 string = getAndAdvance();
8251 hasMore = _matches(TokenType.STRING_INTERPOLATION_EXPRESSION) || 8250 hasMore = _matches(TokenType.STRING_INTERPOLATION_EXPRESSION) ||
8252 _matches(TokenType.STRING_INTERPOLATION_IDENTIFIER); 8251 _matches(TokenType.STRING_INTERPOLATION_IDENTIFIER);
8253 elements.add( 8252 elements.add(
8254 new InterpolationString( 8253 new InterpolationString(
8255 string, 8254 string,
8256 _computeStringValue(string.lexeme, false, !hasMore))); 8255 _computeStringValue(string.lexeme, false, !hasMore)));
8257 } else { 8256 } else {
8258 hasMore = false; 8257 hasMore = false;
8259 } 8258 }
8260 } 8259 }
8261 return new StringInterpolation(elements); 8260 return new StringInterpolation(elements);
8262 } 8261 }
8263 8262
8264 /** 8263 /**
8265 * Parse a super constructor invocation. 8264 * Parse a super constructor invocation.
8266 * 8265 *
8267 * <pre> 8266 * <pre>
8268 * superConstructorInvocation ::= 8267 * superConstructorInvocation ::=
8269 * 'super' ('.' identifier)? arguments 8268 * 'super' ('.' identifier)? arguments
8270 * </pre> 8269 * </pre>
8271 * 8270 *
8272 * @return the super constructor invocation that was parsed 8271 * @return the super constructor invocation that was parsed
8273 */ 8272 */
8274 SuperConstructorInvocation _parseSuperConstructorInvocation() { 8273 SuperConstructorInvocation _parseSuperConstructorInvocation() {
8275 Token keyword = _expectKeyword(Keyword.SUPER); 8274 Token keyword = _expectKeyword(Keyword.SUPER);
8276 Token period = null; 8275 Token period = null;
8277 SimpleIdentifier constructorName = null; 8276 SimpleIdentifier constructorName = null;
8278 if (_matches(TokenType.PERIOD)) { 8277 if (_matches(TokenType.PERIOD)) {
8279 period = andAdvance; 8278 period = getAndAdvance();
8280 constructorName = parseSimpleIdentifier(); 8279 constructorName = parseSimpleIdentifier();
8281 } 8280 }
8282 ArgumentList argumentList = parseArgumentList(); 8281 ArgumentList argumentList = parseArgumentList();
8283 return new SuperConstructorInvocation( 8282 return new SuperConstructorInvocation(
8284 keyword, 8283 keyword,
8285 period, 8284 period,
8286 constructorName, 8285 constructorName,
8287 argumentList); 8286 argumentList);
8288 } 8287 }
8289 8288
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
8327 ParserErrorCode.DUPLICATE_LABEL_IN_SWITCH_STATEMENT, 8326 ParserErrorCode.DUPLICATE_LABEL_IN_SWITCH_STATEMENT,
8328 identifier.token, 8327 identifier.token,
8329 [label]); 8328 [label]);
8330 } else { 8329 } else {
8331 definedLabels.add(label); 8330 definedLabels.add(label);
8332 } 8331 }
8333 Token colon = _expect(TokenType.COLON); 8332 Token colon = _expect(TokenType.COLON);
8334 labels.add(new Label(identifier, colon)); 8333 labels.add(new Label(identifier, colon));
8335 } 8334 }
8336 if (_matchesKeyword(Keyword.CASE)) { 8335 if (_matchesKeyword(Keyword.CASE)) {
8337 Token caseKeyword = andAdvance; 8336 Token caseKeyword = getAndAdvance();
8338 Expression caseExpression = parseExpression2(); 8337 Expression caseExpression = parseExpression2();
8339 Token colon = _expect(TokenType.COLON); 8338 Token colon = _expect(TokenType.COLON);
8340 members.add( 8339 members.add(
8341 new SwitchCase( 8340 new SwitchCase(
8342 labels, 8341 labels,
8343 caseKeyword, 8342 caseKeyword,
8344 caseExpression, 8343 caseExpression,
8345 colon, 8344 colon,
8346 _parseStatementList())); 8345 _parseStatementList()));
8347 if (defaultKeyword != null) { 8346 if (defaultKeyword != null) {
8348 _reportErrorForToken( 8347 _reportErrorForToken(
8349 ParserErrorCode.SWITCH_HAS_CASE_AFTER_DEFAULT_CASE, 8348 ParserErrorCode.SWITCH_HAS_CASE_AFTER_DEFAULT_CASE,
8350 caseKeyword); 8349 caseKeyword);
8351 } 8350 }
8352 } else if (_matchesKeyword(Keyword.DEFAULT)) { 8351 } else if (_matchesKeyword(Keyword.DEFAULT)) {
8353 if (defaultKeyword != null) { 8352 if (defaultKeyword != null) {
8354 _reportErrorForToken( 8353 _reportErrorForToken(
8355 ParserErrorCode.SWITCH_HAS_MULTIPLE_DEFAULT_CASES, 8354 ParserErrorCode.SWITCH_HAS_MULTIPLE_DEFAULT_CASES,
8356 _peek()); 8355 _peek());
8357 } 8356 }
8358 defaultKeyword = andAdvance; 8357 defaultKeyword = getAndAdvance();
8359 Token colon = _expect(TokenType.COLON); 8358 Token colon = _expect(TokenType.COLON);
8360 members.add( 8359 members.add(
8361 new SwitchDefault(labels, defaultKeyword, colon, _parseStatementLi st())); 8360 new SwitchDefault(labels, defaultKeyword, colon, _parseStatementLi st()));
8362 } else { 8361 } else {
8363 // We need to advance, otherwise we could end up in an infinite loop, 8362 // We need to advance, otherwise we could end up in an infinite loop,
8364 // but this could be a lot smarter about recovering from the error. 8363 // but this could be a lot smarter about recovering from the error.
8365 _reportErrorForCurrentToken(ParserErrorCode.EXPECTED_CASE_OR_DEFAULT); 8364 _reportErrorForCurrentToken(ParserErrorCode.EXPECTED_CASE_OR_DEFAULT);
8366 while (!_matches(TokenType.EOF) && 8365 while (!_matches(TokenType.EOF) &&
8367 !_matches(TokenType.CLOSE_CURLY_BRACKET) && 8366 !_matches(TokenType.CLOSE_CURLY_BRACKET) &&
8368 !_matchesKeyword(Keyword.CASE) && 8367 !_matchesKeyword(Keyword.CASE) &&
(...skipping 20 matching lines...) Expand all
8389 * Parse a symbol literal. 8388 * Parse a symbol literal.
8390 * 8389 *
8391 * <pre> 8390 * <pre>
8392 * symbolLiteral ::= 8391 * symbolLiteral ::=
8393 * '#' identifier ('.' identifier)* 8392 * '#' identifier ('.' identifier)*
8394 * </pre> 8393 * </pre>
8395 * 8394 *
8396 * @return the symbol literal that was parsed 8395 * @return the symbol literal that was parsed
8397 */ 8396 */
8398 SymbolLiteral _parseSymbolLiteral() { 8397 SymbolLiteral _parseSymbolLiteral() {
8399 Token poundSign = andAdvance; 8398 Token poundSign = getAndAdvance();
8400 List<Token> components = new List<Token>(); 8399 List<Token> components = new List<Token>();
8401 if (_matchesIdentifier()) { 8400 if (_matchesIdentifier()) {
8402 components.add(andAdvance); 8401 components.add(getAndAdvance());
8403 while (_matches(TokenType.PERIOD)) { 8402 while (_matches(TokenType.PERIOD)) {
8404 _advance(); 8403 _advance();
8405 if (_matchesIdentifier()) { 8404 if (_matchesIdentifier()) {
8406 components.add(andAdvance); 8405 components.add(getAndAdvance());
8407 } else { 8406 } else {
8408 _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER); 8407 _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER);
8409 components.add(_createSyntheticToken(TokenType.IDENTIFIER)); 8408 components.add(_createSyntheticToken(TokenType.IDENTIFIER));
8410 break; 8409 break;
8411 } 8410 }
8412 } 8411 }
8413 } else if (_currentToken.isOperator) { 8412 } else if (_currentToken.isOperator) {
8414 components.add(andAdvance); 8413 components.add(getAndAdvance());
8415 } else if (_tokenMatchesKeyword(_currentToken, Keyword.VOID)) { 8414 } else if (_tokenMatchesKeyword(_currentToken, Keyword.VOID)) {
8416 components.add(andAdvance); 8415 components.add(getAndAdvance());
8417 } else { 8416 } else {
8418 _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER); 8417 _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER);
8419 components.add(_createSyntheticToken(TokenType.IDENTIFIER)); 8418 components.add(_createSyntheticToken(TokenType.IDENTIFIER));
8420 } 8419 }
8421 return new SymbolLiteral(poundSign, components); 8420 return new SymbolLiteral(poundSign, components);
8422 } 8421 }
8423 8422
8424 /** 8423 /**
8425 * Parse a throw expression. 8424 * Parse a throw expression.
8426 * 8425 *
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
8487 */ 8486 */
8488 Statement _parseTryStatement() { 8487 Statement _parseTryStatement() {
8489 Token tryKeyword = _expectKeyword(Keyword.TRY); 8488 Token tryKeyword = _expectKeyword(Keyword.TRY);
8490 Block body = parseBlock(); 8489 Block body = parseBlock();
8491 List<CatchClause> catchClauses = new List<CatchClause>(); 8490 List<CatchClause> catchClauses = new List<CatchClause>();
8492 Block finallyClause = null; 8491 Block finallyClause = null;
8493 while (_matchesString(_ON) || _matchesKeyword(Keyword.CATCH)) { 8492 while (_matchesString(_ON) || _matchesKeyword(Keyword.CATCH)) {
8494 Token onKeyword = null; 8493 Token onKeyword = null;
8495 TypeName exceptionType = null; 8494 TypeName exceptionType = null;
8496 if (_matchesString(_ON)) { 8495 if (_matchesString(_ON)) {
8497 onKeyword = andAdvance; 8496 onKeyword = getAndAdvance();
8498 exceptionType = parseTypeName(); 8497 exceptionType = parseTypeName();
8499 } 8498 }
8500 Token catchKeyword = null; 8499 Token catchKeyword = null;
8501 Token leftParenthesis = null; 8500 Token leftParenthesis = null;
8502 SimpleIdentifier exceptionParameter = null; 8501 SimpleIdentifier exceptionParameter = null;
8503 Token comma = null; 8502 Token comma = null;
8504 SimpleIdentifier stackTraceParameter = null; 8503 SimpleIdentifier stackTraceParameter = null;
8505 Token rightParenthesis = null; 8504 Token rightParenthesis = null;
8506 if (_matchesKeyword(Keyword.CATCH)) { 8505 if (_matchesKeyword(Keyword.CATCH)) {
8507 catchKeyword = andAdvance; 8506 catchKeyword = getAndAdvance();
8508 leftParenthesis = _expect(TokenType.OPEN_PAREN); 8507 leftParenthesis = _expect(TokenType.OPEN_PAREN);
8509 exceptionParameter = parseSimpleIdentifier(); 8508 exceptionParameter = parseSimpleIdentifier();
8510 if (_matches(TokenType.COMMA)) { 8509 if (_matches(TokenType.COMMA)) {
8511 comma = andAdvance; 8510 comma = getAndAdvance();
8512 stackTraceParameter = parseSimpleIdentifier(); 8511 stackTraceParameter = parseSimpleIdentifier();
8513 } 8512 }
8514 rightParenthesis = _expect(TokenType.CLOSE_PAREN); 8513 rightParenthesis = _expect(TokenType.CLOSE_PAREN);
8515 } 8514 }
8516 Block catchBody = parseBlock(); 8515 Block catchBody = parseBlock();
8517 catchClauses.add( 8516 catchClauses.add(
8518 new CatchClause( 8517 new CatchClause(
8519 onKeyword, 8518 onKeyword,
8520 exceptionType, 8519 exceptionType,
8521 catchKeyword, 8520 catchKeyword,
8522 leftParenthesis, 8521 leftParenthesis,
8523 exceptionParameter, 8522 exceptionParameter,
8524 comma, 8523 comma,
8525 stackTraceParameter, 8524 stackTraceParameter,
8526 rightParenthesis, 8525 rightParenthesis,
8527 catchBody)); 8526 catchBody));
8528 } 8527 }
8529 Token finallyKeyword = null; 8528 Token finallyKeyword = null;
8530 if (_matchesKeyword(Keyword.FINALLY)) { 8529 if (_matchesKeyword(Keyword.FINALLY)) {
8531 finallyKeyword = andAdvance; 8530 finallyKeyword = getAndAdvance();
8532 finallyClause = parseBlock(); 8531 finallyClause = parseBlock();
8533 } else { 8532 } else {
8534 if (catchClauses.isEmpty) { 8533 if (catchClauses.isEmpty) {
8535 _reportErrorForCurrentToken(ParserErrorCode.MISSING_CATCH_OR_FINALLY); 8534 _reportErrorForCurrentToken(ParserErrorCode.MISSING_CATCH_OR_FINALLY);
8536 } 8535 }
8537 } 8536 }
8538 return new TryStatement( 8537 return new TryStatement(
8539 tryKeyword, 8538 tryKeyword,
8540 body, 8539 body,
8541 catchClauses, 8540 catchClauses,
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
8608 * | '-' 'super' 8607 * | '-' 'super'
8609 * | incrementOperator assignableExpression 8608 * | incrementOperator assignableExpression
8610 * </pre> 8609 * </pre>
8611 * 8610 *
8612 * @return the unary expression that was parsed 8611 * @return the unary expression that was parsed
8613 */ 8612 */
8614 Expression _parseUnaryExpression() { 8613 Expression _parseUnaryExpression() {
8615 if (_matches(TokenType.MINUS) || 8614 if (_matches(TokenType.MINUS) ||
8616 _matches(TokenType.BANG) || 8615 _matches(TokenType.BANG) ||
8617 _matches(TokenType.TILDE)) { 8616 _matches(TokenType.TILDE)) {
8618 Token operator = andAdvance; 8617 Token operator = getAndAdvance();
8619 if (_matchesKeyword(Keyword.SUPER)) { 8618 if (_matchesKeyword(Keyword.SUPER)) {
8620 if (_tokenMatches(_peek(), TokenType.OPEN_SQUARE_BRACKET) || 8619 if (_tokenMatches(_peek(), TokenType.OPEN_SQUARE_BRACKET) ||
8621 _tokenMatches(_peek(), TokenType.PERIOD)) { 8620 _tokenMatches(_peek(), TokenType.PERIOD)) {
8622 // "prefixOperator unaryExpression" 8621 // "prefixOperator unaryExpression"
8623 // --> "prefixOperator postfixExpression" 8622 // --> "prefixOperator postfixExpression"
8624 // --> "prefixOperator primary selector*" 8623 // --> "prefixOperator primary selector*"
8625 // --> "prefixOperator 'super' assignableSelector selector*" 8624 // --> "prefixOperator 'super' assignableSelector selector*"
8626 return new PrefixExpression(operator, _parseUnaryExpression()); 8625 return new PrefixExpression(operator, _parseUnaryExpression());
8627 } 8626 }
8628 return new PrefixExpression(operator, new SuperExpression(andAdvance)); 8627 return new PrefixExpression(operator, new SuperExpression(getAndAdvance( )));
8629 } 8628 }
8630 return new PrefixExpression(operator, _parseUnaryExpression()); 8629 return new PrefixExpression(operator, _parseUnaryExpression());
8631 } else if (_currentToken.type.isIncrementOperator) { 8630 } else if (_currentToken.type.isIncrementOperator) {
8632 Token operator = andAdvance; 8631 Token operator = getAndAdvance();
8633 if (_matchesKeyword(Keyword.SUPER)) { 8632 if (_matchesKeyword(Keyword.SUPER)) {
8634 if (_tokenMatches(_peek(), TokenType.OPEN_SQUARE_BRACKET) || 8633 if (_tokenMatches(_peek(), TokenType.OPEN_SQUARE_BRACKET) ||
8635 _tokenMatches(_peek(), TokenType.PERIOD)) { 8634 _tokenMatches(_peek(), TokenType.PERIOD)) {
8636 // --> "prefixOperator 'super' assignableSelector selector*" 8635 // --> "prefixOperator 'super' assignableSelector selector*"
8637 return new PrefixExpression(operator, _parseUnaryExpression()); 8636 return new PrefixExpression(operator, _parseUnaryExpression());
8638 } 8637 }
8639 // 8638 //
8640 // Even though it is not valid to use an incrementing operator 8639 // Even though it is not valid to use an incrementing operator
8641 // ('++' or '--') before 'super', we can (and therefore must) interpret 8640 // ('++' or '--') before 'super', we can (and therefore must) interpret
8642 // "--super" as semantically equivalent to "-(-super)". Unfortunately, 8641 // "--super" as semantically equivalent to "-(-super)". Unfortunately,
8643 // we cannot do the same for "++super" because "+super" is also not 8642 // we cannot do the same for "++super" because "+super" is also not
8644 // valid. 8643 // valid.
8645 // 8644 //
8646 if (operator.type == TokenType.MINUS_MINUS) { 8645 if (operator.type == TokenType.MINUS_MINUS) {
8647 int offset = operator.offset; 8646 int offset = operator.offset;
8648 Token firstOperator = new Token(TokenType.MINUS, offset); 8647 Token firstOperator = new Token(TokenType.MINUS, offset);
8649 Token secondOperator = new Token(TokenType.MINUS, offset + 1); 8648 Token secondOperator = new Token(TokenType.MINUS, offset + 1);
8650 secondOperator.setNext(_currentToken); 8649 secondOperator.setNext(_currentToken);
8651 firstOperator.setNext(secondOperator); 8650 firstOperator.setNext(secondOperator);
8652 operator.previous.setNext(firstOperator); 8651 operator.previous.setNext(firstOperator);
8653 return new PrefixExpression( 8652 return new PrefixExpression(
8654 firstOperator, 8653 firstOperator,
8655 new PrefixExpression(secondOperator, new SuperExpression(andAdvanc e))); 8654 new PrefixExpression(secondOperator, new SuperExpression(getAndAdv ance())));
8656 } else { 8655 } else {
8657 // Invalid operator before 'super' 8656 // Invalid operator before 'super'
8658 _reportErrorForCurrentToken( 8657 _reportErrorForCurrentToken(
8659 ParserErrorCode.INVALID_OPERATOR_FOR_SUPER, 8658 ParserErrorCode.INVALID_OPERATOR_FOR_SUPER,
8660 [operator.lexeme]); 8659 [operator.lexeme]);
8661 return new PrefixExpression( 8660 return new PrefixExpression(
8662 operator, 8661 operator,
8663 new SuperExpression(andAdvance)); 8662 new SuperExpression(getAndAdvance()));
8664 } 8663 }
8665 } 8664 }
8666 return new PrefixExpression(operator, _parseAssignableExpression(false)); 8665 return new PrefixExpression(operator, _parseAssignableExpression(false));
8667 } else if (_matches(TokenType.PLUS)) { 8666 } else if (_matches(TokenType.PLUS)) {
8668 _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER); 8667 _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER);
8669 return _createSyntheticIdentifier(); 8668 return _createSyntheticIdentifier();
8670 } else if (_matchesString(_AWAIT)) { 8669 } else if (_matchesString(_AWAIT)) {
8671 return _parseAwaitExpression(); 8670 return _parseAwaitExpression();
8672 } 8671 }
8673 return _parsePostfixExpression(); 8672 return _parsePostfixExpression();
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
8734 * </pre> 8733 * </pre>
8735 * 8734 *
8736 * @return the variable declaration that was parsed 8735 * @return the variable declaration that was parsed
8737 */ 8736 */
8738 VariableDeclaration _parseVariableDeclaration() { 8737 VariableDeclaration _parseVariableDeclaration() {
8739 CommentAndMetadata commentAndMetadata = _parseCommentAndMetadata(); 8738 CommentAndMetadata commentAndMetadata = _parseCommentAndMetadata();
8740 SimpleIdentifier name = parseSimpleIdentifier(); 8739 SimpleIdentifier name = parseSimpleIdentifier();
8741 Token equals = null; 8740 Token equals = null;
8742 Expression initializer = null; 8741 Expression initializer = null;
8743 if (_matches(TokenType.EQ)) { 8742 if (_matches(TokenType.EQ)) {
8744 equals = andAdvance; 8743 equals = getAndAdvance();
8745 initializer = parseExpression2(); 8744 initializer = parseExpression2();
8746 } 8745 }
8747 return new VariableDeclaration( 8746 return new VariableDeclaration(
8748 commentAndMetadata.comment, 8747 commentAndMetadata.comment,
8749 commentAndMetadata.metadata, 8748 commentAndMetadata.metadata,
8750 name, 8749 name,
8751 equals, 8750 equals,
8752 initializer); 8751 initializer);
8753 } 8752 }
8754 8753
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
8894 * Parse a yield statement. 8893 * Parse a yield statement.
8895 * 8894 *
8896 * <pre> 8895 * <pre>
8897 * yieldStatement ::= 8896 * yieldStatement ::=
8898 * 'yield' '*'? expression ';' 8897 * 'yield' '*'? expression ';'
8899 * </pre> 8898 * </pre>
8900 * 8899 *
8901 * @return the yield statement that was parsed 8900 * @return the yield statement that was parsed
8902 */ 8901 */
8903 YieldStatement _parseYieldStatement() { 8902 YieldStatement _parseYieldStatement() {
8904 Token yieldToken = andAdvance; 8903 Token yieldToken = getAndAdvance();
8905 Token star = null; 8904 Token star = null;
8906 if (_matches(TokenType.STAR)) { 8905 if (_matches(TokenType.STAR)) {
8907 star = andAdvance; 8906 star = getAndAdvance();
8908 } 8907 }
8909 Expression expression = parseExpression2(); 8908 Expression expression = parseExpression2();
8910 Token semicolon = _expect(TokenType.SEMICOLON); 8909 Token semicolon = _expect(TokenType.SEMICOLON);
8911 return new YieldStatement(yieldToken, star, expression, semicolon); 8910 return new YieldStatement(yieldToken, star, expression, semicolon);
8912 } 8911 }
8913 8912
8914 /** 8913 /**
8915 * Return the token that is immediately after the current token. This is equiv alent to 8914 * Return the token that is immediately after the current token. This is equiv alent to
8916 * [peekAt]. 8915 * [peekAt].
8917 * 8916 *
(...skipping 3245 matching lines...) Expand 10 before | Expand all | Expand 10 after
12163 * Copy resolution data from one node to another. 12162 * Copy resolution data from one node to another.
12164 * 12163 *
12165 * @param fromNode the node from which resolution information will be copied 12164 * @param fromNode the node from which resolution information will be copied
12166 * @param toNode the node to which resolution information will be copied 12165 * @param toNode the node to which resolution information will be copied
12167 */ 12166 */
12168 static void copyResolutionData(AstNode fromNode, AstNode toNode) { 12167 static void copyResolutionData(AstNode fromNode, AstNode toNode) {
12169 ResolutionCopier copier = new ResolutionCopier(); 12168 ResolutionCopier copier = new ResolutionCopier();
12170 copier._isEqualNodes(fromNode, toNode); 12169 copier._isEqualNodes(fromNode, toNode);
12171 } 12170 }
12172 } 12171 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698