| 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 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 } else { | 773 } else { |
| 774 bool isQuestionPeriod = type == TokenType.QUESTION_PERIOD; | 774 bool isQuestionPeriod = type == TokenType.QUESTION_PERIOD; |
| 775 if (type == TokenType.PERIOD || isQuestionPeriod) { | 775 if (type == TokenType.PERIOD || isQuestionPeriod) { |
| 776 if (isQuestionPeriod && !allowConditional) { | 776 if (isQuestionPeriod && !allowConditional) { |
| 777 _reportErrorForCurrentToken( | 777 _reportErrorForCurrentToken( |
| 778 ParserErrorCode.INVALID_OPERATOR_FOR_SUPER, | 778 ParserErrorCode.INVALID_OPERATOR_FOR_SUPER, |
| 779 [_currentToken.lexeme]); | 779 [_currentToken.lexeme]); |
| 780 } | 780 } |
| 781 Token operator = getAndAdvance(); | 781 Token operator = getAndAdvance(); |
| 782 return new PropertyAccess(prefix, operator, parseSimpleIdentifier()); | 782 return new PropertyAccess(prefix, operator, parseSimpleIdentifier()); |
| 783 } else if (type == TokenType.INDEX) { |
| 784 _splitIndex(); |
| 785 Token leftBracket = getAndAdvance(); |
| 786 Expression index = parseSimpleIdentifier(); |
| 787 Token rightBracket = getAndAdvance(); |
| 788 return new IndexExpression.forTarget( |
| 789 prefix, leftBracket, index, rightBracket); |
| 783 } else { | 790 } else { |
| 784 if (!optional) { | 791 if (!optional) { |
| 785 // Report the missing selector. | 792 // Report the missing selector. |
| 786 _reportErrorForCurrentToken( | 793 _reportErrorForCurrentToken( |
| 787 ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR); | 794 ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR); |
| 788 } | 795 } |
| 789 return prefix; | 796 return prefix; |
| 790 } | 797 } |
| 791 } | 798 } |
| 792 } | 799 } |
| (...skipping 2710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3503 * no type arguments. Return the list literal that was parsed. | 3510 * no type arguments. Return the list literal that was parsed. |
| 3504 * | 3511 * |
| 3505 * This method assumes that the current token matches either | 3512 * This method assumes that the current token matches either |
| 3506 * `TokenType.OPEN_SQUARE_BRACKET` or `TokenType.INDEX`. | 3513 * `TokenType.OPEN_SQUARE_BRACKET` or `TokenType.INDEX`. |
| 3507 * | 3514 * |
| 3508 * listLiteral ::= | 3515 * listLiteral ::= |
| 3509 * 'const'? typeArguments? '[' (expressionList ','?)? ']' | 3516 * 'const'? typeArguments? '[' (expressionList ','?)? ']' |
| 3510 */ | 3517 */ |
| 3511 ListLiteral parseListLiteral(Token modifier, TypeArgumentList typeArguments) { | 3518 ListLiteral parseListLiteral(Token modifier, TypeArgumentList typeArguments) { |
| 3512 if (_matches(TokenType.INDEX)) { | 3519 if (_matches(TokenType.INDEX)) { |
| 3513 // Split the token into two separate tokens. | 3520 _splitIndex(); |
| 3514 BeginToken leftBracket = _createToken( | |
| 3515 _currentToken, TokenType.OPEN_SQUARE_BRACKET, | |
| 3516 isBegin: true); | |
| 3517 Token rightBracket = | |
| 3518 new Token(TokenType.CLOSE_SQUARE_BRACKET, _currentToken.offset + 1); | |
| 3519 leftBracket.endToken = rightBracket; | |
| 3520 rightBracket.setNext(_currentToken.next); | |
| 3521 leftBracket.setNext(rightBracket); | |
| 3522 _currentToken.previous.setNext(leftBracket); | |
| 3523 _currentToken = _currentToken.next; | |
| 3524 return new ListLiteral( | 3521 return new ListLiteral( |
| 3525 modifier, typeArguments, leftBracket, null, rightBracket); | 3522 modifier, typeArguments, getAndAdvance(), null, getAndAdvance()); |
| 3526 } | 3523 } |
| 3527 Token leftBracket = getAndAdvance(); | 3524 Token leftBracket = getAndAdvance(); |
| 3528 if (_matches(TokenType.CLOSE_SQUARE_BRACKET)) { | 3525 if (_matches(TokenType.CLOSE_SQUARE_BRACKET)) { |
| 3529 return new ListLiteral( | 3526 return new ListLiteral( |
| 3530 modifier, typeArguments, leftBracket, null, getAndAdvance()); | 3527 modifier, typeArguments, leftBracket, null, getAndAdvance()); |
| 3531 } | 3528 } |
| 3532 bool wasInInitializer = _inInitializer; | 3529 bool wasInInitializer = _inInitializer; |
| 3533 _inInitializer = false; | 3530 _inInitializer = false; |
| 3534 try { | 3531 try { |
| 3535 List<Expression> elements = <Expression>[parseExpression2()]; | 3532 List<Expression> elements = <Expression>[parseExpression2()]; |
| (...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4112 * assignableSelector | 4109 * assignableSelector |
| 4113 * | argumentList | 4110 * | argumentList |
| 4114 */ | 4111 */ |
| 4115 Expression parsePostfixExpression() { | 4112 Expression parsePostfixExpression() { |
| 4116 Expression operand = parseAssignableExpression(true); | 4113 Expression operand = parseAssignableExpression(true); |
| 4117 TokenType type = _currentToken.type; | 4114 TokenType type = _currentToken.type; |
| 4118 if (type == TokenType.OPEN_SQUARE_BRACKET || | 4115 if (type == TokenType.OPEN_SQUARE_BRACKET || |
| 4119 type == TokenType.PERIOD || | 4116 type == TokenType.PERIOD || |
| 4120 type == TokenType.QUESTION_PERIOD || | 4117 type == TokenType.QUESTION_PERIOD || |
| 4121 type == TokenType.OPEN_PAREN || | 4118 type == TokenType.OPEN_PAREN || |
| 4122 (parseGenericMethods && type == TokenType.LT)) { | 4119 (parseGenericMethods && type == TokenType.LT) || |
| 4120 type == TokenType.INDEX) { |
| 4123 do { | 4121 do { |
| 4124 if (_isLikelyArgumentList()) { | 4122 if (_isLikelyArgumentList()) { |
| 4125 TypeArgumentList typeArguments = _parseOptionalTypeArguments(); | 4123 TypeArgumentList typeArguments = _parseOptionalTypeArguments(); |
| 4126 ArgumentList argumentList = parseArgumentList(); | 4124 ArgumentList argumentList = parseArgumentList(); |
| 4127 Expression currentOperand = operand; | 4125 Expression currentOperand = operand; |
| 4128 if (currentOperand is PropertyAccess) { | 4126 if (currentOperand is PropertyAccess) { |
| 4129 operand = new MethodInvocation( | 4127 operand = new MethodInvocation( |
| 4130 currentOperand.target, | 4128 currentOperand.target, |
| 4131 currentOperand.operator, | 4129 currentOperand.operator, |
| 4132 currentOperand.propertyName, | 4130 currentOperand.propertyName, |
| 4133 typeArguments, | 4131 typeArguments, |
| 4134 argumentList); | 4132 argumentList); |
| 4135 } else { | 4133 } else { |
| 4136 operand = new FunctionExpressionInvocation( | 4134 operand = new FunctionExpressionInvocation( |
| 4137 operand, typeArguments, argumentList); | 4135 operand, typeArguments, argumentList); |
| 4138 } | 4136 } |
| 4139 } else { | 4137 } else { |
| 4140 operand = parseAssignableSelector(operand, true); | 4138 operand = parseAssignableSelector(operand, true); |
| 4141 } | 4139 } |
| 4142 type = _currentToken.type; | 4140 type = _currentToken.type; |
| 4143 } while (type == TokenType.OPEN_SQUARE_BRACKET || | 4141 } while (type == TokenType.OPEN_SQUARE_BRACKET || |
| 4144 type == TokenType.PERIOD || | 4142 type == TokenType.PERIOD || |
| 4145 type == TokenType.QUESTION_PERIOD || | 4143 type == TokenType.QUESTION_PERIOD || |
| 4146 type == TokenType.OPEN_PAREN); | 4144 type == TokenType.OPEN_PAREN || |
| 4145 type == TokenType.INDEX); |
| 4147 return operand; | 4146 return operand; |
| 4148 } | 4147 } |
| 4149 if (!_currentToken.type.isIncrementOperator) { | 4148 if (!_currentToken.type.isIncrementOperator) { |
| 4150 return operand; | 4149 return operand; |
| 4151 } | 4150 } |
| 4152 _ensureAssignable(operand); | 4151 _ensureAssignable(operand); |
| 4153 Token operator = getAndAdvance(); | 4152 Token operator = getAndAdvance(); |
| 4154 return new PostfixExpression(operand, operator); | 4153 return new PostfixExpression(operand, operator); |
| 4155 } | 4154 } |
| 4156 | 4155 |
| (...skipping 3421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7578 return fakeEquals; | 7577 return fakeEquals; |
| 7579 } | 7578 } |
| 7580 depth -= 2; | 7579 depth -= 2; |
| 7581 } | 7580 } |
| 7582 next = next.next; | 7581 next = next.next; |
| 7583 } | 7582 } |
| 7584 return next; | 7583 return next; |
| 7585 } | 7584 } |
| 7586 | 7585 |
| 7587 /** | 7586 /** |
| 7587 * Assuming that the current token is an index token ('[]'), split it into two |
| 7588 * tokens ('[' and ']'), leaving the left bracket as the current token. |
| 7589 */ |
| 7590 void _splitIndex() { |
| 7591 // Split the token into two separate tokens. |
| 7592 BeginToken leftBracket = _createToken( |
| 7593 _currentToken, TokenType.OPEN_SQUARE_BRACKET, |
| 7594 isBegin: true); |
| 7595 Token rightBracket = |
| 7596 new Token(TokenType.CLOSE_SQUARE_BRACKET, _currentToken.offset + 1); |
| 7597 leftBracket.endToken = rightBracket; |
| 7598 rightBracket.setNext(_currentToken.next); |
| 7599 leftBracket.setNext(rightBracket); |
| 7600 _currentToken.previous.setNext(leftBracket); |
| 7601 _currentToken = leftBracket; |
| 7602 } |
| 7603 |
| 7604 /** |
| 7588 * Return `true` if the given [token] has the given [type]. | 7605 * Return `true` if the given [token] has the given [type]. |
| 7589 */ | 7606 */ |
| 7590 bool _tokenMatches(Token token, TokenType type) => token.type == type; | 7607 bool _tokenMatches(Token token, TokenType type) => token.type == type; |
| 7591 | 7608 |
| 7592 /** | 7609 /** |
| 7593 * Return `true` if the given [token] is a valid identifier. Valid identifiers | 7610 * Return `true` if the given [token] is a valid identifier. Valid identifiers |
| 7594 * include built-in identifiers (pseudo-keywords). | 7611 * include built-in identifiers (pseudo-keywords). |
| 7595 */ | 7612 */ |
| 7596 bool _tokenMatchesIdentifier(Token token) => | 7613 bool _tokenMatchesIdentifier(Token token) => |
| 7597 _tokenMatches(token, TokenType.IDENTIFIER) || | 7614 _tokenMatches(token, TokenType.IDENTIFIER) || |
| (...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8100 */ | 8117 */ |
| 8101 Parser_SyntheticKeywordToken(Keyword keyword, int offset) | 8118 Parser_SyntheticKeywordToken(Keyword keyword, int offset) |
| 8102 : super(keyword, offset); | 8119 : super(keyword, offset); |
| 8103 | 8120 |
| 8104 @override | 8121 @override |
| 8105 int get length => 0; | 8122 int get length => 0; |
| 8106 | 8123 |
| 8107 @override | 8124 @override |
| 8108 Token copy() => new Parser_SyntheticKeywordToken(keyword, offset); | 8125 Token copy() => new Parser_SyntheticKeywordToken(keyword, offset); |
| 8109 } | 8126 } |
| OLD | NEW |