| 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 // This code was auto-generated, is not intended to be edited, and is subject to | 5 // This code was auto-generated, is not intended to be edited, and is subject to |
| 6 // significant change. Please see the README file for more information. | 6 // significant change. Please see the README file for more information. |
| 7 | 7 |
| 8 library engine.parser; | 8 library engine.parser; |
| 9 | 9 |
| 10 import 'java_core.dart'; | 10 import 'java_core.dart'; |
| (...skipping 1440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1451 /** | 1451 /** |
| 1452 * A flag indicating whether the parser is currently in the body of a loop. | 1452 * A flag indicating whether the parser is currently in the body of a loop. |
| 1453 */ | 1453 */ |
| 1454 bool _inLoop = false; | 1454 bool _inLoop = false; |
| 1455 | 1455 |
| 1456 /** | 1456 /** |
| 1457 * A flag indicating whether the parser is currently in a switch statement. | 1457 * A flag indicating whether the parser is currently in a switch statement. |
| 1458 */ | 1458 */ |
| 1459 bool _inSwitch = false; | 1459 bool _inSwitch = false; |
| 1460 | 1460 |
| 1461 /** |
| 1462 * A flag indicating whether the parser is currently in a constructor field in
itializer, with no |
| 1463 * intervening parens, braces, or brackets. |
| 1464 */ |
| 1465 bool _inInitializer = false; |
| 1466 |
| 1461 static String _HIDE = "hide"; | 1467 static String _HIDE = "hide"; |
| 1462 | 1468 |
| 1463 static String _OF = "of"; | 1469 static String _OF = "of"; |
| 1464 | 1470 |
| 1465 static String _ON = "on"; | 1471 static String _ON = "on"; |
| 1466 | 1472 |
| 1467 static String _NATIVE = "native"; | 1473 static String _NATIVE = "native"; |
| 1468 | 1474 |
| 1469 static String _SHOW = "show"; | 1475 static String _SHOW = "show"; |
| 1470 | 1476 |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1622 ArgumentList parseArgumentList() { | 1628 ArgumentList parseArgumentList() { |
| 1623 Token leftParenthesis = _expect(TokenType.OPEN_PAREN); | 1629 Token leftParenthesis = _expect(TokenType.OPEN_PAREN); |
| 1624 List<Expression> arguments = new List<Expression>(); | 1630 List<Expression> arguments = new List<Expression>(); |
| 1625 if (_matches(TokenType.CLOSE_PAREN)) { | 1631 if (_matches(TokenType.CLOSE_PAREN)) { |
| 1626 return new ArgumentList(leftParenthesis, arguments, andAdvance); | 1632 return new ArgumentList(leftParenthesis, arguments, andAdvance); |
| 1627 } | 1633 } |
| 1628 // | 1634 // |
| 1629 // Even though unnamed arguments must all appear before any named arguments,
we allow them to | 1635 // Even though unnamed arguments must all appear before any named arguments,
we allow them to |
| 1630 // appear in any order so that we can recover faster. | 1636 // appear in any order so that we can recover faster. |
| 1631 // | 1637 // |
| 1632 Expression argument = parseArgument(); | 1638 bool wasInInitializer = _inInitializer; |
| 1633 arguments.add(argument); | 1639 _inInitializer = false; |
| 1634 bool foundNamedArgument = argument is NamedExpression; | 1640 try { |
| 1635 bool generatedError = false; | 1641 Expression argument = parseArgument(); |
| 1636 while (_optional(TokenType.COMMA)) { | |
| 1637 argument = parseArgument(); | |
| 1638 arguments.add(argument); | 1642 arguments.add(argument); |
| 1639 if (foundNamedArgument) { | 1643 bool foundNamedArgument = argument is NamedExpression; |
| 1640 if (!generatedError && argument is! NamedExpression) { | 1644 bool generatedError = false; |
| 1641 // Report the error, once, but allow the arguments to be in any order
in the AST. | 1645 while (_optional(TokenType.COMMA)) { |
| 1642 _reportErrorForCurrentToken(ParserErrorCode.POSITIONAL_AFTER_NAMED_ARG
UMENT, []); | 1646 argument = parseArgument(); |
| 1643 generatedError = true; | 1647 arguments.add(argument); |
| 1648 if (foundNamedArgument) { |
| 1649 if (!generatedError && argument is! NamedExpression) { |
| 1650 // Report the error, once, but allow the arguments to be in any orde
r in the AST. |
| 1651 _reportErrorForCurrentToken(ParserErrorCode.POSITIONAL_AFTER_NAMED_A
RGUMENT, []); |
| 1652 generatedError = true; |
| 1653 } |
| 1654 } else if (argument is NamedExpression) { |
| 1655 foundNamedArgument = true; |
| 1644 } | 1656 } |
| 1645 } else if (argument is NamedExpression) { | |
| 1646 foundNamedArgument = true; | |
| 1647 } | 1657 } |
| 1658 // TODO(brianwilkerson) Recovery: Look at the left parenthesis to see whet
her there is a |
| 1659 // matching right parenthesis. If there is, then we're more likely missing
a comma and should |
| 1660 // go back to parsing arguments. |
| 1661 Token rightParenthesis = _expect(TokenType.CLOSE_PAREN); |
| 1662 return new ArgumentList(leftParenthesis, arguments, rightParenthesis); |
| 1663 } finally { |
| 1664 _inInitializer = wasInInitializer; |
| 1648 } | 1665 } |
| 1649 // TODO(brianwilkerson) Recovery: Look at the left parenthesis to see whethe
r there is a | |
| 1650 // matching right parenthesis. If there is, then we're more likely missing a
comma and should | |
| 1651 // go back to parsing arguments. | |
| 1652 Token rightParenthesis = _expect(TokenType.CLOSE_PAREN); | |
| 1653 return new ArgumentList(leftParenthesis, arguments, rightParenthesis); | |
| 1654 } | 1666 } |
| 1655 | 1667 |
| 1656 /** | 1668 /** |
| 1657 * Parse a bitwise or expression. | 1669 * Parse a bitwise or expression. |
| 1658 * | 1670 * |
| 1659 * <pre> | 1671 * <pre> |
| 1660 * bitwiseOrExpression ::= | 1672 * bitwiseOrExpression ::= |
| 1661 * bitwiseXorExpression ('|' bitwiseXorExpression)* | 1673 * bitwiseXorExpression ('|' bitwiseXorExpression)* |
| 1662 * | 'super' ('|' bitwiseXorExpression)+ | 1674 * | 'super' ('|' bitwiseXorExpression)+ |
| 1663 * </pre> | 1675 * </pre> |
| (...skipping 1401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3065 return false; | 3077 return false; |
| 3066 } | 3078 } |
| 3067 | 3079 |
| 3068 /** | 3080 /** |
| 3069 * Return `true` if the given token appears to be the beginning of a function
expression. | 3081 * Return `true` if the given token appears to be the beginning of a function
expression. |
| 3070 * | 3082 * |
| 3071 * @param startToken the token that might be the start of a function expressio
n | 3083 * @param startToken the token that might be the start of a function expressio
n |
| 3072 * @return `true` if the given token appears to be the beginning of a function
expression | 3084 * @return `true` if the given token appears to be the beginning of a function
expression |
| 3073 */ | 3085 */ |
| 3074 bool _isFunctionExpression(Token startToken) { | 3086 bool _isFunctionExpression(Token startToken) { |
| 3087 // Function expressions aren't allowed in initializer lists. |
| 3088 if (_inInitializer) { |
| 3089 return false; |
| 3090 } |
| 3075 Token afterParameters = _skipFormalParameterList(startToken); | 3091 Token afterParameters = _skipFormalParameterList(startToken); |
| 3076 if (afterParameters == null) { | 3092 if (afterParameters == null) { |
| 3077 return false; | 3093 return false; |
| 3078 } | 3094 } |
| 3079 return afterParameters.matchesAny([TokenType.OPEN_CURLY_BRACKET, TokenType.F
UNCTION]); | 3095 return afterParameters.matchesAny([TokenType.OPEN_CURLY_BRACKET, TokenType.F
UNCTION]); |
| 3080 } | 3096 } |
| 3081 | 3097 |
| 3082 /** | 3098 /** |
| 3083 * Return `true` if the given character is a valid hexadecimal digit. | 3099 * Return `true` if the given character is a valid hexadecimal digit. |
| 3084 * | 3100 * |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3497 * | '.' identifier | 3513 * | '.' identifier |
| 3498 * </pre> | 3514 * </pre> |
| 3499 * | 3515 * |
| 3500 * @param prefix the expression preceding the selector | 3516 * @param prefix the expression preceding the selector |
| 3501 * @param optional `true` if the selector is optional | 3517 * @param optional `true` if the selector is optional |
| 3502 * @return the assignable selector that was parsed | 3518 * @return the assignable selector that was parsed |
| 3503 */ | 3519 */ |
| 3504 Expression _parseAssignableSelector(Expression prefix, bool optional) { | 3520 Expression _parseAssignableSelector(Expression prefix, bool optional) { |
| 3505 if (_matches(TokenType.OPEN_SQUARE_BRACKET)) { | 3521 if (_matches(TokenType.OPEN_SQUARE_BRACKET)) { |
| 3506 Token leftBracket = andAdvance; | 3522 Token leftBracket = andAdvance; |
| 3507 Expression index = parseExpression2(); | 3523 bool wasInInitializer = _inInitializer; |
| 3508 Token rightBracket = _expect(TokenType.CLOSE_SQUARE_BRACKET); | 3524 _inInitializer = false; |
| 3509 return new IndexExpression.forTarget(prefix, leftBracket, index, rightBrac
ket); | 3525 try { |
| 3526 Expression index = parseExpression2(); |
| 3527 Token rightBracket = _expect(TokenType.CLOSE_SQUARE_BRACKET); |
| 3528 return new IndexExpression.forTarget(prefix, leftBracket, index, rightBr
acket); |
| 3529 } finally { |
| 3530 _inInitializer = wasInInitializer; |
| 3531 } |
| 3510 } else if (_matches(TokenType.PERIOD)) { | 3532 } else if (_matches(TokenType.PERIOD)) { |
| 3511 Token period = andAdvance; | 3533 Token period = andAdvance; |
| 3512 return new PropertyAccess(prefix, period, parseSimpleIdentifier()); | 3534 return new PropertyAccess(prefix, period, parseSimpleIdentifier()); |
| 3513 } else { | 3535 } else { |
| 3514 if (!optional) { | 3536 if (!optional) { |
| 3515 // Report the missing selector. | 3537 // Report the missing selector. |
| 3516 _reportErrorForCurrentToken(ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR,
[]); | 3538 _reportErrorForCurrentToken(ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR,
[]); |
| 3517 } | 3539 } |
| 3518 return prefix; | 3540 return prefix; |
| 3519 } | 3541 } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3610 * @return the expression representing the cascaded method invocation | 3632 * @return the expression representing the cascaded method invocation |
| 3611 */ | 3633 */ |
| 3612 Expression _parseCascadeSection() { | 3634 Expression _parseCascadeSection() { |
| 3613 Token period = _expect(TokenType.PERIOD_PERIOD); | 3635 Token period = _expect(TokenType.PERIOD_PERIOD); |
| 3614 Expression expression = null; | 3636 Expression expression = null; |
| 3615 SimpleIdentifier functionName = null; | 3637 SimpleIdentifier functionName = null; |
| 3616 if (_matchesIdentifier()) { | 3638 if (_matchesIdentifier()) { |
| 3617 functionName = parseSimpleIdentifier(); | 3639 functionName = parseSimpleIdentifier(); |
| 3618 } else if (_currentToken.type == TokenType.OPEN_SQUARE_BRACKET) { | 3640 } else if (_currentToken.type == TokenType.OPEN_SQUARE_BRACKET) { |
| 3619 Token leftBracket = andAdvance; | 3641 Token leftBracket = andAdvance; |
| 3620 Expression index = parseExpression2(); | 3642 bool wasInInitializer = _inInitializer; |
| 3621 Token rightBracket = _expect(TokenType.CLOSE_SQUARE_BRACKET); | 3643 _inInitializer = false; |
| 3622 expression = new IndexExpression.forCascade(period, leftBracket, index, ri
ghtBracket); | 3644 try { |
| 3623 period = null; | 3645 Expression index = parseExpression2(); |
| 3646 Token rightBracket = _expect(TokenType.CLOSE_SQUARE_BRACKET); |
| 3647 expression = new IndexExpression.forCascade(period, leftBracket, index,
rightBracket); |
| 3648 period = null; |
| 3649 } finally { |
| 3650 _inInitializer = wasInInitializer; |
| 3651 } |
| 3624 } else { | 3652 } else { |
| 3625 _reportErrorForToken(ParserErrorCode.MISSING_IDENTIFIER, _currentToken, [_
currentToken.lexeme]); | 3653 _reportErrorForToken(ParserErrorCode.MISSING_IDENTIFIER, _currentToken, [_
currentToken.lexeme]); |
| 3626 functionName = _createSyntheticIdentifier(); | 3654 functionName = _createSyntheticIdentifier(); |
| 3627 } | 3655 } |
| 3628 if (_currentToken.type == TokenType.OPEN_PAREN) { | 3656 if (_currentToken.type == TokenType.OPEN_PAREN) { |
| 3629 while (_currentToken.type == TokenType.OPEN_PAREN) { | 3657 while (_currentToken.type == TokenType.OPEN_PAREN) { |
| 3630 if (functionName != null) { | 3658 if (functionName != null) { |
| 3631 expression = new MethodInvocation(expression, period, functionName, pa
rseArgumentList()); | 3659 expression = new MethodInvocation(expression, period, functionName, pa
rseArgumentList()); |
| 3632 period = null; | 3660 period = null; |
| 3633 functionName = null; | 3661 functionName = null; |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3823 * @param classKeyword the token representing the 'class' keyword | 3851 * @param classKeyword the token representing the 'class' keyword |
| 3824 * @return the class type alias that was parsed | 3852 * @return the class type alias that was parsed |
| 3825 */ | 3853 */ |
| 3826 ClassTypeAlias _parseClassTypeAlias(CommentAndMetadata commentAndMetadata, Tok
en abstractKeyword, Token classKeyword) { | 3854 ClassTypeAlias _parseClassTypeAlias(CommentAndMetadata commentAndMetadata, Tok
en abstractKeyword, Token classKeyword) { |
| 3827 SimpleIdentifier className = parseSimpleIdentifier(); | 3855 SimpleIdentifier className = parseSimpleIdentifier(); |
| 3828 TypeParameterList typeParameters = null; | 3856 TypeParameterList typeParameters = null; |
| 3829 if (_matches(TokenType.LT)) { | 3857 if (_matches(TokenType.LT)) { |
| 3830 typeParameters = parseTypeParameterList(); | 3858 typeParameters = parseTypeParameterList(); |
| 3831 } | 3859 } |
| 3832 Token equals = _expect(TokenType.EQ); | 3860 Token equals = _expect(TokenType.EQ); |
| 3833 if (_matchesKeyword(Keyword.ABSTRACT)) { | |
| 3834 abstractKeyword = andAdvance; | |
| 3835 } | |
| 3836 TypeName superclass = parseTypeName(); | 3861 TypeName superclass = parseTypeName(); |
| 3837 WithClause withClause = null; | 3862 WithClause withClause = null; |
| 3838 if (_matchesKeyword(Keyword.WITH)) { | 3863 if (_matchesKeyword(Keyword.WITH)) { |
| 3839 withClause = parseWithClause(); | 3864 withClause = parseWithClause(); |
| 3865 } else { |
| 3866 _reportErrorForCurrentToken(ParserErrorCode.EXPECTED_TOKEN, [Keyword.WITH.
syntax]); |
| 3840 } | 3867 } |
| 3841 ImplementsClause implementsClause = null; | 3868 ImplementsClause implementsClause = null; |
| 3842 if (_matchesKeyword(Keyword.IMPLEMENTS)) { | 3869 if (_matchesKeyword(Keyword.IMPLEMENTS)) { |
| 3843 implementsClause = parseImplementsClause(); | 3870 implementsClause = parseImplementsClause(); |
| 3844 } | 3871 } |
| 3845 Token semicolon; | 3872 Token semicolon; |
| 3846 if (_matches(TokenType.SEMICOLON)) { | 3873 if (_matches(TokenType.SEMICOLON)) { |
| 3847 semicolon = andAdvance; | 3874 semicolon = andAdvance; |
| 3848 } else { | 3875 } else { |
| 3849 if (_matches(TokenType.OPEN_CURLY_BRACKET)) { | 3876 if (_matches(TokenType.OPEN_CURLY_BRACKET)) { |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4228 */ | 4255 */ |
| 4229 ConstructorFieldInitializer _parseConstructorFieldInitializer() { | 4256 ConstructorFieldInitializer _parseConstructorFieldInitializer() { |
| 4230 Token keyword = null; | 4257 Token keyword = null; |
| 4231 Token period = null; | 4258 Token period = null; |
| 4232 if (_matchesKeyword(Keyword.THIS)) { | 4259 if (_matchesKeyword(Keyword.THIS)) { |
| 4233 keyword = andAdvance; | 4260 keyword = andAdvance; |
| 4234 period = _expect(TokenType.PERIOD); | 4261 period = _expect(TokenType.PERIOD); |
| 4235 } | 4262 } |
| 4236 SimpleIdentifier fieldName = parseSimpleIdentifier(); | 4263 SimpleIdentifier fieldName = parseSimpleIdentifier(); |
| 4237 Token equals = _expect(TokenType.EQ); | 4264 Token equals = _expect(TokenType.EQ); |
| 4238 Expression expression = parseConditionalExpression(); | 4265 bool wasInInitializer = _inInitializer; |
| 4239 TokenType tokenType = _currentToken.type; | 4266 _inInitializer = true; |
| 4240 if (tokenType == TokenType.PERIOD_PERIOD) { | 4267 try { |
| 4241 List<Expression> cascadeSections = new List<Expression>(); | 4268 Expression expression = parseConditionalExpression(); |
| 4242 while (tokenType == TokenType.PERIOD_PERIOD) { | 4269 TokenType tokenType = _currentToken.type; |
| 4243 Expression section = _parseCascadeSection(); | 4270 if (tokenType == TokenType.PERIOD_PERIOD) { |
| 4244 if (section != null) { | 4271 List<Expression> cascadeSections = new List<Expression>(); |
| 4245 cascadeSections.add(section); | 4272 while (tokenType == TokenType.PERIOD_PERIOD) { |
| 4273 Expression section = _parseCascadeSection(); |
| 4274 if (section != null) { |
| 4275 cascadeSections.add(section); |
| 4276 } |
| 4277 tokenType = _currentToken.type; |
| 4246 } | 4278 } |
| 4247 tokenType = _currentToken.type; | 4279 expression = new CascadeExpression(expression, cascadeSections); |
| 4248 } | 4280 } |
| 4249 expression = new CascadeExpression(expression, cascadeSections); | 4281 return new ConstructorFieldInitializer(keyword, period, fieldName, equals,
expression); |
| 4282 } finally { |
| 4283 _inInitializer = wasInInitializer; |
| 4250 } | 4284 } |
| 4251 return new ConstructorFieldInitializer(keyword, period, fieldName, equals, e
xpression); | |
| 4252 } | 4285 } |
| 4253 | 4286 |
| 4254 /** | 4287 /** |
| 4255 * Parse a continue statement. | 4288 * Parse a continue statement. |
| 4256 * | 4289 * |
| 4257 * <pre> | 4290 * <pre> |
| 4258 * continueStatement ::= | 4291 * continueStatement ::= |
| 4259 * 'continue' identifier? ';' | 4292 * 'continue' identifier? ';' |
| 4260 * </pre> | 4293 * </pre> |
| 4261 * | 4294 * |
| (...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5048 leftBracket.setNext(rightBracket); | 5081 leftBracket.setNext(rightBracket); |
| 5049 _currentToken.previous.setNext(leftBracket); | 5082 _currentToken.previous.setNext(leftBracket); |
| 5050 _currentToken = _currentToken.next; | 5083 _currentToken = _currentToken.next; |
| 5051 return new ListLiteral(modifier, typeArguments, leftBracket, null, rightBr
acket); | 5084 return new ListLiteral(modifier, typeArguments, leftBracket, null, rightBr
acket); |
| 5052 } | 5085 } |
| 5053 // open | 5086 // open |
| 5054 Token leftBracket = _expect(TokenType.OPEN_SQUARE_BRACKET); | 5087 Token leftBracket = _expect(TokenType.OPEN_SQUARE_BRACKET); |
| 5055 if (_matches(TokenType.CLOSE_SQUARE_BRACKET)) { | 5088 if (_matches(TokenType.CLOSE_SQUARE_BRACKET)) { |
| 5056 return new ListLiteral(modifier, typeArguments, leftBracket, null, andAdva
nce); | 5089 return new ListLiteral(modifier, typeArguments, leftBracket, null, andAdva
nce); |
| 5057 } | 5090 } |
| 5058 List<Expression> elements = new List<Expression>(); | 5091 bool wasInInitializer = _inInitializer; |
| 5059 elements.add(parseExpression2()); | 5092 _inInitializer = false; |
| 5060 while (_optional(TokenType.COMMA)) { | 5093 try { |
| 5061 if (_matches(TokenType.CLOSE_SQUARE_BRACKET)) { | 5094 List<Expression> elements = new List<Expression>(); |
| 5062 return new ListLiteral(modifier, typeArguments, leftBracket, elements, a
ndAdvance); | 5095 elements.add(parseExpression2()); |
| 5096 while (_optional(TokenType.COMMA)) { |
| 5097 if (_matches(TokenType.CLOSE_SQUARE_BRACKET)) { |
| 5098 return new ListLiteral(modifier, typeArguments, leftBracket, elements,
andAdvance); |
| 5099 } |
| 5100 elements.add(parseExpression2()); |
| 5063 } | 5101 } |
| 5064 elements.add(parseExpression2()); | 5102 Token rightBracket = _expect(TokenType.CLOSE_SQUARE_BRACKET); |
| 5103 return new ListLiteral(modifier, typeArguments, leftBracket, elements, rig
htBracket); |
| 5104 } finally { |
| 5105 _inInitializer = wasInInitializer; |
| 5065 } | 5106 } |
| 5066 Token rightBracket = _expect(TokenType.CLOSE_SQUARE_BRACKET); | |
| 5067 return new ListLiteral(modifier, typeArguments, leftBracket, elements, right
Bracket); | |
| 5068 } | 5107 } |
| 5069 | 5108 |
| 5070 /** | 5109 /** |
| 5071 * Parse a list or map literal. | 5110 * Parse a list or map literal. |
| 5072 * | 5111 * |
| 5073 * <pre> | 5112 * <pre> |
| 5074 * listOrMapLiteral ::= | 5113 * listOrMapLiteral ::= |
| 5075 * listLiteral | 5114 * listLiteral |
| 5076 * | mapLiteral | 5115 * | mapLiteral |
| 5077 * </pre> | 5116 * </pre> |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5126 * @param typeArguments the type arguments that were declared, or `null` if th
ere are no | 5165 * @param typeArguments the type arguments that were declared, or `null` if th
ere are no |
| 5127 * type arguments | 5166 * type arguments |
| 5128 * @return the map literal that was parsed | 5167 * @return the map literal that was parsed |
| 5129 */ | 5168 */ |
| 5130 MapLiteral _parseMapLiteral(Token modifier, TypeArgumentList typeArguments) { | 5169 MapLiteral _parseMapLiteral(Token modifier, TypeArgumentList typeArguments) { |
| 5131 Token leftBracket = _expect(TokenType.OPEN_CURLY_BRACKET); | 5170 Token leftBracket = _expect(TokenType.OPEN_CURLY_BRACKET); |
| 5132 List<MapLiteralEntry> entries = new List<MapLiteralEntry>(); | 5171 List<MapLiteralEntry> entries = new List<MapLiteralEntry>(); |
| 5133 if (_matches(TokenType.CLOSE_CURLY_BRACKET)) { | 5172 if (_matches(TokenType.CLOSE_CURLY_BRACKET)) { |
| 5134 return new MapLiteral(modifier, typeArguments, leftBracket, entries, andAd
vance); | 5173 return new MapLiteral(modifier, typeArguments, leftBracket, entries, andAd
vance); |
| 5135 } | 5174 } |
| 5136 entries.add(parseMapLiteralEntry()); | 5175 bool wasInInitializer = _inInitializer; |
| 5137 while (_optional(TokenType.COMMA)) { | 5176 _inInitializer = false; |
| 5138 if (_matches(TokenType.CLOSE_CURLY_BRACKET)) { | 5177 try { |
| 5139 return new MapLiteral(modifier, typeArguments, leftBracket, entries, and
Advance); | 5178 entries.add(parseMapLiteralEntry()); |
| 5179 while (_optional(TokenType.COMMA)) { |
| 5180 if (_matches(TokenType.CLOSE_CURLY_BRACKET)) { |
| 5181 return new MapLiteral(modifier, typeArguments, leftBracket, entries, a
ndAdvance); |
| 5182 } |
| 5183 entries.add(parseMapLiteralEntry()); |
| 5140 } | 5184 } |
| 5141 entries.add(parseMapLiteralEntry()); | 5185 Token rightBracket = _expect(TokenType.CLOSE_CURLY_BRACKET); |
| 5186 return new MapLiteral(modifier, typeArguments, leftBracket, entries, right
Bracket); |
| 5187 } finally { |
| 5188 _inInitializer = wasInInitializer; |
| 5142 } | 5189 } |
| 5143 Token rightBracket = _expect(TokenType.CLOSE_CURLY_BRACKET); | |
| 5144 return new MapLiteral(modifier, typeArguments, leftBracket, entries, rightBr
acket); | |
| 5145 } | 5190 } |
| 5146 | 5191 |
| 5147 /** | 5192 /** |
| 5148 * Parse a method declaration. | 5193 * Parse a method declaration. |
| 5149 * | 5194 * |
| 5150 * <pre> | 5195 * <pre> |
| 5151 * functionDeclaration ::= | 5196 * functionDeclaration ::= |
| 5152 * ('external' 'static'?)? functionSignature functionBody | 5197 * ('external' 'static'?)? functionSignature functionBody |
| 5153 * | 'external'? functionSignature ';' | 5198 * | 'external'? functionSignature ';' |
| 5154 * </pre> | 5199 * </pre> |
| (...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5672 return parsePrefixedIdentifier(); | 5717 return parsePrefixedIdentifier(); |
| 5673 } else if (_matchesKeyword(Keyword.NEW)) { | 5718 } else if (_matchesKeyword(Keyword.NEW)) { |
| 5674 return _parseNewExpression(); | 5719 return _parseNewExpression(); |
| 5675 } else if (_matchesKeyword(Keyword.CONST)) { | 5720 } else if (_matchesKeyword(Keyword.CONST)) { |
| 5676 return _parseConstExpression(); | 5721 return _parseConstExpression(); |
| 5677 } else if (_matches(TokenType.OPEN_PAREN)) { | 5722 } else if (_matches(TokenType.OPEN_PAREN)) { |
| 5678 if (_isFunctionExpression(_currentToken)) { | 5723 if (_isFunctionExpression(_currentToken)) { |
| 5679 return parseFunctionExpression(); | 5724 return parseFunctionExpression(); |
| 5680 } | 5725 } |
| 5681 Token leftParenthesis = andAdvance; | 5726 Token leftParenthesis = andAdvance; |
| 5682 Expression expression = parseExpression2(); | 5727 bool wasInInitializer = _inInitializer; |
| 5683 Token rightParenthesis = _expect(TokenType.CLOSE_PAREN); | 5728 _inInitializer = false; |
| 5684 return new ParenthesizedExpression(leftParenthesis, expression, rightParen
thesis); | 5729 try { |
| 5730 Expression expression = parseExpression2(); |
| 5731 Token rightParenthesis = _expect(TokenType.CLOSE_PAREN); |
| 5732 return new ParenthesizedExpression(leftParenthesis, expression, rightPar
enthesis); |
| 5733 } finally { |
| 5734 _inInitializer = wasInInitializer; |
| 5735 } |
| 5685 } else if (_matches(TokenType.LT)) { | 5736 } else if (_matches(TokenType.LT)) { |
| 5686 return _parseListOrMapLiteral(null); | 5737 return _parseListOrMapLiteral(null); |
| 5687 } else if (_matches(TokenType.QUESTION)) { | 5738 } else if (_matches(TokenType.QUESTION)) { |
| 5688 return _parseArgumentDefinitionTest(); | 5739 return _parseArgumentDefinitionTest(); |
| 5689 } else if (_matchesKeyword(Keyword.VOID)) { | 5740 } else if (_matchesKeyword(Keyword.VOID)) { |
| 5690 // | 5741 // |
| 5691 // Recover from having a return type of "void" where a return type is not
expected. | 5742 // Recover from having a return type of "void" where a return type is not
expected. |
| 5692 // | 5743 // |
| 5693 // TODO(brianwilkerson) Improve this error message. | 5744 // TODO(brianwilkerson) Improve this error message. |
| 5694 _reportErrorForCurrentToken(ParserErrorCode.UNEXPECTED_TOKEN, [_currentTok
en.lexeme]); | 5745 _reportErrorForCurrentToken(ParserErrorCode.UNEXPECTED_TOKEN, [_currentTok
en.lexeme]); |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5877 * | 5928 * |
| 5878 * @return the string literal that was parsed | 5929 * @return the string literal that was parsed |
| 5879 */ | 5930 */ |
| 5880 StringInterpolation _parseStringInterpolation(Token string) { | 5931 StringInterpolation _parseStringInterpolation(Token string) { |
| 5881 List<InterpolationElement> elements = new List<InterpolationElement>(); | 5932 List<InterpolationElement> elements = new List<InterpolationElement>(); |
| 5882 bool hasMore = _matches(TokenType.STRING_INTERPOLATION_EXPRESSION) || _match
es(TokenType.STRING_INTERPOLATION_IDENTIFIER); | 5933 bool hasMore = _matches(TokenType.STRING_INTERPOLATION_EXPRESSION) || _match
es(TokenType.STRING_INTERPOLATION_IDENTIFIER); |
| 5883 elements.add(new InterpolationString(string, _computeStringValue(string.lexe
me, true, !hasMore))); | 5934 elements.add(new InterpolationString(string, _computeStringValue(string.lexe
me, true, !hasMore))); |
| 5884 while (hasMore) { | 5935 while (hasMore) { |
| 5885 if (_matches(TokenType.STRING_INTERPOLATION_EXPRESSION)) { | 5936 if (_matches(TokenType.STRING_INTERPOLATION_EXPRESSION)) { |
| 5886 Token openToken = andAdvance; | 5937 Token openToken = andAdvance; |
| 5887 Expression expression = parseExpression2(); | 5938 bool wasInInitializer = _inInitializer; |
| 5888 Token rightBracket = _expect(TokenType.CLOSE_CURLY_BRACKET); | 5939 _inInitializer = false; |
| 5889 elements.add(new InterpolationExpression(openToken, expression, rightBra
cket)); | 5940 try { |
| 5941 Expression expression = parseExpression2(); |
| 5942 Token rightBracket = _expect(TokenType.CLOSE_CURLY_BRACKET); |
| 5943 elements.add(new InterpolationExpression(openToken, expression, rightB
racket)); |
| 5944 } finally { |
| 5945 _inInitializer = wasInInitializer; |
| 5946 } |
| 5890 } else { | 5947 } else { |
| 5891 Token openToken = andAdvance; | 5948 Token openToken = andAdvance; |
| 5892 Expression expression = null; | 5949 Expression expression = null; |
| 5893 if (_matchesKeyword(Keyword.THIS)) { | 5950 if (_matchesKeyword(Keyword.THIS)) { |
| 5894 expression = new ThisExpression(andAdvance); | 5951 expression = new ThisExpression(andAdvance); |
| 5895 } else { | 5952 } else { |
| 5896 expression = parseSimpleIdentifier(); | 5953 expression = parseSimpleIdentifier(); |
| 5897 } | 5954 } |
| 5898 elements.add(new InterpolationExpression(openToken, expression, null)); | 5955 elements.add(new InterpolationExpression(openToken, expression, null)); |
| 5899 } | 5956 } |
| (...skipping 3071 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8971 return trampoline(target, arguments[0], arguments[1]); | 9028 return trampoline(target, arguments[0], arguments[1]); |
| 8972 case 3: | 9029 case 3: |
| 8973 return trampoline(target, arguments[0], arguments[1], arguments[2]); | 9030 return trampoline(target, arguments[0], arguments[1], arguments[2]); |
| 8974 case 4: | 9031 case 4: |
| 8975 return trampoline(target, arguments[0], arguments[1], arguments[2], argu
ments[3]); | 9032 return trampoline(target, arguments[0], arguments[1], arguments[2], argu
ments[3]); |
| 8976 default: | 9033 default: |
| 8977 throw new IllegalArgumentException("Not implemented for > 4 arguments"); | 9034 throw new IllegalArgumentException("Not implemented for > 4 arguments"); |
| 8978 } | 9035 } |
| 8979 } | 9036 } |
| 8980 } | 9037 } |
| OLD | NEW |