| 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 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 */ | 242 */ |
| 243 bool _inSwitch = false; | 243 bool _inSwitch = false; |
| 244 | 244 |
| 245 /** | 245 /** |
| 246 * A flag indicating whether the parser is currently in a constructor field | 246 * A flag indicating whether the parser is currently in a constructor field |
| 247 * initializer, with no intervening parentheses, braces, or brackets. | 247 * initializer, with no intervening parentheses, braces, or brackets. |
| 248 */ | 248 */ |
| 249 bool _inInitializer = false; | 249 bool _inInitializer = false; |
| 250 | 250 |
| 251 /** | 251 /** |
| 252 * A flag indicating whether the parser is to parse generic function type | |
| 253 * syntax. | |
| 254 */ | |
| 255 bool parseGenericFunctionTypes = false; | |
| 256 | |
| 257 /** | |
| 258 * A flag indicating whether the parser is to parse generic method syntax. | 252 * A flag indicating whether the parser is to parse generic method syntax. |
| 259 */ | 253 */ |
| 260 @deprecated | 254 @deprecated |
| 261 bool parseGenericMethods = false; | 255 bool parseGenericMethods = false; |
| 262 | 256 |
| 263 /** | 257 /** |
| 264 * A flag indicating whether to parse generic method comments, of the form | 258 * A flag indicating whether to parse generic method comments, of the form |
| 265 * `/*=T*/` and `/*<T>*/`. | 259 * `/*=T*/` and `/*<T>*/`. |
| 266 */ | 260 */ |
| 267 bool parseGenericMethodComments = false; | 261 bool parseGenericMethodComments = false; |
| (...skipping 4782 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5050 } | 5044 } |
| 5051 | 5045 |
| 5052 /** | 5046 /** |
| 5053 * Parse a type. | 5047 * Parse a type. |
| 5054 * | 5048 * |
| 5055 * type ::= | 5049 * type ::= |
| 5056 * typeWithoutFunction | 5050 * typeWithoutFunction |
| 5057 * | functionType | 5051 * | functionType |
| 5058 */ | 5052 */ |
| 5059 TypeAnnotation parseTypeAnnotation(bool inExpression) { | 5053 TypeAnnotation parseTypeAnnotation(bool inExpression) { |
| 5060 if (parseGenericFunctionTypes) { | 5054 TypeAnnotation type = null; |
| 5061 TypeAnnotation type = null; | 5055 if (_atGenericFunctionTypeAfterReturnType(_currentToken)) { |
| 5062 if (_atGenericFunctionTypeAfterReturnType(_currentToken)) { | 5056 // Generic function type with no return type. |
| 5063 // Generic function type with no return type. | 5057 type = parseGenericFunctionTypeAfterReturnType(null); |
| 5064 type = parseGenericFunctionTypeAfterReturnType(null); | 5058 } else if (_currentToken.keyword == Keyword.VOID && |
| 5065 } else if (_currentToken.keyword == Keyword.VOID && | 5059 _atGenericFunctionTypeAfterReturnType(_currentToken.next)) { |
| 5066 _atGenericFunctionTypeAfterReturnType(_currentToken.next)) { | 5060 type = astFactory.typeName( |
| 5067 type = astFactory.typeName( | 5061 astFactory.simpleIdentifier(getAndAdvance()), null); |
| 5068 astFactory.simpleIdentifier(getAndAdvance()), null); | 5062 } else { |
| 5069 } else { | 5063 type = parseTypeName(inExpression); |
| 5070 type = parseTypeName(inExpression); | |
| 5071 } | |
| 5072 while (_atGenericFunctionTypeAfterReturnType(_currentToken)) { | |
| 5073 type = parseGenericFunctionTypeAfterReturnType(type); | |
| 5074 } | |
| 5075 return type; | |
| 5076 } | 5064 } |
| 5077 return parseTypeName(inExpression); | 5065 while (_atGenericFunctionTypeAfterReturnType(_currentToken)) { |
| 5066 type = parseGenericFunctionTypeAfterReturnType(type); |
| 5067 } |
| 5068 return type; |
| 5078 } | 5069 } |
| 5079 | 5070 |
| 5080 /** | 5071 /** |
| 5081 * Parse a list of type arguments. Return the type argument list that was | 5072 * Parse a list of type arguments. Return the type argument list that was |
| 5082 * parsed. | 5073 * parsed. |
| 5083 * | 5074 * |
| 5084 * This method assumes that the current token matches `TokenType.LT`. | 5075 * This method assumes that the current token matches `TokenType.LT`. |
| 5085 * | 5076 * |
| 5086 * typeArguments ::= | 5077 * typeArguments ::= |
| 5087 * '<' typeList '>' | 5078 * '<' typeList '>' |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5528 | 5519 |
| 5529 /** | 5520 /** |
| 5530 * Parse a type annotation, starting at the [startToken], without actually | 5521 * Parse a type annotation, starting at the [startToken], without actually |
| 5531 * creating a type annotation or changing the current token. Return the token | 5522 * creating a type annotation or changing the current token. Return the token |
| 5532 * following the type annotation that was parsed, or `null` if the given token | 5523 * following the type annotation that was parsed, or `null` if the given token |
| 5533 * is not the first token in a valid type annotation. | 5524 * is not the first token in a valid type annotation. |
| 5534 * | 5525 * |
| 5535 * This method must be kept in sync with [parseTypeAnnotation]. | 5526 * This method must be kept in sync with [parseTypeAnnotation]. |
| 5536 */ | 5527 */ |
| 5537 Token skipTypeAnnotation(Token startToken) { | 5528 Token skipTypeAnnotation(Token startToken) { |
| 5538 if (parseGenericFunctionTypes) { | 5529 Token next = null; |
| 5539 Token next = null; | 5530 if (_atGenericFunctionTypeAfterReturnType(startToken)) { |
| 5540 if (_atGenericFunctionTypeAfterReturnType(startToken)) { | 5531 next = skipGenericFunctionTypeAfterReturnType(startToken); |
| 5541 next = skipGenericFunctionTypeAfterReturnType(startToken); | 5532 } else if (_currentToken.keyword == Keyword.VOID && |
| 5542 } else if (_currentToken.keyword == Keyword.VOID && | 5533 _atGenericFunctionTypeAfterReturnType(_currentToken.next)) { |
| 5543 _atGenericFunctionTypeAfterReturnType(_currentToken.next)) { | 5534 next = next.next; |
| 5544 next = next.next; | 5535 } else { |
| 5545 } else { | 5536 next = skipTypeName(startToken); |
| 5546 next = skipTypeName(startToken); | |
| 5547 } | |
| 5548 while (next != null && _tokenMatchesString(next, 'Function')) { | |
| 5549 next = skipGenericFunctionTypeAfterReturnType(next); | |
| 5550 } | |
| 5551 return next; | |
| 5552 } | 5537 } |
| 5553 return skipTypeName(startToken); | 5538 while (next != null && _atGenericFunctionTypeAfterReturnType(next)) { |
| 5539 next = skipGenericFunctionTypeAfterReturnType(next); |
| 5540 } |
| 5541 return next; |
| 5554 } | 5542 } |
| 5555 | 5543 |
| 5556 /** | 5544 /** |
| 5557 * Parse a list of type arguments, starting at the [startToken], without | 5545 * Parse a list of type arguments, starting at the [startToken], without |
| 5558 * actually creating a type argument list or changing the current token. | 5546 * actually creating a type argument list or changing the current token. |
| 5559 * Return the token following the type argument list that was parsed, or | 5547 * Return the token following the type argument list that was parsed, or |
| 5560 * `null` if the given token is not the first token in a valid type argument | 5548 * `null` if the given token is not the first token in a valid type argument |
| 5561 * list. | 5549 * list. |
| 5562 * | 5550 * |
| 5563 * This method must be kept in sync with [parseTypeArgumentList]. | 5551 * This method must be kept in sync with [parseTypeArgumentList]. |
| (...skipping 2941 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8505 */ | 8493 */ |
| 8506 Parser_SyntheticKeywordToken(Keyword keyword, int offset) | 8494 Parser_SyntheticKeywordToken(Keyword keyword, int offset) |
| 8507 : super(keyword, offset); | 8495 : super(keyword, offset); |
| 8508 | 8496 |
| 8509 @override | 8497 @override |
| 8510 int get length => 0; | 8498 int get length => 0; |
| 8511 | 8499 |
| 8512 @override | 8500 @override |
| 8513 Token copy() => new Parser_SyntheticKeywordToken(keyword, offset); | 8501 Token copy() => new Parser_SyntheticKeywordToken(keyword, offset); |
| 8514 } | 8502 } |
| OLD | NEW |