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

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

Issue 1216873002: Add parsing support for generic methods (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: sort and format Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/parser_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // 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 2315 matching lines...) Expand 10 before | Expand all | Expand 10 after
2326 return _parseSetter(commentAndMetadata, modifiers.externalKeyword, 2326 return _parseSetter(commentAndMetadata, modifiers.externalKeyword,
2327 modifiers.staticKeyword, returnType); 2327 modifiers.staticKeyword, returnType);
2328 } else if (_matchesKeyword(Keyword.OPERATOR) && _isOperator(_peek())) { 2328 } else if (_matchesKeyword(Keyword.OPERATOR) && _isOperator(_peek())) {
2329 _validateModifiersForOperator(modifiers); 2329 _validateModifiersForOperator(modifiers);
2330 return _parseOperator( 2330 return _parseOperator(
2331 commentAndMetadata, modifiers.externalKeyword, returnType); 2331 commentAndMetadata, modifiers.externalKeyword, returnType);
2332 } else if (_matchesIdentifier() && 2332 } else if (_matchesIdentifier() &&
2333 _peek().matchesAny([ 2333 _peek().matchesAny([
2334 TokenType.OPEN_PAREN, 2334 TokenType.OPEN_PAREN,
2335 TokenType.OPEN_CURLY_BRACKET, 2335 TokenType.OPEN_CURLY_BRACKET,
2336 TokenType.FUNCTION 2336 TokenType.FUNCTION,
2337 TokenType.LT
2337 ])) { 2338 ])) {
2338 _validateModifiersForGetterOrSetterOrMethod(modifiers); 2339 _validateModifiersForGetterOrSetterOrMethod(modifiers);
2339 return _parseMethodDeclarationAfterReturnType(commentAndMetadata, 2340 return _parseMethodDeclarationAfterReturnType(commentAndMetadata,
2340 modifiers.externalKeyword, modifiers.staticKeyword, returnType); 2341 modifiers.externalKeyword, modifiers.staticKeyword, returnType);
2341 } else { 2342 } else {
2342 // 2343 //
2343 // We have found an error of some kind. Try to recover. 2344 // We have found an error of some kind. Try to recover.
2344 // 2345 //
2345 if (_matchesIdentifier()) { 2346 if (_matchesIdentifier()) {
2346 if (_peek().matchesAny( 2347 if (_peek().matchesAny(
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
2481 ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE); 2482 ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE);
2482 } 2483 }
2483 return _parseInitializedIdentifierList(commentAndMetadata, 2484 return _parseInitializedIdentifierList(commentAndMetadata,
2484 modifiers.staticKeyword, _validateModifiersForField(modifiers), null); 2485 modifiers.staticKeyword, _validateModifiersForField(modifiers), null);
2485 } else if (_matchesKeyword(Keyword.TYPEDEF)) { 2486 } else if (_matchesKeyword(Keyword.TYPEDEF)) {
2486 _reportErrorForCurrentToken(ParserErrorCode.TYPEDEF_IN_CLASS); 2487 _reportErrorForCurrentToken(ParserErrorCode.TYPEDEF_IN_CLASS);
2487 // TODO(brianwilkerson) We don't currently have any way to capture the 2488 // TODO(brianwilkerson) We don't currently have any way to capture the
2488 // function type alias that was parsed. 2489 // function type alias that was parsed.
2489 _parseFunctionTypeAlias(commentAndMetadata, getAndAdvance()); 2490 _parseFunctionTypeAlias(commentAndMetadata, getAndAdvance());
2490 return null; 2491 return null;
2492 } else if (parseGenericMethods) {
2493 Token token = _skipTypeParameterList(_peek());
2494 if (token != null && _tokenMatches(token, TokenType.OPEN_PAREN)) {
2495 return _parseMethodDeclarationAfterReturnType(commentAndMetadata,
2496 modifiers.externalKeyword, modifiers.staticKeyword, null);
2497 }
2491 } 2498 }
2492 TypeName type = parseTypeName(); 2499 TypeName type = parseTypeName();
2493 if (_matchesKeyword(Keyword.GET) && _tokenMatchesIdentifier(_peek())) { 2500 if (_matchesKeyword(Keyword.GET) && _tokenMatchesIdentifier(_peek())) {
2494 _validateModifiersForGetterOrSetterOrMethod(modifiers); 2501 _validateModifiersForGetterOrSetterOrMethod(modifiers);
2495 return _parseGetter(commentAndMetadata, modifiers.externalKeyword, 2502 return _parseGetter(commentAndMetadata, modifiers.externalKeyword,
2496 modifiers.staticKeyword, type); 2503 modifiers.staticKeyword, type);
2497 } else if (_matchesKeyword(Keyword.SET) && 2504 } else if (_matchesKeyword(Keyword.SET) &&
2498 _tokenMatchesIdentifier(_peek())) { 2505 _tokenMatchesIdentifier(_peek())) {
2499 _validateModifiersForGetterOrSetterOrMethod(modifiers); 2506 _validateModifiersForGetterOrSetterOrMethod(modifiers);
2500 return _parseSetter(commentAndMetadata, modifiers.externalKeyword, 2507 return _parseSetter(commentAndMetadata, modifiers.externalKeyword,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2545 _reportErrorForNode(ParserErrorCode.CONSTRUCTOR_WITH_RETURN_TYPE, type); 2552 _reportErrorForNode(ParserErrorCode.CONSTRUCTOR_WITH_RETURN_TYPE, type);
2546 return _parseConstructor(commentAndMetadata, modifiers.externalKeyword, 2553 return _parseConstructor(commentAndMetadata, modifiers.externalKeyword,
2547 _validateModifiersForConstructor(modifiers), 2554 _validateModifiersForConstructor(modifiers),
2548 modifiers.factoryKeyword, methodName, null, null, parameters); 2555 modifiers.factoryKeyword, methodName, null, null, parameters);
2549 } 2556 }
2550 _validateModifiersForGetterOrSetterOrMethod(modifiers); 2557 _validateModifiersForGetterOrSetterOrMethod(modifiers);
2551 _validateFormalParameterList(parameters); 2558 _validateFormalParameterList(parameters);
2552 return _parseMethodDeclarationAfterParameters(commentAndMetadata, 2559 return _parseMethodDeclarationAfterParameters(commentAndMetadata,
2553 modifiers.externalKeyword, modifiers.staticKeyword, type, methodName, 2560 modifiers.externalKeyword, modifiers.staticKeyword, type, methodName,
2554 null, parameters); 2561 null, parameters);
2562 } else if (parseGenericMethods && _tokenMatches(_peek(), TokenType.LT)) {
2563 return _parseMethodDeclarationAfterReturnType(commentAndMetadata,
2564 modifiers.externalKeyword, modifiers.staticKeyword, type);
2555 } else if (_tokenMatches(_peek(), TokenType.OPEN_CURLY_BRACKET)) { 2565 } else if (_tokenMatches(_peek(), TokenType.OPEN_CURLY_BRACKET)) {
2556 // We have found "TypeName identifier {", and are guessing that this is a 2566 // We have found "TypeName identifier {", and are guessing that this is a
2557 // getter without the keyword 'get'. 2567 // getter without the keyword 'get'.
2558 _validateModifiersForGetterOrSetterOrMethod(modifiers); 2568 _validateModifiersForGetterOrSetterOrMethod(modifiers);
2559 _reportErrorForCurrentToken(ParserErrorCode.MISSING_GET); 2569 _reportErrorForCurrentToken(ParserErrorCode.MISSING_GET);
2560 _currentToken = _injectToken( 2570 _currentToken = _injectToken(
2561 new Parser_SyntheticKeywordToken(Keyword.GET, _currentToken.offset)); 2571 new Parser_SyntheticKeywordToken(Keyword.GET, _currentToken.offset));
2562 return _parseGetter(commentAndMetadata, modifiers.externalKeyword, 2572 return _parseGetter(commentAndMetadata, modifiers.externalKeyword,
2563 modifiers.staticKeyword, type); 2573 modifiers.staticKeyword, type);
2564 } 2574 }
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
3034 } 3044 }
3035 return new FormalParameterList(leftParenthesis, parameters, 3045 return new FormalParameterList(leftParenthesis, parameters,
3036 leftSquareBracket, rightSquareBracket, rightParenthesis); 3046 leftSquareBracket, rightSquareBracket, rightParenthesis);
3037 } 3047 }
3038 3048
3039 /** 3049 /**
3040 * Parse a function expression. Return the function expression that was 3050 * Parse a function expression. Return the function expression that was
3041 * parsed. 3051 * parsed.
3042 * 3052 *
3043 * functionExpression ::= 3053 * functionExpression ::=
3044 * formalParameterList functionExpressionBody 3054 * typeParameters? formalParameterList functionExpressionBody
3045 */ 3055 */
3046 FunctionExpression parseFunctionExpression() { 3056 FunctionExpression parseFunctionExpression() {
3057 TypeParameterList typeParameters = null;
3058 if (parseGenericMethods && _matches(TokenType.LT)) {
3059 typeParameters = parseTypeParameterList();
3060 }
3047 FormalParameterList parameters = parseFormalParameterList(); 3061 FormalParameterList parameters = parseFormalParameterList();
3048 _validateFormalParameterList(parameters); 3062 _validateFormalParameterList(parameters);
3049 FunctionBody body = 3063 FunctionBody body =
3050 _parseFunctionBody(false, ParserErrorCode.MISSING_FUNCTION_BODY, true); 3064 _parseFunctionBody(false, ParserErrorCode.MISSING_FUNCTION_BODY, true);
3051 return new FunctionExpression(null, parameters, body); 3065 return new FunctionExpression(typeParameters, parameters, body);
3052 } 3066 }
3053 3067
3054 /** 3068 /**
3055 * Parse an if-null expression. Return the if-null expression that was 3069 * Parse an if-null expression. Return the if-null expression that was
3056 * parsed. 3070 * parsed.
3057 * 3071 *
3058 * ifNullExpression ::= logicalOrExpression ('??' logicalOrExpression)* 3072 * ifNullExpression ::= logicalOrExpression ('??' logicalOrExpression)*
3059 */ 3073 */
3060 Expression parseIfNullExpression() { 3074 Expression parseIfNullExpression() {
3061 Expression expression = parseLogicalOrExpression(); 3075 Expression expression = parseLogicalOrExpression();
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
3144 /** 3158 /**
3145 * Parse a normal formal parameter. Return the normal formal parameter that 3159 * Parse a normal formal parameter. Return the normal formal parameter that
3146 * was parsed. 3160 * was parsed.
3147 * 3161 *
3148 * normalFormalParameter ::= 3162 * normalFormalParameter ::=
3149 * functionSignature 3163 * functionSignature
3150 * | fieldFormalParameter 3164 * | fieldFormalParameter
3151 * | simpleFormalParameter 3165 * | simpleFormalParameter
3152 * 3166 *
3153 * functionSignature: 3167 * functionSignature:
3154 * metadata returnType? identifier formalParameterList 3168 * metadata returnType? identifier typeParameters? formalParameterList
3155 * 3169 *
3156 * fieldFormalParameter ::= 3170 * fieldFormalParameter ::=
3157 * metadata finalConstVarOrType? 'this' '.' identifier 3171 * metadata finalConstVarOrType? 'this' '.' identifier
3158 * 3172 *
3159 * simpleFormalParameter ::= 3173 * simpleFormalParameter ::=
3160 * declaredIdentifier 3174 * declaredIdentifier
3161 * | metadata identifier 3175 * | metadata identifier
3162 */ 3176 */
3163 NormalFormalParameter parseNormalFormalParameter() { 3177 NormalFormalParameter parseNormalFormalParameter() {
3164 CommentAndMetadata commentAndMetadata = _parseCommentAndMetadata(); 3178 CommentAndMetadata commentAndMetadata = _parseCommentAndMetadata();
3165 FinalConstVarOrType holder = _parseFinalConstVarOrType(true); 3179 FinalConstVarOrType holder = _parseFinalConstVarOrType(true);
3166 Token thisKeyword = null; 3180 Token thisKeyword = null;
3167 Token period = null; 3181 Token period = null;
3168 if (_matchesKeyword(Keyword.THIS)) { 3182 if (_matchesKeyword(Keyword.THIS)) {
3169 thisKeyword = getAndAdvance(); 3183 thisKeyword = getAndAdvance();
3170 period = _expect(TokenType.PERIOD); 3184 period = _expect(TokenType.PERIOD);
3171 } 3185 }
3172 SimpleIdentifier identifier = parseSimpleIdentifier(); 3186 SimpleIdentifier identifier = parseSimpleIdentifier();
3187 TypeParameterList typeParameters = null;
3188 if (parseGenericMethods && _matches(TokenType.LT)) {
3189 typeParameters = parseTypeParameterList();
3190 }
3173 if (_matches(TokenType.OPEN_PAREN)) { 3191 if (_matches(TokenType.OPEN_PAREN)) {
3174 FormalParameterList parameters = parseFormalParameterList(); 3192 FormalParameterList parameters = parseFormalParameterList();
3175 if (thisKeyword == null) { 3193 if (thisKeyword == null) {
3176 if (holder.keyword != null) { 3194 if (holder.keyword != null) {
3177 _reportErrorForToken( 3195 _reportErrorForToken(
3178 ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR, holder.keyword); 3196 ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR, holder.keyword);
3179 } 3197 }
3180 return new FunctionTypedFormalParameter(commentAndMetadata.comment, 3198 return new FunctionTypedFormalParameter(commentAndMetadata.comment,
3181 commentAndMetadata.metadata, holder.type, identifier, null, 3199 commentAndMetadata.metadata, holder.type, identifier,
3182 parameters); 3200 typeParameters, parameters);
3183 } else { 3201 } else {
3184 return new FieldFormalParameter(commentAndMetadata.comment, 3202 return new FieldFormalParameter(commentAndMetadata.comment,
3185 commentAndMetadata.metadata, holder.keyword, holder.type, 3203 commentAndMetadata.metadata, holder.keyword, holder.type,
3186 thisKeyword, period, identifier, null, parameters); 3204 thisKeyword, period, identifier, typeParameters, parameters);
3187 } 3205 }
3206 } else if (typeParameters != null) {
3207 // TODO(brianwilkerson) Report an error. It looks like a function-typed
3208 // parameter with no parameter list.
3209 //_reportErrorForToken(ParserErrorCode.MISSING_PARAMETERS, typeParameters. endToken);
3188 } 3210 }
3189 TypeName type = holder.type; 3211 TypeName type = holder.type;
3190 if (type != null) { 3212 if (type != null) {
3191 if (_tokenMatchesKeyword(type.name.beginToken, Keyword.VOID)) { 3213 if (_tokenMatchesKeyword(type.name.beginToken, Keyword.VOID)) {
3192 _reportErrorForToken( 3214 _reportErrorForToken(
3193 ParserErrorCode.VOID_PARAMETER, type.name.beginToken); 3215 ParserErrorCode.VOID_PARAMETER, type.name.beginToken);
3194 } else if (holder.keyword != null && 3216 } else if (holder.keyword != null &&
3195 _tokenMatchesKeyword(holder.keyword, Keyword.VAR)) { 3217 _tokenMatchesKeyword(holder.keyword, Keyword.VAR)) {
3196 _reportErrorForToken(ParserErrorCode.VAR_AND_TYPE, holder.keyword); 3218 _reportErrorForToken(ParserErrorCode.VAR_AND_TYPE, holder.keyword);
3197 } 3219 }
3198 } 3220 }
3199 if (thisKeyword != null) { 3221 if (thisKeyword != null) {
3222 // TODO(brianwilkerson) If there are type parameters but no parameters,
3223 // should we create a synthetic empty parameter list here so we can
3224 // capture the type parameters?
3200 return new FieldFormalParameter(commentAndMetadata.comment, 3225 return new FieldFormalParameter(commentAndMetadata.comment,
3201 commentAndMetadata.metadata, holder.keyword, holder.type, thisKeyword, 3226 commentAndMetadata.metadata, holder.keyword, holder.type, thisKeyword,
3202 period, identifier, null, null); 3227 period, identifier, null, null);
3203 } 3228 }
3204 return new SimpleFormalParameter(commentAndMetadata.comment, 3229 return new SimpleFormalParameter(commentAndMetadata.comment,
3205 commentAndMetadata.metadata, holder.keyword, holder.type, identifier); 3230 commentAndMetadata.metadata, holder.keyword, holder.type, identifier);
3206 } 3231 }
3207 3232
3208 /** 3233 /**
3209 * Parse a prefixed identifier. Return the prefixed identifier that was 3234 * Parse a prefixed identifier. Return the prefixed identifier that was
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after
3839 3864
3840 /** 3865 /**
3841 * Return `true` if the given [token] appears to be the beginning of a 3866 * Return `true` if the given [token] appears to be the beginning of a
3842 * function expression. 3867 * function expression.
3843 */ 3868 */
3844 bool _isFunctionExpression(Token token) { 3869 bool _isFunctionExpression(Token token) {
3845 // Function expressions aren't allowed in initializer lists. 3870 // Function expressions aren't allowed in initializer lists.
3846 if (_inInitializer) { 3871 if (_inInitializer) {
3847 return false; 3872 return false;
3848 } 3873 }
3849 Token afterParameters = _skipFormalParameterList(token); 3874 Token afterTypeParameters = _skipTypeParameterList(token);
3875 if (afterTypeParameters == null) {
3876 afterTypeParameters = token;
3877 }
3878 Token afterParameters = _skipFormalParameterList(afterTypeParameters);
3850 if (afterParameters == null) { 3879 if (afterParameters == null) {
3851 return false; 3880 return false;
3852 } 3881 }
3853 if (afterParameters 3882 if (afterParameters
3854 .matchesAny([TokenType.OPEN_CURLY_BRACKET, TokenType.FUNCTION])) { 3883 .matchesAny([TokenType.OPEN_CURLY_BRACKET, TokenType.FUNCTION])) {
3855 return true; 3884 return true;
3856 } 3885 }
3857 String lexeme = afterParameters.lexeme; 3886 String lexeme = afterParameters.lexeme;
3858 return lexeme == ASYNC || lexeme == SYNC; 3887 return lexeme == ASYNC || lexeme == SYNC;
3859 } 3888 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
3916 if (token == null) { 3945 if (token == null) {
3917 return false; 3946 return false;
3918 } 3947 }
3919 TokenType type = token.type; 3948 TokenType type = token.type;
3920 return type == TokenType.EQ || 3949 return type == TokenType.EQ ||
3921 type == TokenType.COMMA || 3950 type == TokenType.COMMA ||
3922 type == TokenType.SEMICOLON || 3951 type == TokenType.SEMICOLON ||
3923 _tokenMatchesKeyword(token, Keyword.IN); 3952 _tokenMatchesKeyword(token, Keyword.IN);
3924 } 3953 }
3925 3954
3955 bool _isLikelyParameterList() {
3956 if (_matches(TokenType.OPEN_PAREN)) {
3957 return true;
3958 }
3959 if (!parseGenericMethods) {
3960 return false;
3961 }
3962 Token token = _skipTypeArgumentList(_currentToken);
3963 return token != null && _tokenMatches(token, TokenType.OPEN_PAREN);
3964 }
3965
3926 /** 3966 /**
3927 * Given that we have just found bracketed text within the given [comment], 3967 * Given that we have just found bracketed text within the given [comment],
3928 * look to see whether that text is (a) followed by a parenthesized link 3968 * look to see whether that text is (a) followed by a parenthesized link
3929 * address, (b) followed by a colon, or (c) followed by optional whitespace 3969 * address, (b) followed by a colon, or (c) followed by optional whitespace
3930 * and another square bracket. The [rightIndex] is the index of the right 3970 * and another square bracket. The [rightIndex] is the index of the right
3931 * bracket. Return `true` if the bracketed text is followed by a link address. 3971 * bracket. Return `true` if the bracketed text is followed by a link address.
3932 * 3972 *
3933 * This method uses the syntax described by the 3973 * This method uses the syntax described by the
3934 * <a href="http://daringfireball.net/projects/markdown/syntax">markdown</a> 3974 * <a href="http://daringfireball.net/projects/markdown/syntax">markdown</a>
3935 * project. 3975 * project.
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
4004 } else if (_tokenMatchesIdentifier(token)) { 4044 } else if (_tokenMatchesIdentifier(token)) {
4005 return true; 4045 return true;
4006 } else if (_tokenMatchesKeyword(token, Keyword.THIS) && 4046 } else if (_tokenMatchesKeyword(token, Keyword.THIS) &&
4007 _tokenMatches(token.next, TokenType.PERIOD) && 4047 _tokenMatches(token.next, TokenType.PERIOD) &&
4008 _tokenMatchesIdentifier(token.next.next)) { 4048 _tokenMatchesIdentifier(token.next.next)) {
4009 return true; 4049 return true;
4010 } else if (_tokenMatchesKeyword(startToken, Keyword.VOID)) { 4050 } else if (_tokenMatchesKeyword(startToken, Keyword.VOID)) {
4011 // The keyword 'void' isn't a valid identifier, so it should be assumed to 4051 // The keyword 'void' isn't a valid identifier, so it should be assumed to
4012 // be a type name. 4052 // be a type name.
4013 return true; 4053 return true;
4014 } else if (startToken.next != token) { 4054 } else if (startToken.next != token &&
4055 !_tokenMatches(token, TokenType.OPEN_PAREN)) {
4015 // The type is more than a simple identifier, so it should be assumed to 4056 // The type is more than a simple identifier, so it should be assumed to
4016 // be a type name. 4057 // be a type name.
4017 return true; 4058 return true;
4018 } 4059 }
4019 return false; 4060 return false;
4020 } 4061 }
4021 4062
4022 /** 4063 /**
4023 * Increments the error reporting lock level. If level is more than `0`, then 4064 * Increments the error reporting lock level. If level is more than `0`, then
4024 * [reportError] wont report any error. 4065 * [reportError] wont report any error.
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
4177 new SuperExpression(getAndAdvance()), false, allowConditional: false); 4218 new SuperExpression(getAndAdvance()), false, allowConditional: false);
4178 } 4219 }
4179 // 4220 //
4180 // A primary expression can start with an identifier. We resolve the 4221 // A primary expression can start with an identifier. We resolve the
4181 // ambiguity by determining whether the primary consists of anything other 4222 // ambiguity by determining whether the primary consists of anything other
4182 // than an identifier and/or is followed by an assignableSelector. 4223 // than an identifier and/or is followed by an assignableSelector.
4183 // 4224 //
4184 Expression expression = _parsePrimaryExpression(); 4225 Expression expression = _parsePrimaryExpression();
4185 bool isOptional = primaryAllowed || expression is SimpleIdentifier; 4226 bool isOptional = primaryAllowed || expression is SimpleIdentifier;
4186 while (true) { 4227 while (true) {
4187 while (_matches(TokenType.OPEN_PAREN)) { 4228 while (_isLikelyParameterList()) {
4229 TypeArgumentList typeArguments = null;
4230 if (_matches(TokenType.LT)) {
4231 typeArguments = parseTypeArgumentList();
4232 }
4188 ArgumentList argumentList = parseArgumentList(); 4233 ArgumentList argumentList = parseArgumentList();
4189 if (expression is SimpleIdentifier) { 4234 if (expression is SimpleIdentifier) {
4190 expression = new MethodInvocation( 4235 expression = new MethodInvocation(null, null,
4191 null, null, expression as SimpleIdentifier, null, argumentList); 4236 expression as SimpleIdentifier, typeArguments, argumentList);
4192 } else if (expression is PrefixedIdentifier) { 4237 } else if (expression is PrefixedIdentifier) {
4193 PrefixedIdentifier identifier = expression as PrefixedIdentifier; 4238 PrefixedIdentifier identifier = expression as PrefixedIdentifier;
4194 expression = new MethodInvocation(identifier.prefix, 4239 expression = new MethodInvocation(identifier.prefix,
4195 identifier.period, identifier.identifier, null, argumentList); 4240 identifier.period, identifier.identifier, typeArguments,
4241 argumentList);
4196 } else if (expression is PropertyAccess) { 4242 } else if (expression is PropertyAccess) {
4197 PropertyAccess access = expression as PropertyAccess; 4243 PropertyAccess access = expression as PropertyAccess;
4198 expression = new MethodInvocation(access.target, access.operator, 4244 expression = new MethodInvocation(access.target, access.operator,
4199 access.propertyName, null, argumentList); 4245 access.propertyName, typeArguments, argumentList);
4200 } else { 4246 } else {
4201 expression = 4247 expression = new FunctionExpressionInvocation(
4202 new FunctionExpressionInvocation(expression, null, argumentList); 4248 expression, typeArguments, argumentList);
4203 } 4249 }
4204 if (!primaryAllowed) { 4250 if (!primaryAllowed) {
4205 isOptional = false; 4251 isOptional = false;
4206 } 4252 }
4207 } 4253 }
4208 Expression selectorExpression = _parseAssignableSelector( 4254 Expression selectorExpression = _parseAssignableSelector(
4209 expression, isOptional || (expression is PrefixedIdentifier)); 4255 expression, isOptional || (expression is PrefixedIdentifier));
4210 if (identical(selectorExpression, expression)) { 4256 if (identical(selectorExpression, expression)) {
4211 if (!isOptional && (expression is PrefixedIdentifier)) { 4257 if (!isOptional && (expression is PrefixedIdentifier)) {
4212 PrefixedIdentifier identifier = expression as PrefixedIdentifier; 4258 PrefixedIdentifier identifier = expression as PrefixedIdentifier;
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
4344 } 4390 }
4345 Token semicolon = _expect(TokenType.SEMICOLON); 4391 Token semicolon = _expect(TokenType.SEMICOLON);
4346 return new BreakStatement(breakKeyword, label, semicolon); 4392 return new BreakStatement(breakKeyword, label, semicolon);
4347 } 4393 }
4348 4394
4349 /** 4395 /**
4350 * Parse a cascade section. Return the expression representing the cascaded 4396 * Parse a cascade section. Return the expression representing the cascaded
4351 * method invocation. 4397 * method invocation.
4352 * 4398 *
4353 * cascadeSection ::= 4399 * cascadeSection ::=
4354 * '..' (cascadeSelector arguments*) (assignableSelector arguments*)* cascadeAssignment? 4400 * '..' (cascadeSelector typeArguments? arguments*)
4401 * (assignableSelector typeArguments? arguments*)* cascadeAssignment?
4355 * 4402 *
4356 * cascadeSelector ::= 4403 * cascadeSelector ::=
4357 * '[' expression ']' 4404 * '[' expression ']'
4358 * | identifier 4405 * | identifier
4359 * 4406 *
4360 * cascadeAssignment ::= 4407 * cascadeAssignment ::=
4361 * assignmentOperator expressionWithoutCascade 4408 * assignmentOperator expressionWithoutCascade
4362 */ 4409 */
4363 Expression _parseCascadeSection() { 4410 Expression _parseCascadeSection() {
4364 Token period = _expect(TokenType.PERIOD_PERIOD); 4411 Token period = _expect(TokenType.PERIOD_PERIOD);
(...skipping 14 matching lines...) Expand all
4379 } finally { 4426 } finally {
4380 _inInitializer = wasInInitializer; 4427 _inInitializer = wasInInitializer;
4381 } 4428 }
4382 } else { 4429 } else {
4383 _reportErrorForToken(ParserErrorCode.MISSING_IDENTIFIER, _currentToken, 4430 _reportErrorForToken(ParserErrorCode.MISSING_IDENTIFIER, _currentToken,
4384 [_currentToken.lexeme]); 4431 [_currentToken.lexeme]);
4385 functionName = _createSyntheticIdentifier(); 4432 functionName = _createSyntheticIdentifier();
4386 } 4433 }
4387 assert((expression == null && functionName != null) || 4434 assert((expression == null && functionName != null) ||
4388 (expression != null && functionName == null)); 4435 (expression != null && functionName == null));
4389 if (_currentToken.type == TokenType.OPEN_PAREN) { 4436 if (_isLikelyParameterList()) {
4390 while (_currentToken.type == TokenType.OPEN_PAREN) { 4437 while (_isLikelyParameterList()) {
4438 TypeArgumentList typeArguments = null;
4439 if (_matches(TokenType.LT)) {
4440 typeArguments = parseTypeArgumentList();
4441 }
4391 if (functionName != null) { 4442 if (functionName != null) {
4392 expression = new MethodInvocation( 4443 expression = new MethodInvocation(expression, period, functionName,
4393 expression, period, functionName, null, parseArgumentList()); 4444 typeArguments, parseArgumentList());
4394 period = null; 4445 period = null;
4395 functionName = null; 4446 functionName = null;
4396 } else if (expression == null) { 4447 } else if (expression == null) {
4397 // It should not be possible to get here. 4448 // It should not be possible to get here.
4398 expression = new MethodInvocation(expression, period, 4449 expression = new MethodInvocation(expression, period,
4399 _createSyntheticIdentifier(), null, parseArgumentList()); 4450 _createSyntheticIdentifier(), typeArguments, parseArgumentList());
4400 } else { 4451 } else {
4401 expression = new FunctionExpressionInvocation( 4452 expression = new FunctionExpressionInvocation(
4402 expression, null, parseArgumentList()); 4453 expression, typeArguments, parseArgumentList());
4403 } 4454 }
4404 } 4455 }
4405 } else if (functionName != null) { 4456 } else if (functionName != null) {
4406 expression = new PropertyAccess(expression, period, functionName); 4457 expression = new PropertyAccess(expression, period, functionName);
4407 period = null; 4458 period = null;
4408 } 4459 }
4409 assert(expression != null); 4460 assert(expression != null);
4410 bool progress = true; 4461 bool progress = true;
4411 while (progress) { 4462 while (progress) {
4412 progress = false; 4463 progress = false;
4413 Expression selector = _parseAssignableSelector(expression, true); 4464 Expression selector = _parseAssignableSelector(expression, true);
4414 if (!identical(selector, expression)) { 4465 if (!identical(selector, expression)) {
4415 expression = selector; 4466 expression = selector;
4416 progress = true; 4467 progress = true;
4417 while (_currentToken.type == TokenType.OPEN_PAREN) { 4468 while (_isLikelyParameterList()) {
4469 TypeArgumentList typeArguments = null;
4470 if (_matches(TokenType.LT)) {
4471 typeArguments = parseTypeArgumentList();
4472 }
4418 if (expression is PropertyAccess) { 4473 if (expression is PropertyAccess) {
4419 PropertyAccess propertyAccess = expression as PropertyAccess; 4474 PropertyAccess propertyAccess = expression as PropertyAccess;
4420 expression = new MethodInvocation(propertyAccess.target, 4475 expression = new MethodInvocation(propertyAccess.target,
4421 propertyAccess.operator, propertyAccess.propertyName, null, 4476 propertyAccess.operator, propertyAccess.propertyName,
4422 parseArgumentList()); 4477 typeArguments, parseArgumentList());
4423 } else { 4478 } else {
4424 expression = new FunctionExpressionInvocation( 4479 expression = new FunctionExpressionInvocation(
4425 expression, null, parseArgumentList()); 4480 expression, typeArguments, parseArgumentList());
4426 } 4481 }
4427 } 4482 }
4428 } 4483 }
4429 } 4484 }
4430 if (_currentToken.type.isAssignmentOperator) { 4485 if (_currentToken.type.isAssignmentOperator) {
4431 Token operator = getAndAdvance(); 4486 Token operator = getAndAdvance();
4432 _ensureAssignable(expression); 4487 _ensureAssignable(expression);
4433 expression = new AssignmentExpression( 4488 expression = new AssignmentExpression(
4434 expression, operator, parseExpressionWithoutCascade()); 4489 expression, operator, parseExpressionWithoutCascade());
4435 } 4490 }
(...skipping 1315 matching lines...) Expand 10 before | Expand all | Expand 10 after
5751 bool isGetter = false; 5806 bool isGetter = false;
5752 if (_matchesKeyword(Keyword.GET) && 5807 if (_matchesKeyword(Keyword.GET) &&
5753 !_tokenMatches(_peek(), TokenType.OPEN_PAREN)) { 5808 !_tokenMatches(_peek(), TokenType.OPEN_PAREN)) {
5754 keyword = getAndAdvance(); 5809 keyword = getAndAdvance();
5755 isGetter = true; 5810 isGetter = true;
5756 } else if (_matchesKeyword(Keyword.SET) && 5811 } else if (_matchesKeyword(Keyword.SET) &&
5757 !_tokenMatches(_peek(), TokenType.OPEN_PAREN)) { 5812 !_tokenMatches(_peek(), TokenType.OPEN_PAREN)) {
5758 keyword = getAndAdvance(); 5813 keyword = getAndAdvance();
5759 } 5814 }
5760 SimpleIdentifier name = parseSimpleIdentifier(); 5815 SimpleIdentifier name = parseSimpleIdentifier();
5816 TypeParameterList typeParameters = null;
5817 if (parseGenericMethods && _matches(TokenType.LT)) {
5818 typeParameters = parseTypeParameterList();
5819 }
5761 FormalParameterList parameters = null; 5820 FormalParameterList parameters = null;
5762 if (!isGetter) { 5821 if (!isGetter) {
5763 if (_matches(TokenType.OPEN_PAREN)) { 5822 if (_matches(TokenType.OPEN_PAREN)) {
5764 parameters = parseFormalParameterList(); 5823 parameters = parseFormalParameterList();
5765 _validateFormalParameterList(parameters); 5824 _validateFormalParameterList(parameters);
5766 } else { 5825 } else {
5767 _reportErrorForCurrentToken( 5826 _reportErrorForCurrentToken(
5768 ParserErrorCode.MISSING_FUNCTION_PARAMETERS); 5827 ParserErrorCode.MISSING_FUNCTION_PARAMETERS);
5769 parameters = new FormalParameterList( 5828 parameters = new FormalParameterList(
5770 _createSyntheticToken(TokenType.OPEN_PAREN), null, null, null, 5829 _createSyntheticToken(TokenType.OPEN_PAREN), null, null, null,
(...skipping 10 matching lines...) Expand all
5781 } else { 5840 } else {
5782 body = new EmptyFunctionBody(_expect(TokenType.SEMICOLON)); 5841 body = new EmptyFunctionBody(_expect(TokenType.SEMICOLON));
5783 } 5842 }
5784 // if (!isStatement && matches(TokenType.SEMICOLON)) { 5843 // if (!isStatement && matches(TokenType.SEMICOLON)) {
5785 // // TODO(brianwilkerson) Improve this error message. 5844 // // TODO(brianwilkerson) Improve this error message.
5786 // reportError(ParserErrorCode.UNEXPECTED_TOKEN, currentToken.getLexeme ()); 5845 // reportError(ParserErrorCode.UNEXPECTED_TOKEN, currentToken.getLexeme ());
5787 // advance(); 5846 // advance();
5788 // } 5847 // }
5789 return new FunctionDeclaration(commentAndMetadata.comment, 5848 return new FunctionDeclaration(commentAndMetadata.comment,
5790 commentAndMetadata.metadata, externalKeyword, returnType, keyword, name, 5849 commentAndMetadata.metadata, externalKeyword, returnType, keyword, name,
5791 new FunctionExpression(null, parameters, body)); 5850 new FunctionExpression(typeParameters, parameters, body));
5792 } 5851 }
5793 5852
5794 /** 5853 /**
5795 * Parse a function declaration statement. Return the function declaration 5854 * Parse a function declaration statement. Return the function declaration
5796 * statement that was parsed. 5855 * statement that was parsed.
5797 * 5856 *
5798 * functionDeclarationStatement ::= 5857 * functionDeclarationStatement ::=
5799 * functionSignature functionBody 5858 * functionSignature functionBody
5800 */ 5859 */
5801 Statement _parseFunctionDeclarationStatement() { 5860 Statement _parseFunctionDeclarationStatement() {
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
6263 * parsed. 6322 * parsed.
6264 * 6323 *
6265 * functionDeclaration ::= 6324 * functionDeclaration ::=
6266 * 'external'? 'static'? functionSignature functionBody 6325 * 'external'? 'static'? functionSignature functionBody
6267 * | 'external'? functionSignature ';' 6326 * | 'external'? functionSignature ';'
6268 */ 6327 */
6269 MethodDeclaration _parseMethodDeclarationAfterReturnType( 6328 MethodDeclaration _parseMethodDeclarationAfterReturnType(
6270 CommentAndMetadata commentAndMetadata, Token externalKeyword, 6329 CommentAndMetadata commentAndMetadata, Token externalKeyword,
6271 Token staticKeyword, TypeName returnType) { 6330 Token staticKeyword, TypeName returnType) {
6272 SimpleIdentifier methodName = parseSimpleIdentifier(); 6331 SimpleIdentifier methodName = parseSimpleIdentifier();
6332 TypeParameterList typeParameters = null;
6333 if (parseGenericMethods && _matches(TokenType.LT)) {
6334 typeParameters = parseTypeParameterList();
6335 }
6273 FormalParameterList parameters; 6336 FormalParameterList parameters;
6274 if (!_matches(TokenType.OPEN_PAREN) && 6337 if (!_matches(TokenType.OPEN_PAREN) &&
6275 (_matches(TokenType.OPEN_CURLY_BRACKET) || 6338 (_matches(TokenType.OPEN_CURLY_BRACKET) ||
6276 _matches(TokenType.FUNCTION))) { 6339 _matches(TokenType.FUNCTION))) {
6277 _reportErrorForToken( 6340 _reportErrorForToken(
6278 ParserErrorCode.MISSING_METHOD_PARAMETERS, _currentToken.previous); 6341 ParserErrorCode.MISSING_METHOD_PARAMETERS, _currentToken.previous);
6279 parameters = new FormalParameterList( 6342 parameters = new FormalParameterList(
6280 _createSyntheticToken(TokenType.OPEN_PAREN), null, null, null, 6343 _createSyntheticToken(TokenType.OPEN_PAREN), null, null, null,
6281 _createSyntheticToken(TokenType.CLOSE_PAREN)); 6344 _createSyntheticToken(TokenType.CLOSE_PAREN));
6282 } else { 6345 } else {
6283 parameters = parseFormalParameterList(); 6346 parameters = parseFormalParameterList();
6284 } 6347 }
6285 _validateFormalParameterList(parameters); 6348 _validateFormalParameterList(parameters);
6286 return _parseMethodDeclarationAfterParameters(commentAndMetadata, 6349 return _parseMethodDeclarationAfterParameters(commentAndMetadata,
6287 externalKeyword, staticKeyword, returnType, methodName, null, 6350 externalKeyword, staticKeyword, returnType, methodName, typeParameters,
6288 parameters); 6351 parameters);
6289 } 6352 }
6290 6353
6291 /** 6354 /**
6292 * Parse the modifiers preceding a declaration. This method allows the 6355 * Parse the modifiers preceding a declaration. This method allows the
6293 * modifiers to appear in any order but does generate errors for duplicated 6356 * modifiers to appear in any order but does generate errors for duplicated
6294 * modifiers. Checks for other problems, such as having the modifiers appear 6357 * modifiers. Checks for other problems, such as having the modifiers appear
6295 * in the wrong order or specifying both 'const' and 'final', are reported in 6358 * in the wrong order or specifying both 'const' and 'final', are reported in
6296 * one of the methods whose name is prefixed with `validateModifiersFor`. 6359 * one of the methods whose name is prefixed with `validateModifiersFor`.
6297 * Return the modifiers that were parsed. 6360 * Return the modifiers that were parsed.
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
6705 * 6768 *
6706 * selector ::= 6769 * selector ::=
6707 * assignableSelector 6770 * assignableSelector
6708 * | argumentList 6771 * | argumentList
6709 */ 6772 */
6710 Expression _parsePostfixExpression() { 6773 Expression _parsePostfixExpression() {
6711 Expression operand = _parseAssignableExpression(true); 6774 Expression operand = _parseAssignableExpression(true);
6712 if (_matches(TokenType.OPEN_SQUARE_BRACKET) || 6775 if (_matches(TokenType.OPEN_SQUARE_BRACKET) ||
6713 _matches(TokenType.PERIOD) || 6776 _matches(TokenType.PERIOD) ||
6714 _matches(TokenType.QUESTION_PERIOD) || 6777 _matches(TokenType.QUESTION_PERIOD) ||
6715 _matches(TokenType.OPEN_PAREN)) { 6778 _matches(TokenType.OPEN_PAREN) ||
6779 (parseGenericMethods && _matches(TokenType.LT))) {
6716 do { 6780 do {
6717 if (_matches(TokenType.OPEN_PAREN)) { 6781 if (_isLikelyParameterList()) {
6782 TypeArgumentList typeArguments = null;
6783 if (_matches(TokenType.LT)) {
6784 typeArguments = parseTypeArgumentList();
6785 }
6718 ArgumentList argumentList = parseArgumentList(); 6786 ArgumentList argumentList = parseArgumentList();
6719 if (operand is PropertyAccess) { 6787 if (operand is PropertyAccess) {
6720 PropertyAccess access = operand as PropertyAccess; 6788 PropertyAccess access = operand as PropertyAccess;
6721 operand = new MethodInvocation(access.target, access.operator, 6789 operand = new MethodInvocation(access.target, access.operator,
6722 access.propertyName, null, argumentList); 6790 access.propertyName, typeArguments, argumentList);
6723 } else { 6791 } else {
6724 operand = 6792 operand = new FunctionExpressionInvocation(
6725 new FunctionExpressionInvocation(operand, null, argumentList); 6793 operand, typeArguments, argumentList);
6726 } 6794 }
6727 } else { 6795 } else {
6728 operand = _parseAssignableSelector(operand, true); 6796 operand = _parseAssignableSelector(operand, true);
6729 } 6797 }
6730 } while (_matches(TokenType.OPEN_SQUARE_BRACKET) || 6798 } while (_matches(TokenType.OPEN_SQUARE_BRACKET) ||
6731 _matches(TokenType.PERIOD) || 6799 _matches(TokenType.PERIOD) ||
6732 _matches(TokenType.QUESTION_PERIOD) || 6800 _matches(TokenType.QUESTION_PERIOD) ||
6733 _matches(TokenType.OPEN_PAREN)); 6801 _matches(TokenType.OPEN_PAREN));
6734 return operand; 6802 return operand;
6735 } 6803 }
(...skipping 3860 matching lines...) Expand 10 before | Expand all | Expand 10 after
10596 } 10664 }
10597 10665
10598 /** 10666 /**
10599 * Copy resolution data from the [fromNode] to the [toNode]. 10667 * Copy resolution data from the [fromNode] to the [toNode].
10600 */ 10668 */
10601 static void copyResolutionData(AstNode fromNode, AstNode toNode) { 10669 static void copyResolutionData(AstNode fromNode, AstNode toNode) {
10602 ResolutionCopier copier = new ResolutionCopier(); 10670 ResolutionCopier copier = new ResolutionCopier();
10603 copier._isEqualNodes(fromNode, toNode); 10671 copier._isEqualNodes(fromNode, toNode);
10604 } 10672 }
10605 } 10673 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/parser_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698