| 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 return true; | 151 return true; |
| 152 } | 152 } |
| 153 return needsSpace; | 153 return needsSpace; |
| 154 } | 154 } |
| 155 } | 155 } |
| 156 | 156 |
| 157 /** | 157 /** |
| 158 * A parser used to parse tokens into an AST structure. | 158 * A parser used to parse tokens into an AST structure. |
| 159 */ | 159 */ |
| 160 class Parser { | 160 class Parser { |
| 161 static String ASYNC = Keyword.ASYNC.syntax; | 161 static String ASYNC = "async"; |
| 162 | 162 |
| 163 static String _AWAIT = Keyword.AWAIT.syntax; | 163 static String _AWAIT = "await"; |
| 164 | 164 |
| 165 static String _HIDE = Keyword.HIDE.syntax; | 165 static String _HIDE = "hide"; |
| 166 | 166 |
| 167 static String _SHOW = Keyword.SHOW.syntax; | 167 static String _OF = "of"; |
| 168 | 168 |
| 169 static String SYNC = Keyword.SYNC.syntax; | 169 static String _ON = "on"; |
| 170 | 170 |
| 171 static String _YIELD = Keyword.YIELD.syntax; | 171 static String _NATIVE = "native"; |
| 172 |
| 173 static String _SHOW = "show"; |
| 174 |
| 175 static String SYNC = "sync"; |
| 176 |
| 177 static String _YIELD = "yield"; |
| 172 | 178 |
| 173 /** | 179 /** |
| 174 * The source being parsed. | 180 * The source being parsed. |
| 175 */ | 181 */ |
| 176 final Source _source; | 182 final Source _source; |
| 177 | 183 |
| 178 /** | 184 /** |
| 179 * The error listener that will be informed of any errors that are found | 185 * The error listener that will be informed of any errors that are found |
| 180 * during the parse. | 186 * during the parse. |
| 181 */ | 187 */ |
| (...skipping 994 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1176 } | 1182 } |
| 1177 } | 1183 } |
| 1178 if (withClause != null && extendsClause == null) { | 1184 if (withClause != null && extendsClause == null) { |
| 1179 _reportErrorForToken( | 1185 _reportErrorForToken( |
| 1180 ParserErrorCode.WITH_WITHOUT_EXTENDS, withClause.withKeyword); | 1186 ParserErrorCode.WITH_WITHOUT_EXTENDS, withClause.withKeyword); |
| 1181 } | 1187 } |
| 1182 // | 1188 // |
| 1183 // Look for and skip over the extra-lingual 'native' specification. | 1189 // Look for and skip over the extra-lingual 'native' specification. |
| 1184 // | 1190 // |
| 1185 NativeClause nativeClause = null; | 1191 NativeClause nativeClause = null; |
| 1186 if (_matchesKeyword(Keyword.NATIVE) && | 1192 if (_matchesString(_NATIVE) && _tokenMatches(_peek(), TokenType.STRING)) { |
| 1187 _tokenMatches(_peek(), TokenType.STRING)) { | |
| 1188 nativeClause = _parseNativeClause(); | 1193 nativeClause = _parseNativeClause(); |
| 1189 } | 1194 } |
| 1190 // | 1195 // |
| 1191 // Parse the body of the class. | 1196 // Parse the body of the class. |
| 1192 // | 1197 // |
| 1193 Token leftBracket = null; | 1198 Token leftBracket = null; |
| 1194 List<ClassMember> members = null; | 1199 List<ClassMember> members = null; |
| 1195 Token rightBracket = null; | 1200 Token rightBracket = null; |
| 1196 if (_matches(TokenType.OPEN_CURLY_BRACKET)) { | 1201 if (_matches(TokenType.OPEN_CURLY_BRACKET)) { |
| 1197 leftBracket = getAndAdvance(); | 1202 leftBracket = getAndAdvance(); |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1574 | 1579 |
| 1575 /** | 1580 /** |
| 1576 * Parse a single combinator. Return the combinator that was parsed, or `null` | 1581 * Parse a single combinator. Return the combinator that was parsed, or `null` |
| 1577 * if no combinator is found. | 1582 * if no combinator is found. |
| 1578 * | 1583 * |
| 1579 * combinator ::= | 1584 * combinator ::= |
| 1580 * 'show' identifier (',' identifier)* | 1585 * 'show' identifier (',' identifier)* |
| 1581 * | 'hide' identifier (',' identifier)* | 1586 * | 'hide' identifier (',' identifier)* |
| 1582 */ | 1587 */ |
| 1583 Combinator parseCombinator() { | 1588 Combinator parseCombinator() { |
| 1584 if (_matchesKeyword(Keyword.SHOW)) { | 1589 if (_matchesString(_SHOW)) { |
| 1585 return astFactory.showCombinator(getAndAdvance(), parseIdentifierList()); | 1590 return astFactory.showCombinator(getAndAdvance(), parseIdentifierList()); |
| 1586 } else if (_matchesKeyword(Keyword.HIDE)) { | 1591 } else if (_matchesString(_HIDE)) { |
| 1587 return astFactory.hideCombinator(getAndAdvance(), parseIdentifierList()); | 1592 return astFactory.hideCombinator(getAndAdvance(), parseIdentifierList()); |
| 1588 } | 1593 } |
| 1589 return null; | 1594 return null; |
| 1590 } | 1595 } |
| 1591 | 1596 |
| 1592 /** | 1597 /** |
| 1593 * Parse a list of combinators in a directive. Return the combinators that | 1598 * Parse a list of combinators in a directive. Return the combinators that |
| 1594 * were parsed, or `null` if there are no combinators. | 1599 * were parsed, or `null` if there are no combinators. |
| 1595 * | 1600 * |
| 1596 * combinator ::= | 1601 * combinator ::= |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1905 ParserErrorCode.MULTIPLE_LIBRARY_DIRECTIVES); | 1910 ParserErrorCode.MULTIPLE_LIBRARY_DIRECTIVES); |
| 1906 } else { | 1911 } else { |
| 1907 if (directives.length > 0) { | 1912 if (directives.length > 0) { |
| 1908 _reportErrorForCurrentToken( | 1913 _reportErrorForCurrentToken( |
| 1909 ParserErrorCode.LIBRARY_DIRECTIVE_NOT_FIRST); | 1914 ParserErrorCode.LIBRARY_DIRECTIVE_NOT_FIRST); |
| 1910 } | 1915 } |
| 1911 libraryDirectiveFound = true; | 1916 libraryDirectiveFound = true; |
| 1912 } | 1917 } |
| 1913 return parseLibraryDirective(commentAndMetadata); | 1918 return parseLibraryDirective(commentAndMetadata); |
| 1914 } else if (keyword == Keyword.PART) { | 1919 } else if (keyword == Keyword.PART) { |
| 1915 if (_tokenMatchesKeyword(_peek(), Keyword.OF)) { | 1920 if (_tokenMatchesString(_peek(), _OF)) { |
| 1916 partOfDirectiveFound = true; | 1921 partOfDirectiveFound = true; |
| 1917 return _parsePartOfDirective(commentAndMetadata); | 1922 return _parsePartOfDirective(commentAndMetadata); |
| 1918 } else { | 1923 } else { |
| 1919 partDirectiveFound = true; | 1924 partDirectiveFound = true; |
| 1920 return _parsePartDirective(commentAndMetadata); | 1925 return _parsePartDirective(commentAndMetadata); |
| 1921 } | 1926 } |
| 1922 } else { | 1927 } else { |
| 1923 // Internal error: this method should not have been invoked if the | 1928 // Internal error: this method should not have been invoked if the |
| 1924 // current token was something other than one of the above. | 1929 // current token was something other than one of the above. |
| 1925 throw new StateError( | 1930 throw new StateError( |
| (...skipping 1022 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2948 * | 2953 * |
| 2949 * forInitializerStatement ::= | 2954 * forInitializerStatement ::= |
| 2950 * localVariableDeclaration ';' | 2955 * localVariableDeclaration ';' |
| 2951 * | expression? ';' | 2956 * | expression? ';' |
| 2952 */ | 2957 */ |
| 2953 Statement parseForStatement() { | 2958 Statement parseForStatement() { |
| 2954 bool wasInLoop = _inLoop; | 2959 bool wasInLoop = _inLoop; |
| 2955 _inLoop = true; | 2960 _inLoop = true; |
| 2956 try { | 2961 try { |
| 2957 Token awaitKeyword = null; | 2962 Token awaitKeyword = null; |
| 2958 if (_matchesKeyword(Keyword.AWAIT)) { | 2963 if (_matchesString(_AWAIT)) { |
| 2959 awaitKeyword = getAndAdvance(); | 2964 awaitKeyword = getAndAdvance(); |
| 2960 } | 2965 } |
| 2961 Token forKeyword = _expectKeyword(Keyword.FOR); | 2966 Token forKeyword = _expectKeyword(Keyword.FOR); |
| 2962 Token leftParenthesis = _expect(TokenType.OPEN_PAREN); | 2967 Token leftParenthesis = _expect(TokenType.OPEN_PAREN); |
| 2963 VariableDeclarationList variableList = null; | 2968 VariableDeclarationList variableList = null; |
| 2964 Expression initialization = null; | 2969 Expression initialization = null; |
| 2965 if (!_matches(TokenType.SEMICOLON)) { | 2970 if (!_matches(TokenType.SEMICOLON)) { |
| 2966 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); | 2971 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); |
| 2967 if (_matchesIdentifier() && | 2972 if (_matchesIdentifier() && |
| 2968 (_tokenMatchesKeyword(_peek(), Keyword.IN) || | 2973 (_tokenMatchesKeyword(_peek(), Keyword.IN) || |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3111 if (type == TokenType.SEMICOLON) { | 3116 if (type == TokenType.SEMICOLON) { |
| 3112 if (!mayBeEmpty) { | 3117 if (!mayBeEmpty) { |
| 3113 _reportErrorForCurrentToken(emptyErrorCode); | 3118 _reportErrorForCurrentToken(emptyErrorCode); |
| 3114 } | 3119 } |
| 3115 return astFactory.emptyFunctionBody(getAndAdvance()); | 3120 return astFactory.emptyFunctionBody(getAndAdvance()); |
| 3116 } | 3121 } |
| 3117 Token keyword = null; | 3122 Token keyword = null; |
| 3118 Token star = null; | 3123 Token star = null; |
| 3119 bool foundAsync = false; | 3124 bool foundAsync = false; |
| 3120 bool foundSync = false; | 3125 bool foundSync = false; |
| 3121 if (type == TokenType.KEYWORD) { | 3126 if (type == TokenType.IDENTIFIER) { |
| 3122 String lexeme = _currentToken.lexeme; | 3127 String lexeme = _currentToken.lexeme; |
| 3123 if (lexeme == ASYNC) { | 3128 if (lexeme == ASYNC) { |
| 3124 foundAsync = true; | 3129 foundAsync = true; |
| 3125 keyword = getAndAdvance(); | 3130 keyword = getAndAdvance(); |
| 3126 if (_matches(TokenType.STAR)) { | 3131 if (_matches(TokenType.STAR)) { |
| 3127 star = getAndAdvance(); | 3132 star = getAndAdvance(); |
| 3128 _inGenerator = true; | 3133 _inGenerator = true; |
| 3129 } | 3134 } |
| 3130 type = _currentToken.type; | 3135 type = _currentToken.type; |
| 3131 _inAsync = true; | 3136 _inAsync = true; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3172 _reportErrorForToken( | 3177 _reportErrorForToken( |
| 3173 ParserErrorCode.MISSING_STAR_AFTER_SYNC, keyword); | 3178 ParserErrorCode.MISSING_STAR_AFTER_SYNC, keyword); |
| 3174 } | 3179 } |
| 3175 } | 3180 } |
| 3176 if (!_parseFunctionBodies) { | 3181 if (!_parseFunctionBodies) { |
| 3177 _skipBlock(); | 3182 _skipBlock(); |
| 3178 return astFactory | 3183 return astFactory |
| 3179 .emptyFunctionBody(_createSyntheticToken(TokenType.SEMICOLON)); | 3184 .emptyFunctionBody(_createSyntheticToken(TokenType.SEMICOLON)); |
| 3180 } | 3185 } |
| 3181 return astFactory.blockFunctionBody(keyword, star, parseBlock()); | 3186 return astFactory.blockFunctionBody(keyword, star, parseBlock()); |
| 3182 } else if (_matchesKeyword(Keyword.NATIVE)) { | 3187 } else if (_matchesString(_NATIVE)) { |
| 3183 Token nativeToken = getAndAdvance(); | 3188 Token nativeToken = getAndAdvance(); |
| 3184 StringLiteral stringLiteral = null; | 3189 StringLiteral stringLiteral = null; |
| 3185 if (_matches(TokenType.STRING)) { | 3190 if (_matches(TokenType.STRING)) { |
| 3186 stringLiteral = _parseStringLiteralUnchecked(); | 3191 stringLiteral = _parseStringLiteralUnchecked(); |
| 3187 } | 3192 } |
| 3188 return astFactory.nativeFunctionBody( | 3193 return astFactory.nativeFunctionBody( |
| 3189 nativeToken, stringLiteral, _expect(TokenType.SEMICOLON)); | 3194 nativeToken, stringLiteral, _expect(TokenType.SEMICOLON)); |
| 3190 } else { | 3195 } else { |
| 3191 // Invalid function body | 3196 // Invalid function body |
| 3192 _reportErrorForCurrentToken(emptyErrorCode); | 3197 _reportErrorForCurrentToken(emptyErrorCode); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3326 * optionalPositionalParameterTypes ::= | 3331 * optionalPositionalParameterTypes ::= |
| 3327 * '[' normalParameterTypes ','? ']' | 3332 * '[' normalParameterTypes ','? ']' |
| 3328 * namedParameterTypes ::= | 3333 * namedParameterTypes ::= |
| 3329 * '{' typedIdentifier (',' typedIdentifier)* ','? '}' | 3334 * '{' typedIdentifier (',' typedIdentifier)* ','? '}' |
| 3330 * typedIdentifier ::= | 3335 * typedIdentifier ::= |
| 3331 * type identifier | 3336 * type identifier |
| 3332 */ | 3337 */ |
| 3333 GenericFunctionType parseGenericFunctionTypeAfterReturnType( | 3338 GenericFunctionType parseGenericFunctionTypeAfterReturnType( |
| 3334 TypeAnnotation returnType) { | 3339 TypeAnnotation returnType) { |
| 3335 Token functionKeyword = null; | 3340 Token functionKeyword = null; |
| 3336 if (_matchesKeyword(Keyword.FUNCTION)) { | 3341 if (_matchesString('Function')) { |
| 3337 functionKeyword = getAndAdvance(); | 3342 functionKeyword = getAndAdvance(); |
| 3338 } else if (_matchesIdentifier()) { | 3343 } else if (_matchesIdentifier()) { |
| 3339 _reportErrorForCurrentToken(ParserErrorCode.NAMED_FUNCTION_TYPE); | 3344 _reportErrorForCurrentToken(ParserErrorCode.NAMED_FUNCTION_TYPE); |
| 3340 } else { | 3345 } else { |
| 3341 _reportErrorForCurrentToken(ParserErrorCode.MISSING_FUNCTION_KEYWORD); | 3346 _reportErrorForCurrentToken(ParserErrorCode.MISSING_FUNCTION_KEYWORD); |
| 3342 } | 3347 } |
| 3343 TypeParameterList typeParameters = null; | 3348 TypeParameterList typeParameters = null; |
| 3344 if (_matches(TokenType.LT)) { | 3349 if (_matches(TokenType.LT)) { |
| 3345 typeParameters = parseTypeParameterList(); | 3350 typeParameters = parseTypeParameterList(); |
| 3346 } | 3351 } |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3535 if (_matchesKeyword(Keyword.DEFERRED)) { | 3540 if (_matchesKeyword(Keyword.DEFERRED)) { |
| 3536 deferredToken = getAndAdvance(); | 3541 deferredToken = getAndAdvance(); |
| 3537 } | 3542 } |
| 3538 if (_matchesKeyword(Keyword.AS)) { | 3543 if (_matchesKeyword(Keyword.AS)) { |
| 3539 asToken = getAndAdvance(); | 3544 asToken = getAndAdvance(); |
| 3540 prefix = parseSimpleIdentifier(isDeclaration: true); | 3545 prefix = parseSimpleIdentifier(isDeclaration: true); |
| 3541 } else if (deferredToken != null) { | 3546 } else if (deferredToken != null) { |
| 3542 _reportErrorForCurrentToken( | 3547 _reportErrorForCurrentToken( |
| 3543 ParserErrorCode.MISSING_PREFIX_IN_DEFERRED_IMPORT); | 3548 ParserErrorCode.MISSING_PREFIX_IN_DEFERRED_IMPORT); |
| 3544 } else if (!_matches(TokenType.SEMICOLON) && | 3549 } else if (!_matches(TokenType.SEMICOLON) && |
| 3545 !_matchesKeyword(Keyword.SHOW) && | 3550 !_matchesString(_SHOW) && |
| 3546 !_matchesKeyword(Keyword.HIDE)) { | 3551 !_matchesString(_HIDE)) { |
| 3547 Token nextToken = _peek(); | 3552 Token nextToken = _peek(); |
| 3548 if (_tokenMatchesKeyword(nextToken, Keyword.AS) || | 3553 if (_tokenMatchesKeyword(nextToken, Keyword.AS) || |
| 3549 _tokenMatchesKeyword(nextToken, Keyword.SHOW) || | 3554 _tokenMatchesString(nextToken, _SHOW) || |
| 3550 _tokenMatchesKeyword(nextToken, Keyword.HIDE)) { | 3555 _tokenMatchesString(nextToken, _HIDE)) { |
| 3551 _reportErrorForCurrentToken( | 3556 _reportErrorForCurrentToken( |
| 3552 ParserErrorCode.UNEXPECTED_TOKEN, [_currentToken]); | 3557 ParserErrorCode.UNEXPECTED_TOKEN, [_currentToken]); |
| 3553 _advance(); | 3558 _advance(); |
| 3554 if (_matchesKeyword(Keyword.AS)) { | 3559 if (_matchesKeyword(Keyword.AS)) { |
| 3555 asToken = getAndAdvance(); | 3560 asToken = getAndAdvance(); |
| 3556 prefix = parseSimpleIdentifier(isDeclaration: true); | 3561 prefix = parseSimpleIdentifier(isDeclaration: true); |
| 3557 } | 3562 } |
| 3558 } | 3563 } |
| 3559 } | 3564 } |
| 3560 List<Combinator> combinators = parseCombinators(); | 3565 List<Combinator> combinators = parseCombinators(); |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3977 TokenType type = _currentToken.type; | 3982 TokenType type = _currentToken.type; |
| 3978 if (type == TokenType.OPEN_CURLY_BRACKET) { | 3983 if (type == TokenType.OPEN_CURLY_BRACKET) { |
| 3979 if (_tokenMatches(_peek(), TokenType.STRING)) { | 3984 if (_tokenMatches(_peek(), TokenType.STRING)) { |
| 3980 Token afterString = skipStringLiteral(_currentToken.next); | 3985 Token afterString = skipStringLiteral(_currentToken.next); |
| 3981 if (afterString != null && afterString.type == TokenType.COLON) { | 3986 if (afterString != null && afterString.type == TokenType.COLON) { |
| 3982 return astFactory.expressionStatement( | 3987 return astFactory.expressionStatement( |
| 3983 parseExpression2(), _expect(TokenType.SEMICOLON)); | 3988 parseExpression2(), _expect(TokenType.SEMICOLON)); |
| 3984 } | 3989 } |
| 3985 } | 3990 } |
| 3986 return parseBlock(); | 3991 return parseBlock(); |
| 3987 } else if (type == TokenType.KEYWORD && | 3992 } else if (type == TokenType.KEYWORD && !_currentToken.keyword.isBuiltIn) { |
| 3988 !_currentToken.keyword.isBuiltInOrPseudo) { | |
| 3989 Keyword keyword = _currentToken.keyword; | 3993 Keyword keyword = _currentToken.keyword; |
| 3990 // TODO(jwren) compute some metrics to figure out a better order for this | 3994 // TODO(jwren) compute some metrics to figure out a better order for this |
| 3991 // if-then sequence to optimize performance | 3995 // if-then sequence to optimize performance |
| 3992 if (keyword == Keyword.ASSERT) { | 3996 if (keyword == Keyword.ASSERT) { |
| 3993 return parseAssertStatement(); | 3997 return parseAssertStatement(); |
| 3994 } else if (keyword == Keyword.BREAK) { | 3998 } else if (keyword == Keyword.BREAK) { |
| 3995 return parseBreakStatement(); | 3999 return parseBreakStatement(); |
| 3996 } else if (keyword == Keyword.CONTINUE) { | 4000 } else if (keyword == Keyword.CONTINUE) { |
| 3997 return parseContinueStatement(); | 4001 return parseContinueStatement(); |
| 3998 } else if (keyword == Keyword.DO) { | 4002 } else if (keyword == Keyword.DO) { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4094 return astFactory.expressionStatement( | 4098 return astFactory.expressionStatement( |
| 4095 parseExpression2(), _expect(TokenType.SEMICOLON)); | 4099 parseExpression2(), _expect(TokenType.SEMICOLON)); |
| 4096 } else { | 4100 } else { |
| 4097 // | 4101 // |
| 4098 // We have found an error of some kind. Try to recover. | 4102 // We have found an error of some kind. Try to recover. |
| 4099 // | 4103 // |
| 4100 _reportErrorForCurrentToken(ParserErrorCode.MISSING_STATEMENT); | 4104 _reportErrorForCurrentToken(ParserErrorCode.MISSING_STATEMENT); |
| 4101 return astFactory | 4105 return astFactory |
| 4102 .emptyStatement(_createSyntheticToken(TokenType.SEMICOLON)); | 4106 .emptyStatement(_createSyntheticToken(TokenType.SEMICOLON)); |
| 4103 } | 4107 } |
| 4104 } else if (_inGenerator && _matchesKeyword(Keyword.YIELD)) { | 4108 } else if (_inGenerator && _matchesString(_YIELD)) { |
| 4105 return parseYieldStatement(); | 4109 return parseYieldStatement(); |
| 4106 } else if (_inAsync && _matchesKeyword(Keyword.AWAIT)) { | 4110 } else if (_inAsync && _matchesString(_AWAIT)) { |
| 4107 if (_tokenMatchesKeyword(_peek(), Keyword.FOR)) { | 4111 if (_tokenMatchesKeyword(_peek(), Keyword.FOR)) { |
| 4108 return parseForStatement(); | 4112 return parseForStatement(); |
| 4109 } | 4113 } |
| 4110 return astFactory.expressionStatement( | 4114 return astFactory.expressionStatement( |
| 4111 parseExpression2(), _expect(TokenType.SEMICOLON)); | 4115 parseExpression2(), _expect(TokenType.SEMICOLON)); |
| 4112 } else if (_matchesKeyword(Keyword.AWAIT) && | 4116 } else if (_matchesString(_AWAIT) && |
| 4113 _tokenMatchesKeyword(_peek(), Keyword.FOR)) { | 4117 _tokenMatchesKeyword(_peek(), Keyword.FOR)) { |
| 4114 Token awaitToken = _currentToken; | 4118 Token awaitToken = _currentToken; |
| 4115 Statement statement = parseForStatement(); | 4119 Statement statement = parseForStatement(); |
| 4116 if (statement is! ForStatement) { | 4120 if (statement is! ForStatement) { |
| 4117 _reportErrorForToken( | 4121 _reportErrorForToken( |
| 4118 CompileTimeErrorCode.ASYNC_FOR_IN_WRONG_CONTEXT, awaitToken); | 4122 CompileTimeErrorCode.ASYNC_FOR_IN_WRONG_CONTEXT, awaitToken); |
| 4119 } | 4123 } |
| 4120 return statement; | 4124 return statement; |
| 4121 } else if (type == TokenType.SEMICOLON) { | 4125 } else if (type == TokenType.SEMICOLON) { |
| 4122 return parseEmptyStatement(); | 4126 return parseEmptyStatement(); |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4295 * | 4299 * |
| 4296 * This method assumes that the current token matches `Keyword.PART`. | 4300 * This method assumes that the current token matches `Keyword.PART`. |
| 4297 * | 4301 * |
| 4298 * partDirective ::= | 4302 * partDirective ::= |
| 4299 * metadata 'part' stringLiteral ';' | 4303 * metadata 'part' stringLiteral ';' |
| 4300 * | 4304 * |
| 4301 * partOfDirective ::= | 4305 * partOfDirective ::= |
| 4302 * metadata 'part' 'of' identifier ';' | 4306 * metadata 'part' 'of' identifier ';' |
| 4303 */ | 4307 */ |
| 4304 Directive parsePartOrPartOfDirective(CommentAndMetadata commentAndMetadata) { | 4308 Directive parsePartOrPartOfDirective(CommentAndMetadata commentAndMetadata) { |
| 4305 if (_tokenMatchesKeyword(_peek(), Keyword.OF)) { | 4309 if (_tokenMatchesString(_peek(), _OF)) { |
| 4306 return _parsePartOfDirective(commentAndMetadata); | 4310 return _parsePartOfDirective(commentAndMetadata); |
| 4307 } | 4311 } |
| 4308 return _parsePartDirective(commentAndMetadata); | 4312 return _parsePartDirective(commentAndMetadata); |
| 4309 } | 4313 } |
| 4310 | 4314 |
| 4311 /** | 4315 /** |
| 4312 * Parse a postfix expression. Return the postfix expression that was parsed. | 4316 * Parse a postfix expression. Return the postfix expression that was parsed. |
| 4313 * | 4317 * |
| 4314 * postfixExpression ::= | 4318 * postfixExpression ::= |
| 4315 * assignableExpression postfixOperator | 4319 * assignableExpression postfixOperator |
| (...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4967 * 'catch' '(' identifier (',' identifier)? ')' | 4971 * 'catch' '(' identifier (',' identifier)? ')' |
| 4968 * | 4972 * |
| 4969 * finallyPart ::= | 4973 * finallyPart ::= |
| 4970 * 'finally' block | 4974 * 'finally' block |
| 4971 */ | 4975 */ |
| 4972 Statement parseTryStatement() { | 4976 Statement parseTryStatement() { |
| 4973 Token tryKeyword = getAndAdvance(); | 4977 Token tryKeyword = getAndAdvance(); |
| 4974 Block body = _parseBlockChecked(); | 4978 Block body = _parseBlockChecked(); |
| 4975 List<CatchClause> catchClauses = <CatchClause>[]; | 4979 List<CatchClause> catchClauses = <CatchClause>[]; |
| 4976 Block finallyClause = null; | 4980 Block finallyClause = null; |
| 4977 while (_matchesKeyword(Keyword.ON) || _matchesKeyword(Keyword.CATCH)) { | 4981 while (_matchesString(_ON) || _matchesKeyword(Keyword.CATCH)) { |
| 4978 Token onKeyword = null; | 4982 Token onKeyword = null; |
| 4979 TypeName exceptionType = null; | 4983 TypeName exceptionType = null; |
| 4980 if (_matchesKeyword(Keyword.ON)) { | 4984 if (_matchesString(_ON)) { |
| 4981 onKeyword = getAndAdvance(); | 4985 onKeyword = getAndAdvance(); |
| 4982 exceptionType = parseTypeAnnotation(false); | 4986 exceptionType = parseTypeAnnotation(false); |
| 4983 } | 4987 } |
| 4984 Token catchKeyword = null; | 4988 Token catchKeyword = null; |
| 4985 Token leftParenthesis = null; | 4989 Token leftParenthesis = null; |
| 4986 SimpleIdentifier exceptionParameter = null; | 4990 SimpleIdentifier exceptionParameter = null; |
| 4987 Token comma = null; | 4991 Token comma = null; |
| 4988 SimpleIdentifier stackTraceParameter = null; | 4992 SimpleIdentifier stackTraceParameter = null; |
| 4989 Token rightParenthesis = null; | 4993 Token rightParenthesis = null; |
| 4990 if (_matchesKeyword(Keyword.CATCH)) { | 4994 if (_matchesKeyword(Keyword.CATCH)) { |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5230 _reportErrorForCurrentToken( | 5234 _reportErrorForCurrentToken( |
| 5231 ParserErrorCode.INVALID_OPERATOR_FOR_SUPER, [operator.lexeme]); | 5235 ParserErrorCode.INVALID_OPERATOR_FOR_SUPER, [operator.lexeme]); |
| 5232 return astFactory.prefixExpression( | 5236 return astFactory.prefixExpression( |
| 5233 operator, astFactory.superExpression(getAndAdvance())); | 5237 operator, astFactory.superExpression(getAndAdvance())); |
| 5234 } | 5238 } |
| 5235 return astFactory.prefixExpression( | 5239 return astFactory.prefixExpression( |
| 5236 operator, _parseAssignableExpressionNotStartingWithSuper(false)); | 5240 operator, _parseAssignableExpressionNotStartingWithSuper(false)); |
| 5237 } else if (type == TokenType.PLUS) { | 5241 } else if (type == TokenType.PLUS) { |
| 5238 _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER); | 5242 _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER); |
| 5239 return createSyntheticIdentifier(); | 5243 return createSyntheticIdentifier(); |
| 5240 } else if (_inAsync && _matchesKeyword(Keyword.AWAIT)) { | 5244 } else if (_inAsync && _matchesString(_AWAIT)) { |
| 5241 return parseAwaitExpression(); | 5245 return parseAwaitExpression(); |
| 5242 } | 5246 } |
| 5243 return parsePostfixExpression(); | 5247 return parsePostfixExpression(); |
| 5244 } | 5248 } |
| 5245 | 5249 |
| 5246 /** | 5250 /** |
| 5247 * Parse a variable declaration. Return the variable declaration that was | 5251 * Parse a variable declaration. Return the variable declaration that was |
| 5248 * parsed. | 5252 * parsed. |
| 5249 * | 5253 * |
| 5250 * variableDeclaration ::= | 5254 * variableDeclaration ::= |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5683 } else { | 5687 } else { |
| 5684 buffer.write(Character.toChars(codePoint)); | 5688 buffer.write(Character.toChars(codePoint)); |
| 5685 } | 5689 } |
| 5686 } | 5690 } |
| 5687 | 5691 |
| 5688 /** | 5692 /** |
| 5689 * Return `true` if we are positioned at the keyword 'Function' in a generic | 5693 * Return `true` if we are positioned at the keyword 'Function' in a generic |
| 5690 * function type alias. | 5694 * function type alias. |
| 5691 */ | 5695 */ |
| 5692 bool _atGenericFunctionTypeAfterReturnType(Token startToken) { | 5696 bool _atGenericFunctionTypeAfterReturnType(Token startToken) { |
| 5693 if (_tokenMatchesKeyword(startToken, Keyword.FUNCTION)) { | 5697 if (_tokenMatchesString(startToken, 'Function')) { |
| 5694 Token next = startToken.next; | 5698 Token next = startToken.next; |
| 5695 if (next != null && | 5699 if (next != null && |
| 5696 (_tokenMatches(next, TokenType.OPEN_PAREN) || | 5700 (_tokenMatches(next, TokenType.OPEN_PAREN) || |
| 5697 _tokenMatches(next, TokenType.LT))) { | 5701 _tokenMatches(next, TokenType.LT))) { |
| 5698 return true; | 5702 return true; |
| 5699 } | 5703 } |
| 5700 } | 5704 } |
| 5701 return false; | 5705 return false; |
| 5702 } | 5706 } |
| 5703 | 5707 |
| (...skipping 2278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7982 /** | 7986 /** |
| 7983 * Return `true` if the given [token] matches the given [keyword]. | 7987 * Return `true` if the given [token] matches the given [keyword]. |
| 7984 */ | 7988 */ |
| 7985 bool _tokenMatchesKeyword(Token token, Keyword keyword) => | 7989 bool _tokenMatchesKeyword(Token token, Keyword keyword) => |
| 7986 token.keyword == keyword; | 7990 token.keyword == keyword; |
| 7987 | 7991 |
| 7988 /** | 7992 /** |
| 7989 * Return `true` if the given [token] matches a pseudo keyword. | 7993 * Return `true` if the given [token] matches a pseudo keyword. |
| 7990 */ | 7994 */ |
| 7991 bool _tokenMatchesPseudoKeyword(Token token) => | 7995 bool _tokenMatchesPseudoKeyword(Token token) => |
| 7992 token.keyword?.isBuiltInOrPseudo ?? false; | 7996 token.keyword?.isBuiltIn ?? false; |
| 7993 | 7997 |
| 7994 /** | 7998 /** |
| 7995 * Return `true` if the given [token] matches the given [identifier]. | 7999 * Return `true` if the given [token] matches the given [identifier]. |
| 7996 */ | 8000 */ |
| 7997 bool _tokenMatchesString(Token token, String identifier) => | 8001 bool _tokenMatchesString(Token token, String identifier) => |
| 7998 token.type == TokenType.IDENTIFIER && token.lexeme == identifier; | 8002 token.type == TokenType.IDENTIFIER && token.lexeme == identifier; |
| 7999 | 8003 |
| 8000 /** | 8004 /** |
| 8001 * Translate the characters at the given [index] in the given [lexeme], | 8005 * Translate the characters at the given [index] in the given [lexeme], |
| 8002 * appending the translated character to the given [buffer]. The index is | 8006 * appending the translated character to the given [buffer]. The index is |
| (...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8493 } | 8497 } |
| 8494 if (modifiers.finalKeyword != null) { | 8498 if (modifiers.finalKeyword != null) { |
| 8495 _reportErrorForToken( | 8499 _reportErrorForToken( |
| 8496 ParserErrorCode.FINAL_TYPEDEF, modifiers.finalKeyword); | 8500 ParserErrorCode.FINAL_TYPEDEF, modifiers.finalKeyword); |
| 8497 } | 8501 } |
| 8498 if (modifiers.varKeyword != null) { | 8502 if (modifiers.varKeyword != null) { |
| 8499 _reportErrorForToken(ParserErrorCode.VAR_TYPEDEF, modifiers.varKeyword); | 8503 _reportErrorForToken(ParserErrorCode.VAR_TYPEDEF, modifiers.varKeyword); |
| 8500 } | 8504 } |
| 8501 } | 8505 } |
| 8502 } | 8506 } |
| OLD | NEW |