Chromium Code Reviews| 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/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
| (...skipping 2090 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2101 * during the parse. | 2101 * during the parse. |
| 2102 */ | 2102 */ |
| 2103 final AnalysisErrorListener _errorListener; | 2103 final AnalysisErrorListener _errorListener; |
| 2104 | 2104 |
| 2105 /** | 2105 /** |
| 2106 * An [errorListener] lock, if more than `0`, then errors are not reported. | 2106 * An [errorListener] lock, if more than `0`, then errors are not reported. |
| 2107 */ | 2107 */ |
| 2108 int _errorListenerLock = 0; | 2108 int _errorListenerLock = 0; |
| 2109 | 2109 |
| 2110 /** | 2110 /** |
| 2111 * A flag indicating whether the parser is to parse the async support. | |
| 2112 */ | |
| 2113 bool _parseAsync = true; | |
| 2114 | |
| 2115 /** | |
| 2111 * A flag indicating whether parser is to parse function bodies. | 2116 * A flag indicating whether parser is to parse function bodies. |
| 2112 */ | 2117 */ |
| 2113 bool _parseFunctionBodies = true; | 2118 bool _parseFunctionBodies = true; |
| 2114 | 2119 |
| 2115 /** | 2120 /** |
| 2116 * The next token to be parsed. | 2121 * The next token to be parsed. |
| 2117 */ | 2122 */ |
| 2118 Token _currentToken; | 2123 Token _currentToken; |
| 2119 | 2124 |
| 2120 /** | 2125 /** |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2181 */ | 2186 */ |
| 2182 bool get hasReturnTypeInTypeAlias { | 2187 bool get hasReturnTypeInTypeAlias { |
| 2183 Token next = _skipReturnType(_currentToken); | 2188 Token next = _skipReturnType(_currentToken); |
| 2184 if (next == null) { | 2189 if (next == null) { |
| 2185 return false; | 2190 return false; |
| 2186 } | 2191 } |
| 2187 return _tokenMatchesIdentifier(next); | 2192 return _tokenMatchesIdentifier(next); |
| 2188 } | 2193 } |
| 2189 | 2194 |
| 2190 /** | 2195 /** |
| 2196 * Set whether the parser is to parse the async support. | |
| 2197 */ | |
| 2198 void set parseAsync(bool parseAsync) { | |
| 2199 this._parseAsync = parseAsync; | |
| 2200 } | |
| 2201 | |
| 2202 /** | |
| 2191 * Set whether parser is to parse function bodies. | 2203 * Set whether parser is to parse function bodies. |
| 2192 */ | 2204 */ |
| 2193 void set parseFunctionBodies(bool parseFunctionBodies) { | 2205 void set parseFunctionBodies(bool parseFunctionBodies) { |
| 2194 this._parseFunctionBodies = parseFunctionBodies; | 2206 this._parseFunctionBodies = parseFunctionBodies; |
| 2195 } | 2207 } |
| 2196 | 2208 |
| 2197 /** | 2209 /** |
| 2198 * Advance to the next token in the token stream, making it the new current | 2210 * Advance to the next token in the token stream, making it the new current |
| 2199 * token and return the token that was current before this method was invoked. | 2211 * token and return the token that was current before this method was invoked. |
| 2200 */ | 2212 */ |
| (...skipping 3879 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6080 if (_matches(TokenType.STRING)) { | 6092 if (_matches(TokenType.STRING)) { |
| 6081 stringLiteral = parseStringLiteral(); | 6093 stringLiteral = parseStringLiteral(); |
| 6082 } | 6094 } |
| 6083 return new NativeFunctionBody( | 6095 return new NativeFunctionBody( |
| 6084 nativeToken, stringLiteral, _expect(TokenType.SEMICOLON)); | 6096 nativeToken, stringLiteral, _expect(TokenType.SEMICOLON)); |
| 6085 } | 6097 } |
| 6086 Token keyword = null; | 6098 Token keyword = null; |
| 6087 Token star = null; | 6099 Token star = null; |
| 6088 if (_matchesString(ASYNC)) { | 6100 if (_matchesString(ASYNC)) { |
| 6089 keyword = getAndAdvance(); | 6101 keyword = getAndAdvance(); |
| 6102 if (!_parseAsync) { | |
| 6103 _reportErrorForToken(ParserErrorCode.ASYNC_NOT_SUPPORTED, keyword); | |
| 6104 } | |
| 6090 if (_matches(TokenType.STAR)) { | 6105 if (_matches(TokenType.STAR)) { |
| 6091 star = getAndAdvance(); | 6106 star = getAndAdvance(); |
| 6092 _inGenerator = true; | 6107 _inGenerator = true; |
| 6093 } | 6108 } |
| 6094 _inAsync = true; | 6109 _inAsync = true; |
| 6095 } else if (_matchesString(SYNC)) { | 6110 } else if (_matchesString(SYNC)) { |
| 6096 keyword = getAndAdvance(); | 6111 keyword = getAndAdvance(); |
| 6112 if (!_parseAsync) { | |
| 6113 _reportErrorForToken(ParserErrorCode.ASYNC_NOT_SUPPORTED, keyword); | |
| 6114 } | |
| 6097 if (_matches(TokenType.STAR)) { | 6115 if (_matches(TokenType.STAR)) { |
| 6098 star = getAndAdvance(); | 6116 star = getAndAdvance(); |
| 6099 _inGenerator = true; | 6117 _inGenerator = true; |
| 6100 } | 6118 } |
| 6101 } | 6119 } |
| 6102 if (_matches(TokenType.FUNCTION)) { | 6120 if (_matches(TokenType.FUNCTION)) { |
| 6103 if (keyword != null) { | 6121 if (keyword != null) { |
| 6104 if (!_tokenMatchesString(keyword, ASYNC)) { | 6122 if (!_tokenMatchesString(keyword, ASYNC)) { |
| 6105 _reportErrorForToken(ParserErrorCode.INVALID_SYNC, keyword); | 6123 _reportErrorForToken(ParserErrorCode.INVALID_SYNC, keyword); |
| 6106 keyword = null; | 6124 keyword = null; |
| (...skipping 3246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9353 | 9371 |
| 9354 /** | 9372 /** |
| 9355 * 16.32 Identifier Reference: It is a compile-time error if any of the | 9373 * 16.32 Identifier Reference: It is a compile-time error if any of the |
| 9356 * identifiers async, await, or yield is used as an identifier in a function | 9374 * identifiers async, await, or yield is used as an identifier in a function |
| 9357 * body marked with either async, async*, or sync*. | 9375 * body marked with either async, async*, or sync*. |
| 9358 */ | 9376 */ |
| 9359 static const ParserErrorCode ASYNC_KEYWORD_USED_AS_IDENTIFIER = | 9377 static const ParserErrorCode ASYNC_KEYWORD_USED_AS_IDENTIFIER = |
| 9360 const ParserErrorCode('ASYNC_KEYWORD_USED_AS_IDENTIFIER', | 9378 const ParserErrorCode('ASYNC_KEYWORD_USED_AS_IDENTIFIER', |
| 9361 "The keywords 'async', 'await', and 'yield' may not be used as identif iers in an asynchronous or generator function."); | 9379 "The keywords 'async', 'await', and 'yield' may not be used as identif iers in an asynchronous or generator function."); |
| 9362 | 9380 |
| 9381 /** | |
| 9382 * Some environments such as fletch do not support async. | |
|
Brian Wilkerson
2016/01/08 18:43:47
"fletch" or "Fletch"?
"environments such as fletc
danrubel
2016/01/08 20:45:51
Done.
| |
| 9383 */ | |
| 9384 static const CompileTimeErrorCode ASYNC_NOT_SUPPORTED = | |
| 9385 const CompileTimeErrorCode('ASYNC_NOT_SUPPORTED', | |
| 9386 "Async and sync are not supported in this environment."); | |
|
Brian Wilkerson
2016/01/08 18:43:47
"in this environment" or "on this platform"? What
danrubel
2016/01/08 20:45:51
Really good question... I struggled with this as w
| |
| 9387 | |
| 9363 static const ParserErrorCode BREAK_OUTSIDE_OF_LOOP = const ParserErrorCode( | 9388 static const ParserErrorCode BREAK_OUTSIDE_OF_LOOP = const ParserErrorCode( |
| 9364 'BREAK_OUTSIDE_OF_LOOP', | 9389 'BREAK_OUTSIDE_OF_LOOP', |
| 9365 "A break statement cannot be used outside of a loop or switch statement"); | 9390 "A break statement cannot be used outside of a loop or switch statement"); |
| 9366 | 9391 |
| 9367 static const ParserErrorCode CLASS_IN_CLASS = const ParserErrorCode( | 9392 static const ParserErrorCode CLASS_IN_CLASS = const ParserErrorCode( |
| 9368 'CLASS_IN_CLASS', "Classes cannot be declared inside other classes"); | 9393 'CLASS_IN_CLASS', "Classes cannot be declared inside other classes"); |
| 9369 | 9394 |
| 9370 static const ParserErrorCode COLON_IN_PLACE_OF_IN = const ParserErrorCode( | 9395 static const ParserErrorCode COLON_IN_PLACE_OF_IN = const ParserErrorCode( |
| 9371 'COLON_IN_PLACE_OF_IN', "For-in loops use 'in' rather than a colon"); | 9396 'COLON_IN_PLACE_OF_IN', "For-in loops use 'in' rather than a colon"); |
| 9372 | 9397 |
| (...skipping 1958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 11331 } | 11356 } |
| 11332 | 11357 |
| 11333 /** | 11358 /** |
| 11334 * Copy resolution data from the [fromNode] to the [toNode]. | 11359 * Copy resolution data from the [fromNode] to the [toNode]. |
| 11335 */ | 11360 */ |
| 11336 static void copyResolutionData(AstNode fromNode, AstNode toNode) { | 11361 static void copyResolutionData(AstNode fromNode, AstNode toNode) { |
| 11337 ResolutionCopier copier = new ResolutionCopier(); | 11362 ResolutionCopier copier = new ResolutionCopier(); |
| 11338 copier._isEqualNodes(fromNode, toNode); | 11363 copier._isEqualNodes(fromNode, toNode); |
| 11339 } | 11364 } |
| 11340 } | 11365 } |
| OLD | NEW |