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/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; | 
| (...skipping 2844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2855 partDirectiveFound = true; | 2855 partDirectiveFound = true; | 
| 2856 return _parsePartDirective(commentAndMetadata); | 2856 return _parsePartDirective(commentAndMetadata); | 
| 2857 } | 2857 } | 
| 2858 } else { | 2858 } else { | 
| 2859 // Internal error: this method should not have been invoked if the | 2859 // Internal error: this method should not have been invoked if the | 
| 2860 // current token was something other than one of the above. | 2860 // current token was something other than one of the above. | 
| 2861 throw new IllegalStateException( | 2861 throw new IllegalStateException( | 
| 2862 "parseDirective invoked in an invalid state (currentToken = $_cu rrentToken)"); | 2862 "parseDirective invoked in an invalid state (currentToken = $_cu rrentToken)"); | 
| 2863 } | 2863 } | 
| 2864 } | 2864 } | 
| 2865 | |
| 2865 Directive directive = parseDirective(); | 2866 Directive directive = parseDirective(); | 
| 2866 if (declarations.length > 0 && !directiveFoundAfterDeclaration) { | 2867 if (declarations.length > 0 && !directiveFoundAfterDeclaration) { | 
| 2867 _reportErrorForToken(ParserErrorCode.DIRECTIVE_AFTER_DECLARATION, | 2868 _reportErrorForToken(ParserErrorCode.DIRECTIVE_AFTER_DECLARATION, | 
| 2868 directive.beginToken); | 2869 directive.beginToken); | 
| 2869 directiveFoundAfterDeclaration = true; | 2870 directiveFoundAfterDeclaration = true; | 
| 2870 } | 2871 } | 
| 2871 directives.add(directive); | 2872 directives.add(directive); | 
| 2872 } else if (type == TokenType.SEMICOLON) { | 2873 } else if (type == TokenType.SEMICOLON) { | 
| 2873 // TODO(brianwilkerson) Consider moving this error detection into | 2874 // TODO(brianwilkerson) Consider moving this error detection into | 
| 2874 // _parseCompilationUnitMember (in the places where EXPECTED_EXECUTABLE | 2875 // _parseCompilationUnitMember (in the places where EXPECTED_EXECUTABLE | 
| (...skipping 1464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4339 } | 4340 } | 
| 4340 _reportErrorForCurrentToken( | 4341 _reportErrorForCurrentToken( | 
| 4341 ParserErrorCode.EXPECTED_TOKEN, [TokenType.OPEN_PAREN.lexeme]); | 4342 ParserErrorCode.EXPECTED_TOKEN, [TokenType.OPEN_PAREN.lexeme]); | 
| 4342 // Recovery: Look to see whether there is a close paren that isn't matched | 4343 // 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. | 4344 // to an open paren and if so parse the list of arguments as normal. | 
| 4344 return new ArgumentList(_createSyntheticToken(TokenType.OPEN_PAREN), null, | 4345 return new ArgumentList(_createSyntheticToken(TokenType.OPEN_PAREN), null, | 
| 4345 _createSyntheticToken(TokenType.CLOSE_PAREN)); | 4346 _createSyntheticToken(TokenType.CLOSE_PAREN)); | 
| 4346 } | 4347 } | 
| 4347 | 4348 | 
| 4348 /** | 4349 /** | 
| 4350 * Parse an assert within a constructor's initializer list. Return the assert. | |
| 4351 * | |
| 4352 * This method assumes that the current token matches `Keyword.ASSERT`. | |
| 4353 * | |
| 4354 * assertInitializer ::= | |
| 4355 * 'assert' '(' expression [',' expression] ')' | |
| 4356 */ | |
| 4357 void _parseAssertInitializer() { | |
| 4358 // return AssertInitializer | |
| 
 
scheglov
2016/08/27 00:06:45
I don't quite understand what this comment means.
 
Brian Wilkerson
2016/08/27 00:32:44
Done
It was a reminder to "Capture the syntax in
 
 | |
| 4359 Token keyword = getAndAdvance(); | |
| 4360 Token leftParen = _expect(TokenType.OPEN_PAREN); | |
| 4361 Expression expression = parseExpression2(); | |
| 4362 Token comma; | |
| 4363 Expression message; | |
| 4364 if (_matches(TokenType.COMMA)) { | |
| 4365 comma = getAndAdvance(); | |
| 4366 message = parseExpression2(); | |
| 4367 } | |
| 4368 Token rightParen = _expect(TokenType.CLOSE_PAREN); | |
| 4369 // return new AssertInitializer( | |
| 4370 // keyword, leftParen, expression, comma, message, rightParen); | |
| 4371 } | |
| 4372 | |
| 4373 /** | |
| 4349 * Parse an assert statement. Return the assert statement. | 4374 * Parse an assert statement. Return the assert statement. | 
| 4350 * | 4375 * | 
| 4351 * This method assumes that the current token matches `Keyword.ASSERT`. | 4376 * This method assumes that the current token matches `Keyword.ASSERT`. | 
| 4352 * | 4377 * | 
| 4353 * assertStatement ::= | 4378 * assertStatement ::= | 
| 4354 * 'assert' '(' expression [',' expression] ')' ';' | 4379 * 'assert' '(' expression [',' expression] ')' ';' | 
| 4355 */ | 4380 */ | 
| 4356 AssertStatement _parseAssertStatement() { | 4381 AssertStatement _parseAssertStatement() { | 
| 4357 Token keyword = getAndAdvance(); | 4382 Token keyword = getAndAdvance(); | 
| 4358 Token leftParen = _expect(TokenType.OPEN_PAREN); | 4383 Token leftParen = _expect(TokenType.OPEN_PAREN); | 
| (...skipping 1136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5495 bodyAllowed = false; | 5520 bodyAllowed = false; | 
| 5496 initializers.add(_parseRedirectingConstructorInvocation(true)); | 5521 initializers.add(_parseRedirectingConstructorInvocation(true)); | 
| 5497 } else { | 5522 } else { | 
| 5498 initializers.add(_parseConstructorFieldInitializer(true)); | 5523 initializers.add(_parseConstructorFieldInitializer(true)); | 
| 5499 } | 5524 } | 
| 5500 } else if (keyword == Keyword.SUPER) { | 5525 } else if (keyword == Keyword.SUPER) { | 
| 5501 initializers.add(_parseSuperConstructorInvocation()); | 5526 initializers.add(_parseSuperConstructorInvocation()); | 
| 5502 } else if (_matches(TokenType.OPEN_CURLY_BRACKET) || | 5527 } else if (_matches(TokenType.OPEN_CURLY_BRACKET) || | 
| 5503 _matches(TokenType.FUNCTION)) { | 5528 _matches(TokenType.FUNCTION)) { | 
| 5504 _reportErrorForCurrentToken(ParserErrorCode.MISSING_INITIALIZER); | 5529 _reportErrorForCurrentToken(ParserErrorCode.MISSING_INITIALIZER); | 
| 5530 } else if (_matchesKeyword(Keyword.ASSERT)) { | |
| 5531 _parseAssertInitializer(); | |
| 5505 } else { | 5532 } else { | 
| 5506 initializers.add(_parseConstructorFieldInitializer(false)); | 5533 initializers.add(_parseConstructorFieldInitializer(false)); | 
| 5507 } | 5534 } | 
| 5508 } while (_optional(TokenType.COMMA)); | 5535 } while (_optional(TokenType.COMMA)); | 
| 5509 if (factoryKeyword != null) { | 5536 if (factoryKeyword != null) { | 
| 5510 _reportErrorForToken( | 5537 _reportErrorForToken( | 
| 5511 ParserErrorCode.FACTORY_WITH_INITIALIZERS, factoryKeyword); | 5538 ParserErrorCode.FACTORY_WITH_INITIALIZERS, factoryKeyword); | 
| 5512 } | 5539 } | 
| 5513 } | 5540 } | 
| 5514 ConstructorName redirectedConstructor = null; | 5541 ConstructorName redirectedConstructor = null; | 
| (...skipping 2760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8275 _reportErrorForCurrentToken(ParserErrorCode.EXPECTED_CASE_OR_DEFAULT); | 8302 _reportErrorForCurrentToken(ParserErrorCode.EXPECTED_CASE_OR_DEFAULT); | 
| 8276 bool atEndOrNextMember() { | 8303 bool atEndOrNextMember() { | 
| 8277 TokenType type = _currentToken.type; | 8304 TokenType type = _currentToken.type; | 
| 8278 if (type == TokenType.EOF || | 8305 if (type == TokenType.EOF || | 
| 8279 type == TokenType.CLOSE_CURLY_BRACKET) { | 8306 type == TokenType.CLOSE_CURLY_BRACKET) { | 
| 8280 return true; | 8307 return true; | 
| 8281 } | 8308 } | 
| 8282 Keyword keyword = _currentToken.keyword; | 8309 Keyword keyword = _currentToken.keyword; | 
| 8283 return keyword == Keyword.CASE || keyword == Keyword.DEFAULT; | 8310 return keyword == Keyword.CASE || keyword == Keyword.DEFAULT; | 
| 8284 } | 8311 } | 
| 8312 | |
| 8285 while (!atEndOrNextMember()) { | 8313 while (!atEndOrNextMember()) { | 
| 8286 _advance(); | 8314 _advance(); | 
| 8287 } | 8315 } | 
| 8288 } | 8316 } | 
| 8289 type = _currentToken.type; | 8317 type = _currentToken.type; | 
| 8290 } | 8318 } | 
| 8291 Token rightBracket = _expect(TokenType.CLOSE_CURLY_BRACKET); | 8319 Token rightBracket = _expect(TokenType.CLOSE_CURLY_BRACKET); | 
| 8292 return new SwitchStatement(keyword, leftParenthesis, expression, | 8320 return new SwitchStatement(keyword, leftParenthesis, expression, | 
| 8293 rightParenthesis, leftBracket, members, rightBracket); | 8321 rightParenthesis, leftBracket, members, rightBracket); | 
| 8294 } finally { | 8322 } finally { | 
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8618 bool isValidInUri(Token token) { | 8646 bool isValidInUri(Token token) { | 
| 8619 TokenType type = token.type; | 8647 TokenType type = token.type; | 
| 8620 return type == TokenType.COLON || | 8648 return type == TokenType.COLON || | 
| 8621 type == TokenType.SLASH || | 8649 type == TokenType.SLASH || | 
| 8622 type == TokenType.PERIOD || | 8650 type == TokenType.PERIOD || | 
| 8623 type == TokenType.PERIOD_PERIOD || | 8651 type == TokenType.PERIOD_PERIOD || | 
| 8624 type == TokenType.PERIOD_PERIOD_PERIOD || | 8652 type == TokenType.PERIOD_PERIOD_PERIOD || | 
| 8625 type == TokenType.INT || | 8653 type == TokenType.INT || | 
| 8626 type == TokenType.DOUBLE; | 8654 type == TokenType.DOUBLE; | 
| 8627 } | 8655 } | 
| 8656 | |
| 8628 while ((_tokenMatchesIdentifier(token) && !isKeywordAfterUri(token)) || | 8657 while ((_tokenMatchesIdentifier(token) && !isKeywordAfterUri(token)) || | 
| 8629 isValidInUri(token)) { | 8658 isValidInUri(token)) { | 
| 8630 token = token.next; | 8659 token = token.next; | 
| 8631 } | 8660 } | 
| 8632 if (_tokenMatches(token, TokenType.SEMICOLON) || | 8661 if (_tokenMatches(token, TokenType.SEMICOLON) || | 
| 8633 isKeywordAfterUri(token)) { | 8662 isKeywordAfterUri(token)) { | 
| 8634 Token endToken = token.previous; | 8663 Token endToken = token.previous; | 
| 8635 token = _currentToken; | 8664 token = _currentToken; | 
| 8636 int endOffset = token.end; | 8665 int endOffset = token.end; | 
| 8637 StringBuffer buffer = new StringBuffer(); | 8666 StringBuffer buffer = new StringBuffer(); | 
| (...skipping 1841 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10479 */ | 10508 */ | 
| 10480 const ParserErrorCode(String name, String message, [String correction]) | 10509 const ParserErrorCode(String name, String message, [String correction]) | 
| 10481 : super(name, message, correction); | 10510 : super(name, message, correction); | 
| 10482 | 10511 | 
| 10483 @override | 10512 @override | 
| 10484 ErrorSeverity get errorSeverity => ErrorSeverity.ERROR; | 10513 ErrorSeverity get errorSeverity => ErrorSeverity.ERROR; | 
| 10485 | 10514 | 
| 10486 @override | 10515 @override | 
| 10487 ErrorType get type => ErrorType.SYNTACTIC_ERROR; | 10516 ErrorType get type => ErrorType.SYNTACTIC_ERROR; | 
| 10488 } | 10517 } | 
| OLD | NEW |