| 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.parser; | 5 library analyzer.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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 173 | 173 | 
| 174   static String _SHOW = Keyword.SHOW.lexeme; | 174   static String _SHOW = Keyword.SHOW.lexeme; | 
| 175 | 175 | 
| 176   static String SYNC = Keyword.SYNC.lexeme; | 176   static String SYNC = Keyword.SYNC.lexeme; | 
| 177 | 177 | 
| 178   static String _YIELD = Keyword.YIELD.lexeme; | 178   static String _YIELD = Keyword.YIELD.lexeme; | 
| 179 | 179 | 
| 180   static const int _MAX_TREE_DEPTH = 300; | 180   static const int _MAX_TREE_DEPTH = 300; | 
| 181 | 181 | 
| 182   /** | 182   /** | 
|  | 183    * A flag indicating whether the analyzer [Parser] factory method | 
|  | 184    * will return a fasta based parser or an analyzer based parser. | 
|  | 185    */ | 
|  | 186   static bool useFasta = const bool.fromEnvironment("useFastaParser"); | 
|  | 187 | 
|  | 188   /** | 
| 183    * The source being parsed. | 189    * The source being parsed. | 
| 184    */ | 190    */ | 
| 185   final Source _source; | 191   final Source _source; | 
| 186 | 192 | 
| 187   /** | 193   /** | 
| 188    * The error listener that will be informed of any errors that are found | 194    * The error listener that will be informed of any errors that are found | 
| 189    * during the parse. | 195    * during the parse. | 
| 190    */ | 196    */ | 
| 191   final AnalysisErrorListener _errorListener; | 197   final AnalysisErrorListener _errorListener; | 
| 192 | 198 | 
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 263   @deprecated | 269   @deprecated | 
| 264   bool parseGenericMethods = false; | 270   bool parseGenericMethods = false; | 
| 265 | 271 | 
| 266   /** | 272   /** | 
| 267    * A flag indicating whether to parse generic method comments, of the form | 273    * A flag indicating whether to parse generic method comments, of the form | 
| 268    * `/*=T*/` and `/*<T>*/`. | 274    * `/*=T*/` and `/*<T>*/`. | 
| 269    */ | 275    */ | 
| 270   bool parseGenericMethodComments = false; | 276   bool parseGenericMethodComments = false; | 
| 271 | 277 | 
| 272   /** | 278   /** | 
| 273    * A flag indicating whether the analyzer [Parser] factory method |  | 
| 274    * will return a fasta based parser or an analyzer based parser. |  | 
| 275    */ |  | 
| 276   static bool useFasta = const bool.fromEnvironment("useFastaParser"); |  | 
| 277 |  | 
| 278   /** |  | 
| 279    * Initialize a newly created parser to parse tokens in the given [_source] | 279    * Initialize a newly created parser to parse tokens in the given [_source] | 
| 280    * and to report any errors that are found to the given [_errorListener]. | 280    * and to report any errors that are found to the given [_errorListener]. | 
| 281    */ | 281    */ | 
| 282   factory Parser(Source source, AnalysisErrorListener errorListener, | 282   factory Parser(Source source, AnalysisErrorListener errorListener, | 
| 283       {bool useFasta}) { | 283       {bool useFasta}) { | 
| 284     if (useFasta ?? Parser.useFasta) { | 284     if (useFasta ?? Parser.useFasta) { | 
| 285       return new _Parser2(source, errorListener); | 285       return new _Parser2(source, errorListener); | 
| 286     } else { | 286     } else { | 
| 287       return new Parser.withoutFasta(source, errorListener); | 287       return new Parser.withoutFasta(source, errorListener); | 
| 288     } | 288     } | 
| (...skipping 2592 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2881       type = _parseOptionalTypeNameComment(); | 2881       type = _parseOptionalTypeNameComment(); | 
| 2882       if (type != null) { | 2882       if (type != null) { | 
| 2883         // Clear the keyword to prevent an error. | 2883         // Clear the keyword to prevent an error. | 
| 2884         keywordToken = null; | 2884         keywordToken = null; | 
| 2885       } | 2885       } | 
| 2886     } else if (_isTypedIdentifier(_currentToken)) { | 2886     } else if (_isTypedIdentifier(_currentToken)) { | 
| 2887       type = parseReturnType(false); | 2887       type = parseReturnType(false); | 
| 2888     } else if (inFunctionType && _matchesIdentifier()) { | 2888     } else if (inFunctionType && _matchesIdentifier()) { | 
| 2889       type = parseTypeAnnotation(false); | 2889       type = parseTypeAnnotation(false); | 
| 2890     } else if (!optional) { | 2890     } else if (!optional) { | 
|  | 2891       // If there is a valid type immediately following an unexpected token, | 
|  | 2892       // then report and skip the unexpected token. | 
|  | 2893       Token next = _peek(); | 
|  | 2894       Keyword nextKeyword = next.keyword; | 
|  | 2895       if (nextKeyword == Keyword.FINAL || | 
|  | 2896           nextKeyword == Keyword.CONST || | 
|  | 2897           nextKeyword == Keyword.VAR || | 
|  | 2898           _isTypedIdentifier(next) || | 
|  | 2899           inFunctionType && _tokenMatchesIdentifier(next)) { | 
|  | 2900         _reportErrorForCurrentToken( | 
|  | 2901             ParserErrorCode.UNEXPECTED_TOKEN, [_currentToken.lexeme]); | 
|  | 2902         _advance(); | 
|  | 2903         return parseFinalConstVarOrType(optional, | 
|  | 2904             inFunctionType: inFunctionType); | 
|  | 2905       } | 
| 2891       _reportErrorForCurrentToken( | 2906       _reportErrorForCurrentToken( | 
| 2892           ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE); | 2907           ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE); | 
| 2893     } else { | 2908     } else { | 
| 2894       // Support parameters such as `(/*=K*/ key, /*=V*/ value)` | 2909       // Support parameters such as `(/*=K*/ key, /*=V*/ value)` | 
| 2895       // This is not supported if the type is required. | 2910       // This is not supported if the type is required. | 
| 2896       type = _parseOptionalTypeNameComment(); | 2911       type = _parseOptionalTypeNameComment(); | 
| 2897     } | 2912     } | 
| 2898     return new FinalConstVarOrType(keywordToken, type); | 2913     return new FinalConstVarOrType(keywordToken, type); | 
| 2899   } | 2914   } | 
| 2900 | 2915 | 
| (...skipping 5725 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 8626     } | 8641     } | 
| 8627   } | 8642   } | 
| 8628 } | 8643 } | 
| 8629 | 8644 | 
| 8630 /** | 8645 /** | 
| 8631  * Instances of this class are thrown when the parser detects that AST has | 8646  * Instances of this class are thrown when the parser detects that AST has | 
| 8632  * too many nested expressions to be parsed safely and avoid possibility of | 8647  * too many nested expressions to be parsed safely and avoid possibility of | 
| 8633  * [StackOverflowError] in the parser or during later analysis. | 8648  * [StackOverflowError] in the parser or during later analysis. | 
| 8634  */ | 8649  */ | 
| 8635 class _TooDeepTreeError {} | 8650 class _TooDeepTreeError {} | 
| OLD | NEW | 
|---|