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

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

Issue 10823090: Fix for issue 2439 (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 5 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/SyntaxTest.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
===================================================================
--- compiler/java/com/google/dart/compiler/parser/DartParser.java (revision 10019)
+++ compiler/java/com/google/dart/compiler/parser/DartParser.java (working copy)
@@ -2368,6 +2368,63 @@
}
}
+ private int skipStringLiteral(int offset) {
+ Token token = peek(offset);
+ while (token == Token.STRING || token == Token.STRING_SEGMENT || token == Token.STRING_EMBED_EXP_START) {
+ switch(token) {
+ case STRING:
+ offset = offset + 1;
+
+ case STRING_SEGMENT:
+ case STRING_EMBED_EXP_START:
+ offset = skipStringInterpolation(offset);
+ }
+ token = peek(offset);
+ }
+ return offset;
+ }
+
+ private int skipStringInterpolation(int offset) {
+ Token token = peek(offset);
+ if (token == Token.STRING_LAST_SEGMENT) {
+ return -1;
+ }
+ boolean inString = true;
+ while (inString) { // Iterate until we find the last string segment.
+ switch (token) {
+ case STRING_SEGMENT:
+ offset = offset + 1;
+ token = peek(offset);
+ break;
+ case STRING_LAST_SEGMENT:
+ offset = offset + 1;
+ token = peek(offset);
+ inString = false;
+ break;
+ case STRING_EMBED_EXP_START: {
+ offset = offset + 1;
+ token = peek(offset);
+ while (token != Token.EOS && token != Token.STRING_EMBED_EXP_END && token != Token.STRING_LAST_SEGMENT) {
+ if (token == Token.STRING || token == Token.STRING_SEGMENT || token == Token.STRING_EMBED_EXP_START) {
+ offset = skipStringLiteral(offset);
+ } else {
+ offset = offset + 1;
+ }
+ token = peek(offset);
+ }
+ if (token != Token.STRING_EMBED_EXP_END) {
+ inString = Token.STRING_LAST_SEGMENT != token;
+ }
+ break;
+ }
+ default:
+ inString = false;
+ break;
+ }
+ }
+ return offset;
+ }
+
/**
* Parse any literal that is not a function literal (those have already been
* handled before this method is called, so we don't need to handle them
@@ -3618,6 +3675,13 @@
}
case LBRACE:
+ Token token = peek(1);
+ if (token == Token.STRING || token == Token.STRING_SEGMENT || token == Token.STRING_EMBED_EXP_START) {
+ int offset = skipStringLiteral(1);
+ if (peek(offset) == Token.COLON) {
+ return parseExpressionStatement();
+ }
+ }
return parseBlock();
case CONTINUE:
« no previous file with comments | « no previous file | compiler/javatests/com/google/dart/compiler/parser/SyntaxTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698