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 3946 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3957 | 3957 |
3958 /** | 3958 /** |
3959 * Parse a normal formal parameter. Return the normal formal parameter that | 3959 * Parse a normal formal parameter. Return the normal formal parameter that |
3960 * was parsed. | 3960 * was parsed. |
3961 * | 3961 * |
3962 * normalFormalParameter ::= | 3962 * normalFormalParameter ::= |
3963 * functionSignature | 3963 * functionSignature |
3964 * | fieldFormalParameter | 3964 * | fieldFormalParameter |
3965 * | simpleFormalParameter | 3965 * | simpleFormalParameter |
3966 * | 3966 * |
3967 * functionSignature: | 3967 * legacyFunctionSignature: |
3968 * metadata returnType? identifier typeParameters? formalParameterList | 3968 * metadata returnType? identifier typeParameters? formalParameterList |
3969 * | 3969 * |
3970 * fieldFormalParameter ::= | 3970 * fieldFormalParameter ::= |
3971 * metadata finalConstVarOrType? 'this' '.' identifier | 3971 * metadata finalConstVarOrType? 'this' '.' identifier |
3972 * | 3972 * |
3973 * simpleFormalParameter ::= | 3973 * simpleFormalParameter ::= |
3974 * declaredIdentifier | 3974 * declaredIdentifier |
3975 * | metadata identifier | 3975 * | metadata identifier |
3976 */ | 3976 */ |
3977 NormalFormalParameter parseNormalFormalParameter() { | 3977 NormalFormalParameter parseNormalFormalParameter() { |
(...skipping 838 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4816 * classTypeAlias | 4816 * classTypeAlias |
4817 * | functionTypeAlias | 4817 * | functionTypeAlias |
4818 * | 4818 * |
4819 * classTypeAlias ::= | 4819 * classTypeAlias ::= |
4820 * identifier typeParameters? '=' 'abstract'? mixinApplication | 4820 * identifier typeParameters? '=' 'abstract'? mixinApplication |
4821 * | 4821 * |
4822 * mixinApplication ::= | 4822 * mixinApplication ::= |
4823 * qualified withClause implementsClause? ';' | 4823 * qualified withClause implementsClause? ';' |
4824 * | 4824 * |
4825 * functionTypeAlias ::= | 4825 * functionTypeAlias ::= |
4826 * legacyFunctionTypeAlias | | |
4827 * newFunctionTypeAlias | |
4828 * | |
4829 * legacyFunctionTypeAlias ::= | |
4826 * functionPrefix typeParameterList? formalParameterList ';' | 4830 * functionPrefix typeParameterList? formalParameterList ';' |
4827 * | 4831 * |
4828 * functionPrefix ::= | 4832 * functionPrefix ::= |
4829 * returnType? name | 4833 * returnType? name |
4834 * | |
4835 * newFunctionTypeAlias ::= | |
4836 * identifier typeParameters? '=' functionType ';' | |
4837 * | |
4838 * functionType ::= typeParameterList? formalParameterList '-' '>' returnT ype | |
Lasse Reichstein Nielsen
2016/10/20 19:36:44
I assume you use '-' '>' instead of '->' because i
floitsch
2016/10/21 12:24:34
correct.
| |
4839 * | |
4830 */ | 4840 */ |
4831 TypeAlias parseTypeAlias(CommentAndMetadata commentAndMetadata) { | 4841 TypeAlias parseTypeAlias(CommentAndMetadata commentAndMetadata) { |
4832 Token keyword = getAndAdvance(); | 4842 Token keyword = getAndAdvance(); |
4833 if (_matchesIdentifier()) { | 4843 if (_matchesIdentifier()) { |
4834 Token next = _peek(); | 4844 Token next = _peek(); |
4835 if (_tokenMatches(next, TokenType.LT)) { | 4845 if (_tokenMatches(next, TokenType.LT)) { |
4836 next = _skipTypeParameterList(next); | 4846 next = _skipTypeParameterList(next); |
4837 if (next != null && _tokenMatches(next, TokenType.EQ)) { | 4847 if (next != null && _tokenMatches(next, TokenType.EQ)) { |
4848 next = next.next; | |
4849 if (next != null && | |
4850 (_tokenMatches(next, TokenType.LT) || | |
4851 _tokenMatches(next, TokenType.OPEN_PAREN))) { | |
4852 return _parseNewFunctionTypeAlias(commentAndMetadata, keyword); | |
4853 } | |
4854 if (next != null && _tokenMatches(next, TokenType.IDENTIFIER)) { | |
4855 next = next.next; | |
4856 if (next != null && _tokenMatches(next, TokenType.MINUS)) { | |
4857 return _parseNewFunctionTypeAlias(commentAndMetadata, keyword); | |
4858 } | |
4859 } | |
4838 TypeAlias typeAlias = | 4860 TypeAlias typeAlias = |
4839 parseClassTypeAlias(commentAndMetadata, null, keyword); | 4861 parseClassTypeAlias(commentAndMetadata, null, keyword); |
4840 _reportErrorForToken( | 4862 _reportErrorForToken( |
4841 ParserErrorCode.DEPRECATED_CLASS_TYPE_ALIAS, keyword); | 4863 ParserErrorCode.DEPRECATED_CLASS_TYPE_ALIAS, keyword); |
4842 return typeAlias; | 4864 return typeAlias; |
4843 } | 4865 } |
4844 } else if (_tokenMatches(next, TokenType.EQ)) { | 4866 } else if (_tokenMatches(next, TokenType.EQ)) { |
4867 next = next.next; | |
4868 if (next != null && | |
4869 (_tokenMatches(next, TokenType.LT) || | |
4870 _tokenMatches(next, TokenType.OPEN_PAREN))) { | |
4871 return _parseNewFunctionTypeAlias(commentAndMetadata, keyword); | |
4872 } else if (next != null && _tokenMatches(next, TokenType.IDENTIFIER)) { | |
4873 next = next.next; | |
4874 if (next != null && _tokenMatches(next, TokenType.MINUS)) { | |
4875 return _parseNewFunctionTypeAlias(commentAndMetadata, keyword); | |
4876 } | |
4877 } | |
4845 TypeAlias typeAlias = | 4878 TypeAlias typeAlias = |
4846 parseClassTypeAlias(commentAndMetadata, null, keyword); | 4879 parseClassTypeAlias(commentAndMetadata, null, keyword); |
4847 _reportErrorForToken( | 4880 _reportErrorForToken( |
4848 ParserErrorCode.DEPRECATED_CLASS_TYPE_ALIAS, keyword); | 4881 ParserErrorCode.DEPRECATED_CLASS_TYPE_ALIAS, keyword); |
4849 return typeAlias; | 4882 return typeAlias; |
4850 } | 4883 } |
4851 } | 4884 } |
4852 return _parseFunctionTypeAlias(commentAndMetadata, keyword); | 4885 return _parseFunctionTypeAlias(commentAndMetadata, keyword); |
4853 } | 4886 } |
4854 | 4887 |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5315 * a type name or changing the current token. Return the token following the | 5348 * a type name or changing the current token. Return the token following the |
5316 * type name that was parsed, or `null` if the given token is not the first | 5349 * type name that was parsed, or `null` if the given token is not the first |
5317 * token in a valid type name. | 5350 * token in a valid type name. |
5318 * | 5351 * |
5319 * This method must be kept in sync with [parseTypeName]. | 5352 * This method must be kept in sync with [parseTypeName]. |
5320 * | 5353 * |
5321 * type ::= | 5354 * type ::= |
5322 * qualified typeArguments? | 5355 * qualified typeArguments? |
5323 */ | 5356 */ |
5324 Token skipTypeName(Token startToken) { | 5357 Token skipTypeName(Token startToken) { |
5325 Token token = skipPrefixedIdentifier(startToken); | 5358 Token token; |
5359 if (_tokenMatches(startToken, TokenType.LT)) { | |
5360 token = skipTypeArgumentList(token); | |
5361 if (token == null) return null; | |
5362 token = _skipFormalParameterList(token); | |
5363 if (token == null) return null; | |
5364 if (!_tokenMatches(token, TokenType.MINUS)) return null; | |
5365 token = token.next; | |
5366 if (token == null) return null; | |
5367 if (!_tokenMatches(token, TokenType.GT)) return null; | |
5368 return skipTypeName(token); | |
5369 } | |
5370 | |
5371 token = skipPrefixedIdentifier(startToken); | |
5326 if (token == null) { | 5372 if (token == null) { |
5327 return null; | 5373 return null; |
5328 } | 5374 } |
5329 if (_tokenMatches(token, TokenType.LT)) { | 5375 if (_tokenMatches(token, TokenType.LT)) { |
5330 token = skipTypeArgumentList(token); | 5376 token = skipTypeArgumentList(token); |
5331 } | 5377 } |
5332 return token; | 5378 return token; |
5333 } | 5379 } |
5334 | 5380 |
5335 /** | 5381 /** |
(...skipping 1174 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(); | |
Lasse Reichstein Nielsen
2016/10/20 19:36:44
Using the old formal-parameter list, so a single i
floitsch
2016/10/21 12:24:34
Right.
I wanted to see how hard it would be to ch
| |
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 855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8099 */ | 8208 */ |
8100 Parser_SyntheticKeywordToken(Keyword keyword, int offset) | 8209 Parser_SyntheticKeywordToken(Keyword keyword, int offset) |
8101 : super(keyword, offset); | 8210 : super(keyword, offset); |
8102 | 8211 |
8103 @override | 8212 @override |
8104 int get length => 0; | 8213 int get length => 0; |
8105 | 8214 |
8106 @override | 8215 @override |
8107 Token copy() => new Parser_SyntheticKeywordToken(keyword, offset); | 8216 Token copy() => new Parser_SyntheticKeywordToken(keyword, offset); |
8108 } | 8217 } |
OLD | NEW |