| 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 4034 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4045 .matchesAny([TokenType.OPEN_CURLY_BRACKET, TokenType.FUNCTION])) { | 4045 .matchesAny([TokenType.OPEN_CURLY_BRACKET, TokenType.FUNCTION])) { |
| 4046 return true; | 4046 return true; |
| 4047 } | 4047 } |
| 4048 String lexeme = afterParameters.lexeme; | 4048 String lexeme = afterParameters.lexeme; |
| 4049 return lexeme == ASYNC || lexeme == SYNC; | 4049 return lexeme == ASYNC || lexeme == SYNC; |
| 4050 } | 4050 } |
| 4051 | 4051 |
| 4052 /** | 4052 /** |
| 4053 * Return `true` if the given [character] is a valid hexadecimal digit. | 4053 * Return `true` if the given [character] is a valid hexadecimal digit. |
| 4054 */ | 4054 */ |
| 4055 bool _isHexDigit(int character) => (0x30 <= character && character <= 0x39) || | 4055 bool _isHexDigit(int character) => |
| 4056 (0x30 <= character && character <= 0x39) || |
| 4056 (0x41 <= character && character <= 0x46) || | 4057 (0x41 <= character && character <= 0x46) || |
| 4057 (0x61 <= character && character <= 0x66); | 4058 (0x61 <= character && character <= 0x66); |
| 4058 | 4059 |
| 4059 /** | 4060 /** |
| 4060 * Return `true` if the current token is the first token in an initialized | 4061 * Return `true` if the current token is the first token in an initialized |
| 4061 * variable declaration rather than an expression. This method assumes that we | 4062 * variable declaration rather than an expression. This method assumes that we |
| 4062 * have already skipped past any metadata that might be associated with the | 4063 * have already skipped past any metadata that might be associated with the |
| 4063 * declaration. | 4064 * declaration. |
| 4064 * | 4065 * |
| 4065 * initializedVariableDeclaration ::= | 4066 * initializedVariableDeclaration ::= |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4319 * Return `true` if the current token matches the given [keyword]. | 4320 * Return `true` if the current token matches the given [keyword]. |
| 4320 */ | 4321 */ |
| 4321 bool _matchesKeyword(Keyword keyword) => | 4322 bool _matchesKeyword(Keyword keyword) => |
| 4322 _tokenMatchesKeyword(_currentToken, keyword); | 4323 _tokenMatchesKeyword(_currentToken, keyword); |
| 4323 | 4324 |
| 4324 /** | 4325 /** |
| 4325 * Return `true` if the current token matches the given [identifier]. | 4326 * Return `true` if the current token matches the given [identifier]. |
| 4326 */ | 4327 */ |
| 4327 bool _matchesString(String identifier) => | 4328 bool _matchesString(String identifier) => |
| 4328 _currentToken.type == TokenType.IDENTIFIER && | 4329 _currentToken.type == TokenType.IDENTIFIER && |
| 4329 _currentToken.lexeme == identifier; | 4330 _currentToken.lexeme == identifier; |
| 4330 | 4331 |
| 4331 /** | 4332 /** |
| 4332 * If the current token has the given [type], then advance to the next token | 4333 * If the current token has the given [type], then advance to the next token |
| 4333 * and return `true`. Otherwise, return `false` without advancing. This method | 4334 * and return `true`. Otherwise, return `false` without advancing. This method |
| 4334 * should not be invoked with an argument value of [TokenType.GT]. | 4335 * should not be invoked with an argument value of [TokenType.GT]. |
| 4335 */ | 4336 */ |
| 4336 bool _optional(TokenType type) { | 4337 bool _optional(TokenType type) { |
| 4337 if (_matches(type)) { | 4338 if (_matches(type)) { |
| 4338 _advance(); | 4339 _advance(); |
| 4339 return true; | 4340 return true; |
| (...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5035 * '[' 'new'? qualified ']' libraryReference? | 5036 * '[' 'new'? qualified ']' libraryReference? |
| 5036 * | 5037 * |
| 5037 * libraryReference ::= | 5038 * libraryReference ::= |
| 5038 * '(' stringLiteral ')' | 5039 * '(' stringLiteral ')' |
| 5039 */ | 5040 */ |
| 5040 List<CommentReference> _parseCommentReferences( | 5041 List<CommentReference> _parseCommentReferences( |
| 5041 List<DocumentationCommentToken> tokens) { | 5042 List<DocumentationCommentToken> tokens) { |
| 5042 List<CommentReference> references = new List<CommentReference>(); | 5043 List<CommentReference> references = new List<CommentReference>(); |
| 5043 for (DocumentationCommentToken token in tokens) { | 5044 for (DocumentationCommentToken token in tokens) { |
| 5044 String comment = token.lexeme; | 5045 String comment = token.lexeme; |
| 5046 comment = _removeGitHubCodeBlocks(comment); |
| 5045 int length = comment.length; | 5047 int length = comment.length; |
| 5046 List<List<int>> codeBlockRanges = _getCodeBlockRanges(comment); | 5048 List<List<int>> codeBlockRanges = _getCodeBlockRanges(comment); |
| 5047 int leftIndex = comment.indexOf('['); | 5049 int leftIndex = comment.indexOf('['); |
| 5048 while (leftIndex >= 0 && leftIndex + 1 < length) { | 5050 while (leftIndex >= 0 && leftIndex + 1 < length) { |
| 5049 List<int> range = _findRange(codeBlockRanges, leftIndex); | 5051 List<int> range = _findRange(codeBlockRanges, leftIndex); |
| 5050 if (range == null) { | 5052 if (range == null) { |
| 5051 int nameOffset = token.offset + leftIndex + 1; | 5053 int nameOffset = token.offset + leftIndex + 1; |
| 5052 int rightIndex = JavaString.indexOf(comment, ']', leftIndex); | 5054 int rightIndex = JavaString.indexOf(comment, ']', leftIndex); |
| 5053 if (rightIndex >= 0) { | 5055 if (rightIndex >= 0) { |
| 5054 int firstChar = comment.codeUnitAt(leftIndex + 1); | 5056 int firstChar = comment.codeUnitAt(leftIndex + 1); |
| (...skipping 2946 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8001 return _parseAwaitExpression(); | 8003 return _parseAwaitExpression(); |
| 8002 } | 8004 } |
| 8003 return _parsePostfixExpression(); | 8005 return _parsePostfixExpression(); |
| 8004 } | 8006 } |
| 8005 | 8007 |
| 8006 /** | 8008 /** |
| 8007 * Parse a string literal representing a URI. Return the string literal that | 8009 * Parse a string literal representing a URI. Return the string literal that |
| 8008 * was parsed. | 8010 * was parsed. |
| 8009 */ | 8011 */ |
| 8010 StringLiteral _parseUri() { | 8012 StringLiteral _parseUri() { |
| 8011 bool iskeywordAfterUri(Token token) => token.lexeme == Keyword.AS.syntax || | 8013 bool iskeywordAfterUri(Token token) => |
| 8014 token.lexeme == Keyword.AS.syntax || |
| 8012 token.lexeme == _HIDE || | 8015 token.lexeme == _HIDE || |
| 8013 token.lexeme == _SHOW; | 8016 token.lexeme == _SHOW; |
| 8014 if (!_matches(TokenType.STRING) && | 8017 if (!_matches(TokenType.STRING) && |
| 8015 !_matches(TokenType.SEMICOLON) && | 8018 !_matches(TokenType.SEMICOLON) && |
| 8016 !iskeywordAfterUri(_currentToken)) { | 8019 !iskeywordAfterUri(_currentToken)) { |
| 8017 // Attempt to recover in the case where the URI was not enclosed in | 8020 // Attempt to recover in the case where the URI was not enclosed in |
| 8018 // quotes. | 8021 // quotes. |
| 8019 Token token = _currentToken; | 8022 Token token = _currentToken; |
| 8020 while ((_tokenMatchesIdentifier(token) && !iskeywordAfterUri(token)) || | 8023 while ((_tokenMatchesIdentifier(token) && !iskeywordAfterUri(token)) || |
| 8021 _tokenMatches(token, TokenType.COLON) || | 8024 _tokenMatches(token, TokenType.COLON) || |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8223 * is the current token, `1` is the next token, etc. | 8226 * is the current token, `1` is the next token, etc. |
| 8224 */ | 8227 */ |
| 8225 Token _peekAt(int distance) { | 8228 Token _peekAt(int distance) { |
| 8226 Token token = _currentToken; | 8229 Token token = _currentToken; |
| 8227 for (int i = 0; i < distance; i++) { | 8230 for (int i = 0; i < distance; i++) { |
| 8228 token = token.next; | 8231 token = token.next; |
| 8229 } | 8232 } |
| 8230 return token; | 8233 return token; |
| 8231 } | 8234 } |
| 8232 | 8235 |
| 8236 String _removeGitHubCodeBlocks(String comment) { |
| 8237 int index = 0; |
| 8238 while (true) { |
| 8239 int beginIndex = comment.indexOf('`', index); |
| 8240 if (beginIndex == -1) { |
| 8241 break; |
| 8242 } |
| 8243 int endIndex = comment.indexOf('`', beginIndex + 1); |
| 8244 if (endIndex == -1) { |
| 8245 break; |
| 8246 } |
| 8247 comment = comment.substring(0, beginIndex + 1) + |
| 8248 ' ' * (endIndex - beginIndex - 1) + |
| 8249 comment.substring(endIndex); |
| 8250 index = endIndex + 1; |
| 8251 } |
| 8252 return comment; |
| 8253 } |
| 8254 |
| 8233 /** | 8255 /** |
| 8234 * Report the given [error]. | 8256 * Report the given [error]. |
| 8235 */ | 8257 */ |
| 8236 void _reportError(AnalysisError error) { | 8258 void _reportError(AnalysisError error) { |
| 8237 if (_errorListenerLock != 0) { | 8259 if (_errorListenerLock != 0) { |
| 8238 return; | 8260 return; |
| 8239 } | 8261 } |
| 8240 _errorListener.onError(error); | 8262 _errorListener.onError(error); |
| 8241 } | 8263 } |
| 8242 | 8264 |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8734 * Return `true` if the given [token] has the given [type]. | 8756 * Return `true` if the given [token] has the given [type]. |
| 8735 */ | 8757 */ |
| 8736 bool _tokenMatches(Token token, TokenType type) => token.type == type; | 8758 bool _tokenMatches(Token token, TokenType type) => token.type == type; |
| 8737 | 8759 |
| 8738 /** | 8760 /** |
| 8739 * Return `true` if the given [token] is a valid identifier. Valid identifiers | 8761 * Return `true` if the given [token] is a valid identifier. Valid identifiers |
| 8740 * include built-in identifiers (pseudo-keywords). | 8762 * include built-in identifiers (pseudo-keywords). |
| 8741 */ | 8763 */ |
| 8742 bool _tokenMatchesIdentifier(Token token) => | 8764 bool _tokenMatchesIdentifier(Token token) => |
| 8743 _tokenMatches(token, TokenType.IDENTIFIER) || | 8765 _tokenMatches(token, TokenType.IDENTIFIER) || |
| 8744 _tokenMatchesPseudoKeyword(token); | 8766 _tokenMatchesPseudoKeyword(token); |
| 8745 | 8767 |
| 8746 /** | 8768 /** |
| 8747 * Return `true` if the given [token] matches the given [keyword]. | 8769 * Return `true` if the given [token] matches the given [keyword]. |
| 8748 */ | 8770 */ |
| 8749 bool _tokenMatchesKeyword(Token token, Keyword keyword) => | 8771 bool _tokenMatchesKeyword(Token token, Keyword keyword) => |
| 8750 token.type == TokenType.KEYWORD && | 8772 token.type == TokenType.KEYWORD && |
| 8751 (token as KeywordToken).keyword == keyword; | 8773 (token as KeywordToken).keyword == keyword; |
| 8752 | 8774 |
| 8753 /** | 8775 /** |
| 8754 * Return `true` if the given [token] matches a pseudo keyword. | 8776 * Return `true` if the given [token] matches a pseudo keyword. |
| 8755 */ | 8777 */ |
| 8756 bool _tokenMatchesPseudoKeyword(Token token) => | 8778 bool _tokenMatchesPseudoKeyword(Token token) => |
| 8757 _tokenMatches(token, TokenType.KEYWORD) && | 8779 _tokenMatches(token, TokenType.KEYWORD) && |
| 8758 (token as KeywordToken).keyword.isPseudoKeyword; | 8780 (token as KeywordToken).keyword.isPseudoKeyword; |
| 8759 | 8781 |
| 8760 /** | 8782 /** |
| 8761 * Return `true` if the given [token] matches the given [identifier]. | 8783 * Return `true` if the given [token] matches the given [identifier]. |
| 8762 */ | 8784 */ |
| 8763 bool _tokenMatchesString(Token token, String identifier) => | 8785 bool _tokenMatchesString(Token token, String identifier) => |
| 8764 token.type == TokenType.IDENTIFIER && token.lexeme == identifier; | 8786 token.type == TokenType.IDENTIFIER && token.lexeme == identifier; |
| 8765 | 8787 |
| 8766 /** | 8788 /** |
| 8767 * Translate the characters at the given [index] in the given [lexeme], | 8789 * Translate the characters at the given [index] in the given [lexeme], |
| 8768 * appending the translated character to the given [buffer]. The index is | 8790 * appending the translated character to the given [buffer]. The index is |
| (...skipping 2518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11287 } | 11309 } |
| 11288 | 11310 |
| 11289 /** | 11311 /** |
| 11290 * Copy resolution data from the [fromNode] to the [toNode]. | 11312 * Copy resolution data from the [fromNode] to the [toNode]. |
| 11291 */ | 11313 */ |
| 11292 static void copyResolutionData(AstNode fromNode, AstNode toNode) { | 11314 static void copyResolutionData(AstNode fromNode, AstNode toNode) { |
| 11293 ResolutionCopier copier = new ResolutionCopier(); | 11315 ResolutionCopier copier = new ResolutionCopier(); |
| 11294 copier._isEqualNodes(fromNode, toNode); | 11316 copier._isEqualNodes(fromNode, toNode); |
| 11295 } | 11317 } |
| 11296 } | 11318 } |
| OLD | NEW |