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

Unified Diff: compiler/java/com/google/dart/compiler/parser/DartParser.java

Issue 10025009: Add more parser error recovery for List and Map literals (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 8 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 | compiler/javatests/com/google/dart/compiler/parser/ParserRecoveryTest.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compiler/java/com/google/dart/compiler/parser/DartParser.java
diff --git a/compiler/java/com/google/dart/compiler/parser/DartParser.java b/compiler/java/com/google/dart/compiler/parser/DartParser.java
index 87042360b6991d6f06e206768cb9d54efcae8ce7..48aabd68c8796944bde6868f02ab8a6207ad1062 100644
--- a/compiler/java/com/google/dart/compiler/parser/DartParser.java
+++ b/compiler/java/com/google/dart/compiler/parser/DartParser.java
@@ -2245,6 +2245,7 @@ public class DartParser extends CompletionHooksParserBase {
* <pre> mapLiteral : '{' (mapLiteralEntry (',' mapLiteralEntry)* ','?)? '}' ;
* </pre>
*/
+ @Terminals(tokens={Token.RBRACE, Token.COMMA})
private DartExpression parseMapLiteral(boolean isConst, List<DartTypeNode> typeArguments) {
beginMapLiteral();
expect(Token.LBRACE);
@@ -2267,16 +2268,24 @@ public class DartParser extends CompletionHooksParserBase {
if (entry != null) {
entries.add(entry);
}
- switch (peek(0)) {
+ Token nextToken = peek(0);
+ switch (nextToken) {
+ // Must keep in sync with @Terminals above
case COMMA:
consume(Token.COMMA);
break;
+ // Must keep in sync with @Terminals above
case RBRACE:
break;
default:
if (entry == null) {
- // Ensure the parser makes progress.
- ctx.advance();
+ Set<Token> terminals = collectTerminalAnnotations();
+ if (!terminals.contains(nextToken) && !looksLikeTopLevelKeyword()) {
+ if (entry == null) {
+ // Ensure the parser makes progress.
+ ctx.advance();
+ }
+ }
}
reportError(position(), ParserErrorCode.EXPECTED_COMMA_OR_RIGHT_BRACE);
break;
@@ -2298,6 +2307,7 @@ public class DartParser extends CompletionHooksParserBase {
* ;
* </pre>
*/
+ @Terminals(tokens={Token.RBRACK, Token.COMMA})
private DartExpression parseArrayLiteral(boolean isConst, List<DartTypeNode> typeArguments) {
beginArrayLiteral();
expect(Token.LBRACK);
@@ -2305,10 +2315,12 @@ public class DartParser extends CompletionHooksParserBase {
List<DartExpression> exprs = new ArrayList<DartExpression>();
while (!match(Token.RBRACK) && !EOS()) {
exprs.add(parseExpression());
+ // Must keep in sync with @Terminals above
if (!optional(Token.COMMA)) {
break;
}
}
+ // Must keep in sync with @Terminals above
expect(Token.RBRACK);
setAllowFunctionExpression(save);
return done(new DartArrayLiteral(isConst, typeArguments, exprs));
« no previous file with comments | « no previous file | compiler/javatests/com/google/dart/compiler/parser/ParserRecoveryTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698