| 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 2117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2128 * during the parse. | 2128 * during the parse. |
| 2129 */ | 2129 */ |
| 2130 final AnalysisErrorListener _errorListener; | 2130 final AnalysisErrorListener _errorListener; |
| 2131 | 2131 |
| 2132 /** | 2132 /** |
| 2133 * An [_errorListener] lock, if more than `0`, then errors are not reported. | 2133 * An [_errorListener] lock, if more than `0`, then errors are not reported. |
| 2134 */ | 2134 */ |
| 2135 int _errorListenerLock = 0; | 2135 int _errorListenerLock = 0; |
| 2136 | 2136 |
| 2137 /** | 2137 /** |
| 2138 * A flag indicating whether the parser is to parse asserts in the initializer |
| 2139 * list of a constructor. |
| 2140 */ |
| 2141 bool _enableAssertInitializer = false; |
| 2142 |
| 2143 /** |
| 2138 * A flag indicating whether the parser is to parse the async support. | 2144 * A flag indicating whether the parser is to parse the async support. |
| 2139 */ | 2145 */ |
| 2140 bool _parseAsync = true; | 2146 bool _parseAsync = true; |
| 2141 | 2147 |
| 2142 /** | 2148 /** |
| 2143 * A flag indicating whether parser is to parse function bodies. | 2149 * A flag indicating whether parser is to parse function bodies. |
| 2144 */ | 2150 */ |
| 2145 bool _parseFunctionBodies = true; | 2151 bool _parseFunctionBodies = true; |
| 2146 | 2152 |
| 2147 /** | 2153 /** |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2195 Parser(this._source, this._errorListener); | 2201 Parser(this._source, this._errorListener); |
| 2196 | 2202 |
| 2197 /** | 2203 /** |
| 2198 * Set the token with which the parse is to begin to the given [token]. | 2204 * Set the token with which the parse is to begin to the given [token]. |
| 2199 */ | 2205 */ |
| 2200 void set currentToken(Token token) { | 2206 void set currentToken(Token token) { |
| 2201 this._currentToken = token; | 2207 this._currentToken = token; |
| 2202 } | 2208 } |
| 2203 | 2209 |
| 2204 /** | 2210 /** |
| 2211 * Return `true` if the parser is to parse asserts in the initializer list of |
| 2212 * a constructor. |
| 2213 */ |
| 2214 bool get enableAssertInitializer => _enableAssertInitializer; |
| 2215 |
| 2216 /** |
| 2217 * Set whether the parser is to parse asserts in the initializer list of a |
| 2218 * constructor to match the given [enable] flag. |
| 2219 */ |
| 2220 void set enableAssertInitializer(bool enable) { |
| 2221 _enableAssertInitializer = enable; |
| 2222 } |
| 2223 |
| 2224 /** |
| 2205 * Return `true` if the current token is the first token of a return type that | 2225 * Return `true` if the current token is the first token of a return type that |
| 2206 * is followed by an identifier, possibly followed by a list of type | 2226 * is followed by an identifier, possibly followed by a list of type |
| 2207 * parameters, followed by a left-parenthesis. This is used by | 2227 * parameters, followed by a left-parenthesis. This is used by |
| 2208 * [_parseTypeAlias] to determine whether or not to parse a return type. | 2228 * [_parseTypeAlias] to determine whether or not to parse a return type. |
| 2209 */ | 2229 */ |
| 2210 @deprecated | 2230 @deprecated |
| 2211 bool get hasReturnTypeInTypeAlias { | 2231 bool get hasReturnTypeInTypeAlias { |
| 2212 Token next = _skipReturnType(_currentToken); | 2232 Token next = _skipReturnType(_currentToken); |
| 2213 if (next == null) { | 2233 if (next == null) { |
| 2214 return false; | 2234 return false; |
| (...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2855 partDirectiveFound = true; | 2875 partDirectiveFound = true; |
| 2856 return _parsePartDirective(commentAndMetadata); | 2876 return _parsePartDirective(commentAndMetadata); |
| 2857 } | 2877 } |
| 2858 } else { | 2878 } else { |
| 2859 // Internal error: this method should not have been invoked if the | 2879 // Internal error: this method should not have been invoked if the |
| 2860 // current token was something other than one of the above. | 2880 // current token was something other than one of the above. |
| 2861 throw new IllegalStateException( | 2881 throw new IllegalStateException( |
| 2862 "parseDirective invoked in an invalid state (currentToken = $_cu
rrentToken)"); | 2882 "parseDirective invoked in an invalid state (currentToken = $_cu
rrentToken)"); |
| 2863 } | 2883 } |
| 2864 } | 2884 } |
| 2885 |
| 2865 Directive directive = parseDirective(); | 2886 Directive directive = parseDirective(); |
| 2866 if (declarations.length > 0 && !directiveFoundAfterDeclaration) { | 2887 if (declarations.length > 0 && !directiveFoundAfterDeclaration) { |
| 2867 _reportErrorForToken(ParserErrorCode.DIRECTIVE_AFTER_DECLARATION, | 2888 _reportErrorForToken(ParserErrorCode.DIRECTIVE_AFTER_DECLARATION, |
| 2868 directive.beginToken); | 2889 directive.beginToken); |
| 2869 directiveFoundAfterDeclaration = true; | 2890 directiveFoundAfterDeclaration = true; |
| 2870 } | 2891 } |
| 2871 directives.add(directive); | 2892 directives.add(directive); |
| 2872 } else if (type == TokenType.SEMICOLON) { | 2893 } else if (type == TokenType.SEMICOLON) { |
| 2873 // TODO(brianwilkerson) Consider moving this error detection into | 2894 // TODO(brianwilkerson) Consider moving this error detection into |
| 2874 // _parseCompilationUnitMember (in the places where EXPECTED_EXECUTABLE | 2895 // _parseCompilationUnitMember (in the places where EXPECTED_EXECUTABLE |
| (...skipping 1464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4339 } | 4360 } |
| 4340 _reportErrorForCurrentToken( | 4361 _reportErrorForCurrentToken( |
| 4341 ParserErrorCode.EXPECTED_TOKEN, [TokenType.OPEN_PAREN.lexeme]); | 4362 ParserErrorCode.EXPECTED_TOKEN, [TokenType.OPEN_PAREN.lexeme]); |
| 4342 // Recovery: Look to see whether there is a close paren that isn't matched | 4363 // Recovery: Look to see whether there is a close paren that isn't matched |
| 4343 // to an open paren and if so parse the list of arguments as normal. | 4364 // to an open paren and if so parse the list of arguments as normal. |
| 4344 return new ArgumentList(_createSyntheticToken(TokenType.OPEN_PAREN), null, | 4365 return new ArgumentList(_createSyntheticToken(TokenType.OPEN_PAREN), null, |
| 4345 _createSyntheticToken(TokenType.CLOSE_PAREN)); | 4366 _createSyntheticToken(TokenType.CLOSE_PAREN)); |
| 4346 } | 4367 } |
| 4347 | 4368 |
| 4348 /** | 4369 /** |
| 4370 * Parse an assert within a constructor's initializer list. Return the assert. |
| 4371 * |
| 4372 * This method assumes that the current token matches `Keyword.ASSERT`. |
| 4373 * |
| 4374 * assertInitializer ::= |
| 4375 * 'assert' '(' expression [',' expression] ')' |
| 4376 */ |
| 4377 void _parseAssertInitializer() { |
| 4378 // TODO(brianwilkerson) Capture the syntax in the AST using a new class, |
| 4379 // such as AssertInitializer |
| 4380 Token keyword = getAndAdvance(); |
| 4381 Token leftParen = _expect(TokenType.OPEN_PAREN); |
| 4382 Expression expression = parseExpression2(); |
| 4383 Token comma; |
| 4384 Expression message; |
| 4385 if (_matches(TokenType.COMMA)) { |
| 4386 comma = getAndAdvance(); |
| 4387 message = parseExpression2(); |
| 4388 } |
| 4389 Token rightParen = _expect(TokenType.CLOSE_PAREN); |
| 4390 // return new AssertInitializer( |
| 4391 // keyword, leftParen, expression, comma, message, rightParen); |
| 4392 } |
| 4393 |
| 4394 /** |
| 4349 * Parse an assert statement. Return the assert statement. | 4395 * Parse an assert statement. Return the assert statement. |
| 4350 * | 4396 * |
| 4351 * This method assumes that the current token matches `Keyword.ASSERT`. | 4397 * This method assumes that the current token matches `Keyword.ASSERT`. |
| 4352 * | 4398 * |
| 4353 * assertStatement ::= | 4399 * assertStatement ::= |
| 4354 * 'assert' '(' expression [',' expression] ')' ';' | 4400 * 'assert' '(' expression [',' expression] ')' ';' |
| 4355 */ | 4401 */ |
| 4356 AssertStatement _parseAssertStatement() { | 4402 AssertStatement _parseAssertStatement() { |
| 4357 Token keyword = getAndAdvance(); | 4403 Token keyword = getAndAdvance(); |
| 4358 Token leftParen = _expect(TokenType.OPEN_PAREN); | 4404 Token leftParen = _expect(TokenType.OPEN_PAREN); |
| (...skipping 1136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5495 bodyAllowed = false; | 5541 bodyAllowed = false; |
| 5496 initializers.add(_parseRedirectingConstructorInvocation(true)); | 5542 initializers.add(_parseRedirectingConstructorInvocation(true)); |
| 5497 } else { | 5543 } else { |
| 5498 initializers.add(_parseConstructorFieldInitializer(true)); | 5544 initializers.add(_parseConstructorFieldInitializer(true)); |
| 5499 } | 5545 } |
| 5500 } else if (keyword == Keyword.SUPER) { | 5546 } else if (keyword == Keyword.SUPER) { |
| 5501 initializers.add(_parseSuperConstructorInvocation()); | 5547 initializers.add(_parseSuperConstructorInvocation()); |
| 5502 } else if (_matches(TokenType.OPEN_CURLY_BRACKET) || | 5548 } else if (_matches(TokenType.OPEN_CURLY_BRACKET) || |
| 5503 _matches(TokenType.FUNCTION)) { | 5549 _matches(TokenType.FUNCTION)) { |
| 5504 _reportErrorForCurrentToken(ParserErrorCode.MISSING_INITIALIZER); | 5550 _reportErrorForCurrentToken(ParserErrorCode.MISSING_INITIALIZER); |
| 5551 } else if (_enableAssertInitializer && |
| 5552 _matchesKeyword(Keyword.ASSERT)) { |
| 5553 _parseAssertInitializer(); |
| 5505 } else { | 5554 } else { |
| 5506 initializers.add(_parseConstructorFieldInitializer(false)); | 5555 initializers.add(_parseConstructorFieldInitializer(false)); |
| 5507 } | 5556 } |
| 5508 } while (_optional(TokenType.COMMA)); | 5557 } while (_optional(TokenType.COMMA)); |
| 5509 if (factoryKeyword != null) { | 5558 if (factoryKeyword != null) { |
| 5510 _reportErrorForToken( | 5559 _reportErrorForToken( |
| 5511 ParserErrorCode.FACTORY_WITH_INITIALIZERS, factoryKeyword); | 5560 ParserErrorCode.FACTORY_WITH_INITIALIZERS, factoryKeyword); |
| 5512 } | 5561 } |
| 5513 } | 5562 } |
| 5514 ConstructorName redirectedConstructor = null; | 5563 ConstructorName redirectedConstructor = null; |
| (...skipping 2760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8275 _reportErrorForCurrentToken(ParserErrorCode.EXPECTED_CASE_OR_DEFAULT); | 8324 _reportErrorForCurrentToken(ParserErrorCode.EXPECTED_CASE_OR_DEFAULT); |
| 8276 bool atEndOrNextMember() { | 8325 bool atEndOrNextMember() { |
| 8277 TokenType type = _currentToken.type; | 8326 TokenType type = _currentToken.type; |
| 8278 if (type == TokenType.EOF || | 8327 if (type == TokenType.EOF || |
| 8279 type == TokenType.CLOSE_CURLY_BRACKET) { | 8328 type == TokenType.CLOSE_CURLY_BRACKET) { |
| 8280 return true; | 8329 return true; |
| 8281 } | 8330 } |
| 8282 Keyword keyword = _currentToken.keyword; | 8331 Keyword keyword = _currentToken.keyword; |
| 8283 return keyword == Keyword.CASE || keyword == Keyword.DEFAULT; | 8332 return keyword == Keyword.CASE || keyword == Keyword.DEFAULT; |
| 8284 } | 8333 } |
| 8334 |
| 8285 while (!atEndOrNextMember()) { | 8335 while (!atEndOrNextMember()) { |
| 8286 _advance(); | 8336 _advance(); |
| 8287 } | 8337 } |
| 8288 } | 8338 } |
| 8289 type = _currentToken.type; | 8339 type = _currentToken.type; |
| 8290 } | 8340 } |
| 8291 Token rightBracket = _expect(TokenType.CLOSE_CURLY_BRACKET); | 8341 Token rightBracket = _expect(TokenType.CLOSE_CURLY_BRACKET); |
| 8292 return new SwitchStatement(keyword, leftParenthesis, expression, | 8342 return new SwitchStatement(keyword, leftParenthesis, expression, |
| 8293 rightParenthesis, leftBracket, members, rightBracket); | 8343 rightParenthesis, leftBracket, members, rightBracket); |
| 8294 } finally { | 8344 } finally { |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8618 bool isValidInUri(Token token) { | 8668 bool isValidInUri(Token token) { |
| 8619 TokenType type = token.type; | 8669 TokenType type = token.type; |
| 8620 return type == TokenType.COLON || | 8670 return type == TokenType.COLON || |
| 8621 type == TokenType.SLASH || | 8671 type == TokenType.SLASH || |
| 8622 type == TokenType.PERIOD || | 8672 type == TokenType.PERIOD || |
| 8623 type == TokenType.PERIOD_PERIOD || | 8673 type == TokenType.PERIOD_PERIOD || |
| 8624 type == TokenType.PERIOD_PERIOD_PERIOD || | 8674 type == TokenType.PERIOD_PERIOD_PERIOD || |
| 8625 type == TokenType.INT || | 8675 type == TokenType.INT || |
| 8626 type == TokenType.DOUBLE; | 8676 type == TokenType.DOUBLE; |
| 8627 } | 8677 } |
| 8678 |
| 8628 while ((_tokenMatchesIdentifier(token) && !isKeywordAfterUri(token)) || | 8679 while ((_tokenMatchesIdentifier(token) && !isKeywordAfterUri(token)) || |
| 8629 isValidInUri(token)) { | 8680 isValidInUri(token)) { |
| 8630 token = token.next; | 8681 token = token.next; |
| 8631 } | 8682 } |
| 8632 if (_tokenMatches(token, TokenType.SEMICOLON) || | 8683 if (_tokenMatches(token, TokenType.SEMICOLON) || |
| 8633 isKeywordAfterUri(token)) { | 8684 isKeywordAfterUri(token)) { |
| 8634 Token endToken = token.previous; | 8685 Token endToken = token.previous; |
| 8635 token = _currentToken; | 8686 token = _currentToken; |
| 8636 int endOffset = token.end; | 8687 int endOffset = token.end; |
| 8637 StringBuffer buffer = new StringBuffer(); | 8688 StringBuffer buffer = new StringBuffer(); |
| (...skipping 1841 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10479 */ | 10530 */ |
| 10480 const ParserErrorCode(String name, String message, [String correction]) | 10531 const ParserErrorCode(String name, String message, [String correction]) |
| 10481 : super(name, message, correction); | 10532 : super(name, message, correction); |
| 10482 | 10533 |
| 10483 @override | 10534 @override |
| 10484 ErrorSeverity get errorSeverity => ErrorSeverity.ERROR; | 10535 ErrorSeverity get errorSeverity => ErrorSeverity.ERROR; |
| 10485 | 10536 |
| 10486 @override | 10537 @override |
| 10487 ErrorType get type => ErrorType.SYNTACTIC_ERROR; | 10538 ErrorType get type => ErrorType.SYNTACTIC_ERROR; |
| 10488 } | 10539 } |
| OLD | NEW |