OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library analyzer.src.generated.parser; | 5 library analyzer.src.generated.parser; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 import "dart:math" as math; | 8 import "dart:math" as math; |
9 | 9 |
10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
(...skipping 3943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3954 | 3954 |
3955 /** | 3955 /** |
3956 * Parse a normal formal parameter. Return the normal formal parameter that | 3956 * Parse a normal formal parameter. Return the normal formal parameter that |
3957 * was parsed. | 3957 * was parsed. |
3958 * | 3958 * |
3959 * normalFormalParameter ::= | 3959 * normalFormalParameter ::= |
3960 * functionSignature | 3960 * functionSignature |
3961 * | fieldFormalParameter | 3961 * | fieldFormalParameter |
3962 * | simpleFormalParameter | 3962 * | simpleFormalParameter |
3963 * | 3963 * |
3964 * functionSignature: | 3964 * legacyFunctionSignature: |
3965 * metadata returnType? identifier typeParameters? formalParameterList | 3965 * metadata returnType? identifier typeParameters? formalParameterList |
3966 * | 3966 * |
3967 * fieldFormalParameter ::= | 3967 * fieldFormalParameter ::= |
3968 * metadata finalConstVarOrType? 'this' '.' identifier | 3968 * metadata finalConstVarOrType? 'this' '.' identifier |
3969 * | 3969 * |
3970 * simpleFormalParameter ::= | 3970 * simpleFormalParameter ::= |
3971 * declaredIdentifier | 3971 * declaredIdentifier |
3972 * | metadata identifier | 3972 * | metadata identifier |
3973 */ | 3973 */ |
3974 NormalFormalParameter parseNormalFormalParameter() { | 3974 NormalFormalParameter parseNormalFormalParameter() { |
(...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4815 * classTypeAlias | 4815 * classTypeAlias |
4816 * | functionTypeAlias | 4816 * | functionTypeAlias |
4817 * | 4817 * |
4818 * classTypeAlias ::= | 4818 * classTypeAlias ::= |
4819 * identifier typeParameters? '=' 'abstract'? mixinApplication | 4819 * identifier typeParameters? '=' 'abstract'? mixinApplication |
4820 * | 4820 * |
4821 * mixinApplication ::= | 4821 * mixinApplication ::= |
4822 * qualified withClause implementsClause? ';' | 4822 * qualified withClause implementsClause? ';' |
4823 * | 4823 * |
4824 * functionTypeAlias ::= | 4824 * functionTypeAlias ::= |
| 4825 * legacyFunctionTypeAlias | |
| 4826 * newFunctionTypeAlias |
| 4827 * |
| 4828 * legacyFunctionTypeAlias ::= |
4825 * functionPrefix typeParameterList? formalParameterList ';' | 4829 * functionPrefix typeParameterList? formalParameterList ';' |
4826 * | 4830 * |
4827 * functionPrefix ::= | 4831 * functionPrefix ::= |
4828 * returnType? name | 4832 * returnType? name |
| 4833 * |
| 4834 * newFunctionTypeAlias ::= |
| 4835 * identifier typeParameters? '=' functionType ';' |
| 4836 * |
| 4837 * functionType ::= typeParameterList? formalParameterList '-' '>' returnT
ype |
| 4838 * |
4829 */ | 4839 */ |
4830 TypeAlias parseTypeAlias(CommentAndMetadata commentAndMetadata) { | 4840 TypeAlias parseTypeAlias(CommentAndMetadata commentAndMetadata) { |
4831 Token keyword = getAndAdvance(); | 4841 Token keyword = getAndAdvance(); |
4832 if (_matchesIdentifier()) { | 4842 if (_matchesIdentifier()) { |
4833 Token next = _peek(); | 4843 Token next = _peek(); |
4834 if (_tokenMatches(next, TokenType.LT)) { | 4844 if (_tokenMatches(next, TokenType.LT)) { |
4835 next = _skipTypeParameterList(next); | 4845 next = _skipTypeParameterList(next); |
4836 if (next != null && _tokenMatches(next, TokenType.EQ)) { | 4846 if (next != null && _tokenMatches(next, TokenType.EQ)) { |
| 4847 next = next.next; |
| 4848 if (next != null && |
| 4849 (_tokenMatches(next, TokenType.LT) || |
| 4850 _tokenMatches(next, TokenType.OPEN_PAREN))) { |
| 4851 return _parseNewFunctionTypeAlias(commentAndMetadata, keyword); |
| 4852 } |
| 4853 if (next != null && _tokenMatches(next, TokenType.IDENTIFIER)) { |
| 4854 next = next.next; |
| 4855 if (next != null && _tokenMatches(next, TokenType.MINUS)) { |
| 4856 return _parseNewFunctionTypeAlias(commentAndMetadata, keyword); |
| 4857 } |
| 4858 } |
4837 TypeAlias typeAlias = | 4859 TypeAlias typeAlias = |
4838 parseClassTypeAlias(commentAndMetadata, null, keyword); | 4860 parseClassTypeAlias(commentAndMetadata, null, keyword); |
4839 _reportErrorForToken( | 4861 _reportErrorForToken( |
4840 ParserErrorCode.DEPRECATED_CLASS_TYPE_ALIAS, keyword); | 4862 ParserErrorCode.DEPRECATED_CLASS_TYPE_ALIAS, keyword); |
4841 return typeAlias; | 4863 return typeAlias; |
4842 } | 4864 } |
4843 } else if (_tokenMatches(next, TokenType.EQ)) { | 4865 } else if (_tokenMatches(next, TokenType.EQ)) { |
| 4866 next = next.next; |
| 4867 if (next != null && |
| 4868 (_tokenMatches(next, TokenType.LT) || |
| 4869 _tokenMatches(next, TokenType.OPEN_PAREN))) { |
| 4870 return _parseNewFunctionTypeAlias(commentAndMetadata, keyword); |
| 4871 } else if (next != null && _tokenMatches(next, TokenType.IDENTIFIER)) { |
| 4872 next = next.next; |
| 4873 if (next != null && _tokenMatches(next, TokenType.MINUS)) { |
| 4874 return _parseNewFunctionTypeAlias(commentAndMetadata, keyword); |
| 4875 } |
| 4876 } |
4844 TypeAlias typeAlias = | 4877 TypeAlias typeAlias = |
4845 parseClassTypeAlias(commentAndMetadata, null, keyword); | 4878 parseClassTypeAlias(commentAndMetadata, null, keyword); |
4846 _reportErrorForToken( | 4879 _reportErrorForToken( |
4847 ParserErrorCode.DEPRECATED_CLASS_TYPE_ALIAS, keyword); | 4880 ParserErrorCode.DEPRECATED_CLASS_TYPE_ALIAS, keyword); |
4848 return typeAlias; | 4881 return typeAlias; |
4849 } | 4882 } |
4850 } | 4883 } |
4851 return _parseFunctionTypeAlias(commentAndMetadata, keyword); | 4884 return _parseFunctionTypeAlias(commentAndMetadata, keyword); |
4852 } | 4885 } |
4853 | 4886 |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5314 * a type name or changing the current token. Return the token following the | 5347 * a type name or changing the current token. Return the token following the |
5315 * type name that was parsed, or `null` if the given token is not the first | 5348 * type name that was parsed, or `null` if the given token is not the first |
5316 * token in a valid type name. | 5349 * token in a valid type name. |
5317 * | 5350 * |
5318 * This method must be kept in sync with [parseTypeName]. | 5351 * This method must be kept in sync with [parseTypeName]. |
5319 * | 5352 * |
5320 * type ::= | 5353 * type ::= |
5321 * qualified typeArguments? | 5354 * qualified typeArguments? |
5322 */ | 5355 */ |
5323 Token skipTypeName(Token startToken) { | 5356 Token skipTypeName(Token startToken) { |
5324 Token token = skipPrefixedIdentifier(startToken); | 5357 Token token; |
| 5358 if (_tokenMatches(startToken, TokenType.LT)) { |
| 5359 token = skipTypeArgumentList(token); |
| 5360 if (token == null) return null; |
| 5361 token = _skipFormalParameterList(token); |
| 5362 if (token == null) return null; |
| 5363 if (!_tokenMatches(token, TokenType.MINUS)) return null; |
| 5364 token = token.next; |
| 5365 if (token == null) return null; |
| 5366 if (!_tokenMatches(token, TokenType.GT)) return null; |
| 5367 return skipTypeName(token); |
| 5368 } |
| 5369 |
| 5370 token = skipPrefixedIdentifier(startToken); |
5325 if (token == null) { | 5371 if (token == null) { |
5326 return null; | 5372 return null; |
5327 } | 5373 } |
5328 if (_tokenMatches(token, TokenType.LT)) { | 5374 if (_tokenMatches(token, TokenType.LT)) { |
5329 token = skipTypeArgumentList(token); | 5375 token = skipTypeArgumentList(token); |
5330 } | 5376 } |
5331 return token; | 5377 return token; |
5332 } | 5378 } |
5333 | 5379 |
5334 /** | 5380 /** |
(...skipping 1175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6510 _reportErrorForToken( | 6556 _reportErrorForToken( |
6511 ParserErrorCode.GETTER_IN_FUNCTION, propertyKeyword); | 6557 ParserErrorCode.GETTER_IN_FUNCTION, propertyKeyword); |
6512 } else { | 6558 } else { |
6513 _reportErrorForToken( | 6559 _reportErrorForToken( |
6514 ParserErrorCode.SETTER_IN_FUNCTION, propertyKeyword); | 6560 ParserErrorCode.SETTER_IN_FUNCTION, propertyKeyword); |
6515 } | 6561 } |
6516 } | 6562 } |
6517 return new FunctionDeclarationStatement(declaration); | 6563 return new FunctionDeclarationStatement(declaration); |
6518 } | 6564 } |
6519 | 6565 |
| 6566 FunctionTypeAlias _parseNewFunctionTypeAlias(CommentAndMetadata commentAndMeta
data, Token keyword) { |
| 6567 SimpleIdentifier name = parseSimpleIdentifier(isDeclaration: true); |
| 6568 TypeParameterList typeParameters = null; |
| 6569 if (_matches(TokenType.LT)) { |
| 6570 typeParameters = parseTypeParameterList(); |
| 6571 } |
| 6572 |
| 6573 _expect(TokenType.EQ); // TODO(floitsch): store the sign in the node. |
| 6574 |
| 6575 if (_matches(TokenType.LT)) { |
| 6576 parseTypeParameterList(); // TODO(floitsch): store the generic arguments. |
| 6577 } |
| 6578 |
| 6579 |
| 6580 TokenType type = _currentToken.type; |
| 6581 |
| 6582 if (type == TokenType.OPEN_PAREN || type == TokenType.IDENTIFIER) { |
| 6583 FormalParameterList parameters; |
| 6584 if (type == TokenType.OPEN_PAREN) { |
| 6585 parameters = _parseFormalParameterListUnchecked(); |
| 6586 } else { |
| 6587 var parameter = parseNormalFormalParameter(); |
| 6588 parameters = new FormalParameterList( |
| 6589 _createSyntheticToken(TokenType.OPEN_PAREN), |
| 6590 [parameter], null, null, |
| 6591 _createSyntheticToken(TokenType.CLOSE_PAREN)); |
| 6592 } |
| 6593 _validateFormalParameterList(parameters); |
| 6594 |
| 6595 _expect(TokenType.MINUS); |
| 6596 _expect(TokenType.GT); |
| 6597 |
| 6598 TypeName returnType = parseReturnType(); |
| 6599 |
| 6600 Token semicolon = _expect(TokenType.SEMICOLON); |
| 6601 return new FunctionTypeAlias( |
| 6602 commentAndMetadata.comment, |
| 6603 commentAndMetadata.metadata, |
| 6604 keyword, |
| 6605 returnType, |
| 6606 name, |
| 6607 typeParameters, |
| 6608 parameters, |
| 6609 semicolon); |
| 6610 } else { |
| 6611 _reportErrorForCurrentToken(ParserErrorCode.MISSING_TYPEDEF_PARAMETERS); |
| 6612 // Recovery: At the very least we should skip to the start of the next |
| 6613 // valid compilation unit member, allowing for the possibility of finding |
| 6614 // the typedef parameters before that point. |
| 6615 return new FunctionTypeAlias( |
| 6616 commentAndMetadata.comment, |
| 6617 commentAndMetadata.metadata, |
| 6618 keyword, |
| 6619 null, |
| 6620 name, |
| 6621 typeParameters, |
| 6622 new FormalParameterList(_createSyntheticToken(TokenType.OPEN_PAREN), |
| 6623 null, null, null, _createSyntheticToken(TokenType.CLOSE_PAREN)), |
| 6624 _createSyntheticToken(TokenType.SEMICOLON)); |
| 6625 } |
| 6626 } |
| 6627 |
6520 /** | 6628 /** |
6521 * Parse a function type alias. The [commentAndMetadata] is the metadata to be | 6629 * Parse a function type alias. The [commentAndMetadata] is the metadata to be |
6522 * associated with the member. The [keyword] is the token representing the | 6630 * associated with the member. The [keyword] is the token representing the |
6523 * 'typedef' keyword. Return the function type alias that was parsed. | 6631 * 'typedef' keyword. Return the function type alias that was parsed. |
6524 * | 6632 * |
6525 * functionTypeAlias ::= | 6633 * functionTypeAlias ::= |
6526 * functionPrefix typeParameterList? formalParameterList ';' | 6634 * functionPrefix typeParameterList? formalParameterList ';' |
6527 * | 6635 * |
6528 * functionPrefix ::= | 6636 * functionPrefix ::= |
6529 * returnType? name | 6637 * returnType? name |
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7224 } | 7332 } |
7225 _errorListener.onError(error); | 7333 _errorListener.onError(error); |
7226 } | 7334 } |
7227 | 7335 |
7228 /** | 7336 /** |
7229 * Report an error with the given [errorCode] and [arguments] associated with | 7337 * Report an error with the given [errorCode] and [arguments] associated with |
7230 * the current token. | 7338 * the current token. |
7231 */ | 7339 */ |
7232 void _reportErrorForCurrentToken(ParserErrorCode errorCode, | 7340 void _reportErrorForCurrentToken(ParserErrorCode errorCode, |
7233 [List<Object> arguments]) { | 7341 [List<Object> arguments]) { |
| 7342 print("error ${StackTrace.current}"); |
7234 _reportErrorForToken(errorCode, _currentToken, arguments); | 7343 _reportErrorForToken(errorCode, _currentToken, arguments); |
7235 } | 7344 } |
7236 | 7345 |
7237 /** | 7346 /** |
7238 * Report an error with the given [errorCode] and [arguments] associated with | 7347 * Report an error with the given [errorCode] and [arguments] associated with |
7239 * the given [node]. | 7348 * the given [node]. |
7240 */ | 7349 */ |
7241 void _reportErrorForNode(ParserErrorCode errorCode, AstNode node, | 7350 void _reportErrorForNode(ParserErrorCode errorCode, AstNode node, |
7242 [List<Object> arguments]) { | 7351 [List<Object> arguments]) { |
7243 _reportError(new AnalysisError( | 7352 _reportError(new AnalysisError( |
(...skipping 873 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8117 */ | 8226 */ |
8118 Parser_SyntheticKeywordToken(Keyword keyword, int offset) | 8227 Parser_SyntheticKeywordToken(Keyword keyword, int offset) |
8119 : super(keyword, offset); | 8228 : super(keyword, offset); |
8120 | 8229 |
8121 @override | 8230 @override |
8122 int get length => 0; | 8231 int get length => 0; |
8123 | 8232 |
8124 @override | 8233 @override |
8125 Token copy() => new Parser_SyntheticKeywordToken(keyword, offset); | 8234 Token copy() => new Parser_SyntheticKeywordToken(keyword, offset); |
8126 } | 8235 } |
OLD | NEW |