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

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

Issue 668083002: Better recovery for getters in functions (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine.parser; 8 library engine.parser;
9 9
10 import 'dart:collection'; 10 import 'dart:collection';
(...skipping 3172 matching lines...) Expand 10 before | Expand all | Expand 10 after
3183 * @return the token that was just added to the token stream 3183 * @return the token that was just added to the token stream
3184 */ 3184 */
3185 Token _injectToken(Token token) { 3185 Token _injectToken(Token token) {
3186 Token previous = _currentToken.previous; 3186 Token previous = _currentToken.previous;
3187 token.setNext(_currentToken); 3187 token.setNext(_currentToken);
3188 previous.setNext(token); 3188 previous.setNext(token);
3189 return token; 3189 return token;
3190 } 3190 }
3191 3191
3192 /** 3192 /**
3193 * Return `true` if the current token appears to be the beginning of a functio n declaration. 3193 * Return `true` if the current token appears to be the beginning of a
3194 * 3194 * function declaration.
3195 * @return `true` if the current token appears to be the beginning of a functi on declaration
3196 */ 3195 */
3197 bool _isFunctionDeclaration() { 3196 bool _isFunctionDeclaration() {
3198 if (_matchesKeyword(Keyword.VOID)) { 3197 if (_matchesKeyword(Keyword.VOID)) {
3199 return true; 3198 return true;
3200 } 3199 }
3201 Token afterReturnType = _skipTypeName(_currentToken); 3200 Token afterReturnType = _skipTypeName(_currentToken);
3202 if (afterReturnType == null) { 3201 if (afterReturnType == null) {
3203 // There was no return type, but it is optional, so go back to where we st arted. 3202 // There was no return type, but it is optional, so go back to where we
3203 // started.
3204 afterReturnType = _currentToken; 3204 afterReturnType = _currentToken;
3205 } 3205 }
3206 Token afterIdentifier = _skipSimpleIdentifier(afterReturnType); 3206 Token afterIdentifier = _skipSimpleIdentifier(afterReturnType);
3207 if (afterIdentifier == null) { 3207 if (afterIdentifier == null) {
3208 // It's possible that we parsed the function name as if it were a type nam e, so see whether 3208 // It's possible that we parsed the function name as if it were a type
3209 // it makes sense if we assume that there is no type. 3209 // name, so see whether it makes sense if we assume that there is no type.
3210 afterIdentifier = _skipSimpleIdentifier(_currentToken); 3210 afterIdentifier = _skipSimpleIdentifier(_currentToken);
3211 } 3211 }
3212 if (afterIdentifier == null) { 3212 if (afterIdentifier == null) {
3213 return false; 3213 return false;
3214 } 3214 }
3215 if (_isFunctionExpression(afterIdentifier)) { 3215 if (_isFunctionExpression(afterIdentifier)) {
3216 return true; 3216 return true;
3217 } 3217 }
3218 // It's possible that we have found a getter. While this isn't valid at this point we test for 3218 // It's possible that we have found a getter. While this isn't valid at this
3219 // it in order to recover better. 3219 // point we test for it in order to recover better.
3220 if (_matchesKeyword(Keyword.GET)) { 3220 if (_matchesKeyword(Keyword.GET)) {
3221 Token afterName = _skipSimpleIdentifier(_currentToken.next); 3221 Token afterName = _skipSimpleIdentifier(_currentToken.next);
3222 if (afterName == null) { 3222 if (afterName == null) {
3223 return false; 3223 return false;
3224 } 3224 }
3225 return _tokenMatches(afterName, TokenType.FUNCTION) || _tokenMatches(after Name, TokenType.OPEN_CURLY_BRACKET); 3225 return _tokenMatches(afterName, TokenType.FUNCTION)
3226 || _tokenMatches(afterName, TokenType.OPEN_CURLY_BRACKET);
3227 } else if (_tokenMatchesKeyword(afterReturnType, Keyword.GET)) {
3228 Token afterName = _skipSimpleIdentifier(afterReturnType.next);
3229 if (afterName == null) {
3230 return false;
3231 }
3232 return _tokenMatches(afterName, TokenType.FUNCTION)
3233 || _tokenMatches(afterName, TokenType.OPEN_CURLY_BRACKET);
3226 } 3234 }
3227 return false; 3235 return false;
3228 } 3236 }
3229 3237
3230 /** 3238 /**
3231 * Return `true` if the given token appears to be the beginning of a function expression. 3239 * Return `true` if the given token appears to be the beginning of a function expression.
3232 * 3240 *
3233 * @param startToken the token that might be the start of a function expressio n 3241 * @param startToken the token that might be the start of a function expressio n
3234 * @return `true` if the given token appears to be the beginning of a function expression 3242 * @return `true` if the given token appears to be the beginning of a function expression
3235 */ 3243 */
(...skipping 6282 matching lines...) Expand 10 before | Expand all | Expand 10 after
9518 return trampoline(target, arguments[0], arguments[1]); 9526 return trampoline(target, arguments[0], arguments[1]);
9519 case 3: 9527 case 3:
9520 return trampoline(target, arguments[0], arguments[1], arguments[2]); 9528 return trampoline(target, arguments[0], arguments[1], arguments[2]);
9521 case 4: 9529 case 4:
9522 return trampoline(target, arguments[0], arguments[1], arguments[2], argu ments[3]); 9530 return trampoline(target, arguments[0], arguments[1], arguments[2], argu ments[3]);
9523 default: 9531 default:
9524 throw new IllegalArgumentException("Not implemented for > 4 arguments"); 9532 throw new IllegalArgumentException("Not implemented for > 4 arguments");
9525 } 9533 }
9526 } 9534 }
9527 } 9535 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698