Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(193)

Unified Diff: pkg/analyzer/lib/src/generated/parser.dart

Issue 2444453002: Improve error recovery (issue 27646) (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/parser_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/generated/parser.dart
diff --git a/pkg/analyzer/lib/src/generated/parser.dart b/pkg/analyzer/lib/src/generated/parser.dart
index b12d26f888fc2c56a0fffacfc3ca62cc08bd5c93..d9e8d6e841f1b31a9f959bb4a71b9d2db07fa5e2 100644
--- a/pkg/analyzer/lib/src/generated/parser.dart
+++ b/pkg/analyzer/lib/src/generated/parser.dart
@@ -780,6 +780,13 @@ class Parser {
}
Token operator = getAndAdvance();
return new PropertyAccess(prefix, operator, parseSimpleIdentifier());
+ } else if (type == TokenType.INDEX) {
+ _splitIndex();
+ Token leftBracket = getAndAdvance();
+ Expression index = parseSimpleIdentifier();
+ Token rightBracket = getAndAdvance();
+ return new IndexExpression.forTarget(
+ prefix, leftBracket, index, rightBracket);
} else {
if (!optional) {
// Report the missing selector.
@@ -3510,19 +3517,9 @@ class Parser {
*/
ListLiteral parseListLiteral(Token modifier, TypeArgumentList typeArguments) {
if (_matches(TokenType.INDEX)) {
- // Split the token into two separate tokens.
- BeginToken leftBracket = _createToken(
- _currentToken, TokenType.OPEN_SQUARE_BRACKET,
- isBegin: true);
- Token rightBracket =
- new Token(TokenType.CLOSE_SQUARE_BRACKET, _currentToken.offset + 1);
- leftBracket.endToken = rightBracket;
- rightBracket.setNext(_currentToken.next);
- leftBracket.setNext(rightBracket);
- _currentToken.previous.setNext(leftBracket);
- _currentToken = _currentToken.next;
+ _splitIndex();
return new ListLiteral(
- modifier, typeArguments, leftBracket, null, rightBracket);
+ modifier, typeArguments, getAndAdvance(), null, getAndAdvance());
}
Token leftBracket = getAndAdvance();
if (_matches(TokenType.CLOSE_SQUARE_BRACKET)) {
@@ -4119,7 +4116,8 @@ class Parser {
type == TokenType.PERIOD ||
type == TokenType.QUESTION_PERIOD ||
type == TokenType.OPEN_PAREN ||
- (parseGenericMethods && type == TokenType.LT)) {
+ (parseGenericMethods && type == TokenType.LT) ||
+ type == TokenType.INDEX) {
do {
if (_isLikelyArgumentList()) {
TypeArgumentList typeArguments = _parseOptionalTypeArguments();
@@ -4143,7 +4141,8 @@ class Parser {
} while (type == TokenType.OPEN_SQUARE_BRACKET ||
type == TokenType.PERIOD ||
type == TokenType.QUESTION_PERIOD ||
- type == TokenType.OPEN_PAREN);
+ type == TokenType.OPEN_PAREN ||
+ type == TokenType.INDEX);
return operand;
}
if (!_currentToken.type.isIncrementOperator) {
@@ -7585,6 +7584,24 @@ class Parser {
}
/**
+ * Assuming that the current token is an index token ('[]'), split it into two
+ * tokens ('[' and ']'), leaving the left bracket as the current token.
+ */
+ void _splitIndex() {
+ // Split the token into two separate tokens.
+ BeginToken leftBracket = _createToken(
+ _currentToken, TokenType.OPEN_SQUARE_BRACKET,
+ isBegin: true);
+ Token rightBracket =
+ new Token(TokenType.CLOSE_SQUARE_BRACKET, _currentToken.offset + 1);
+ leftBracket.endToken = rightBracket;
+ rightBracket.setNext(_currentToken.next);
+ leftBracket.setNext(rightBracket);
+ _currentToken.previous.setNext(leftBracket);
+ _currentToken = leftBracket;
+ }
+
+ /**
* Return `true` if the given [token] has the given [type].
*/
bool _tokenMatches(Token token, TokenType type) => token.type == type;
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/parser_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698