| 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 4250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4261 /** | 4261 /** |
| 4262 * Return `true` if the current token appears to be the beginning of a switch | 4262 * Return `true` if the current token appears to be the beginning of a switch |
| 4263 * member. | 4263 * member. |
| 4264 */ | 4264 */ |
| 4265 bool _isSwitchMember() { | 4265 bool _isSwitchMember() { |
| 4266 Token token = _currentToken; | 4266 Token token = _currentToken; |
| 4267 while (_tokenMatches(token, TokenType.IDENTIFIER) && | 4267 while (_tokenMatches(token, TokenType.IDENTIFIER) && |
| 4268 _tokenMatches(token.next, TokenType.COLON)) { | 4268 _tokenMatches(token.next, TokenType.COLON)) { |
| 4269 token = token.next.next; | 4269 token = token.next.next; |
| 4270 } | 4270 } |
| 4271 if (token.type == TokenType.KEYWORD) { | 4271 Keyword keyword = token.keyword; |
| 4272 Keyword keyword = (token as KeywordToken).keyword; | 4272 return keyword == Keyword.CASE || keyword == Keyword.DEFAULT; |
| 4273 return keyword == Keyword.CASE || keyword == Keyword.DEFAULT; | |
| 4274 } | |
| 4275 return false; | |
| 4276 } | 4273 } |
| 4277 | 4274 |
| 4278 /** | 4275 /** |
| 4279 * Return `true` if the [startToken] appears to be the first token of a type | 4276 * Return `true` if the [startToken] appears to be the first token of a type |
| 4280 * name that is followed by a variable or field formal parameter. | 4277 * name that is followed by a variable or field formal parameter. |
| 4281 */ | 4278 */ |
| 4282 bool _isTypedIdentifier(Token startToken) { | 4279 bool _isTypedIdentifier(Token startToken) { |
| 4283 Token token = _skipReturnType(startToken); | 4280 Token token = _skipReturnType(startToken); |
| 4284 if (token == null) { | 4281 if (token == null) { |
| 4285 return false; | 4282 return false; |
| (...skipping 2009 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6295 * | 6292 * |
| 6296 * functionDeclarationStatement ::= | 6293 * functionDeclarationStatement ::= |
| 6297 * functionSignature functionBody | 6294 * functionSignature functionBody |
| 6298 */ | 6295 */ |
| 6299 Statement _parseFunctionDeclarationStatementAfterReturnType( | 6296 Statement _parseFunctionDeclarationStatementAfterReturnType( |
| 6300 CommentAndMetadata commentAndMetadata, TypeName returnType) { | 6297 CommentAndMetadata commentAndMetadata, TypeName returnType) { |
| 6301 FunctionDeclaration declaration = | 6298 FunctionDeclaration declaration = |
| 6302 _parseFunctionDeclaration(commentAndMetadata, null, returnType); | 6299 _parseFunctionDeclaration(commentAndMetadata, null, returnType); |
| 6303 Token propertyKeyword = declaration.propertyKeyword; | 6300 Token propertyKeyword = declaration.propertyKeyword; |
| 6304 if (propertyKeyword != null) { | 6301 if (propertyKeyword != null) { |
| 6305 if ((propertyKeyword as KeywordToken).keyword == Keyword.GET) { | 6302 if (propertyKeyword.keyword == Keyword.GET) { |
| 6306 _reportErrorForToken( | 6303 _reportErrorForToken( |
| 6307 ParserErrorCode.GETTER_IN_FUNCTION, propertyKeyword); | 6304 ParserErrorCode.GETTER_IN_FUNCTION, propertyKeyword); |
| 6308 } else { | 6305 } else { |
| 6309 _reportErrorForToken( | 6306 _reportErrorForToken( |
| 6310 ParserErrorCode.SETTER_IN_FUNCTION, propertyKeyword); | 6307 ParserErrorCode.SETTER_IN_FUNCTION, propertyKeyword); |
| 6311 } | 6308 } |
| 6312 } | 6309 } |
| 6313 return new FunctionDeclarationStatement(declaration); | 6310 return new FunctionDeclarationStatement(declaration); |
| 6314 } | 6311 } |
| 6315 | 6312 |
| (...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7030 if (_matches(TokenType.OPEN_CURLY_BRACKET)) { | 7027 if (_matches(TokenType.OPEN_CURLY_BRACKET)) { |
| 7031 if (_tokenMatches(_peek(), TokenType.STRING)) { | 7028 if (_tokenMatches(_peek(), TokenType.STRING)) { |
| 7032 Token afterString = _skipStringLiteral(_currentToken.next); | 7029 Token afterString = _skipStringLiteral(_currentToken.next); |
| 7033 if (afterString != null && afterString.type == TokenType.COLON) { | 7030 if (afterString != null && afterString.type == TokenType.COLON) { |
| 7034 return new ExpressionStatement( | 7031 return new ExpressionStatement( |
| 7035 parseExpression2(), _expect(TokenType.SEMICOLON)); | 7032 parseExpression2(), _expect(TokenType.SEMICOLON)); |
| 7036 } | 7033 } |
| 7037 } | 7034 } |
| 7038 return parseBlock(); | 7035 return parseBlock(); |
| 7039 } else if (_matches(TokenType.KEYWORD) && | 7036 } else if (_matches(TokenType.KEYWORD) && |
| 7040 !(_currentToken as KeywordToken).keyword.isPseudoKeyword) { | 7037 !_currentToken.keyword.isPseudoKeyword) { |
| 7041 Keyword keyword = (_currentToken as KeywordToken).keyword; | 7038 Keyword keyword = _currentToken.keyword; |
| 7042 // TODO(jwren) compute some metrics to figure out a better order for this | 7039 // TODO(jwren) compute some metrics to figure out a better order for this |
| 7043 // if-then sequence to optimize performance | 7040 // if-then sequence to optimize performance |
| 7044 if (keyword == Keyword.ASSERT) { | 7041 if (keyword == Keyword.ASSERT) { |
| 7045 return _parseAssertStatement(); | 7042 return _parseAssertStatement(); |
| 7046 } else if (keyword == Keyword.BREAK) { | 7043 } else if (keyword == Keyword.BREAK) { |
| 7047 return _parseBreakStatement(); | 7044 return _parseBreakStatement(); |
| 7048 } else if (keyword == Keyword.CONTINUE) { | 7045 } else if (keyword == Keyword.CONTINUE) { |
| 7049 return _parseContinueStatement(); | 7046 return _parseContinueStatement(); |
| 7050 } else if (keyword == Keyword.DO) { | 7047 } else if (keyword == Keyword.DO) { |
| 7051 return _parseDoStatement(); | 7048 return _parseDoStatement(); |
| (...skipping 1792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8844 * include built-in identifiers (pseudo-keywords). | 8841 * include built-in identifiers (pseudo-keywords). |
| 8845 */ | 8842 */ |
| 8846 bool _tokenMatchesIdentifier(Token token) => | 8843 bool _tokenMatchesIdentifier(Token token) => |
| 8847 _tokenMatches(token, TokenType.IDENTIFIER) || | 8844 _tokenMatches(token, TokenType.IDENTIFIER) || |
| 8848 _tokenMatchesPseudoKeyword(token); | 8845 _tokenMatchesPseudoKeyword(token); |
| 8849 | 8846 |
| 8850 /** | 8847 /** |
| 8851 * Return `true` if the given [token] matches the given [keyword]. | 8848 * Return `true` if the given [token] matches the given [keyword]. |
| 8852 */ | 8849 */ |
| 8853 bool _tokenMatchesKeyword(Token token, Keyword keyword) => | 8850 bool _tokenMatchesKeyword(Token token, Keyword keyword) => |
| 8854 token.type == TokenType.KEYWORD && | 8851 token.keyword == keyword; |
| 8855 (token as KeywordToken).keyword == keyword; | |
| 8856 | 8852 |
| 8857 /** | 8853 /** |
| 8858 * Return `true` if the given [token] matches a pseudo keyword. | 8854 * Return `true` if the given [token] matches a pseudo keyword. |
| 8859 */ | 8855 */ |
| 8860 bool _tokenMatchesPseudoKeyword(Token token) => | 8856 bool _tokenMatchesPseudoKeyword(Token token) => |
| 8861 _tokenMatches(token, TokenType.KEYWORD) && | 8857 token.keyword?.isPseudoKeyword ?? false; |
| 8862 (token as KeywordToken).keyword.isPseudoKeyword; | |
| 8863 | 8858 |
| 8864 /** | 8859 /** |
| 8865 * Return `true` if the given [token] matches the given [identifier]. | 8860 * Return `true` if the given [token] matches the given [identifier]. |
| 8866 */ | 8861 */ |
| 8867 bool _tokenMatchesString(Token token, String identifier) => | 8862 bool _tokenMatchesString(Token token, String identifier) => |
| 8868 token.type == TokenType.IDENTIFIER && token.lexeme == identifier; | 8863 token.type == TokenType.IDENTIFIER && token.lexeme == identifier; |
| 8869 | 8864 |
| 8870 /** | 8865 /** |
| 8871 * Translate the characters at the given [index] in the given [lexeme], | 8866 * Translate the characters at the given [index] in the given [lexeme], |
| 8872 * appending the translated character to the given [buffer]. The index is | 8867 * appending the translated character to the given [buffer]. The index is |
| (...skipping 1104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9977 */ | 9972 */ |
| 9978 const ParserErrorCode(String name, String message, [String correction]) | 9973 const ParserErrorCode(String name, String message, [String correction]) |
| 9979 : super(name, message, correction); | 9974 : super(name, message, correction); |
| 9980 | 9975 |
| 9981 @override | 9976 @override |
| 9982 ErrorSeverity get errorSeverity => ErrorSeverity.ERROR; | 9977 ErrorSeverity get errorSeverity => ErrorSeverity.ERROR; |
| 9983 | 9978 |
| 9984 @override | 9979 @override |
| 9985 ErrorType get type => ErrorType.SYNTACTIC_ERROR; | 9980 ErrorType get type => ErrorType.SYNTACTIC_ERROR; |
| 9986 } | 9981 } |
| OLD | NEW |