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

Unified Diff: pkg/front_end/lib/src/fasta/scanner/abstract_scanner.dart

Issue 2915093002: improve fasta unterminated string recovery (Closed)
Patch Set: Created 3 years, 7 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/front_end/lib/src/fasta/scanner/array_based_scanner.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/front_end/lib/src/fasta/scanner/abstract_scanner.dart
diff --git a/pkg/front_end/lib/src/fasta/scanner/abstract_scanner.dart b/pkg/front_end/lib/src/fasta/scanner/abstract_scanner.dart
index d4a97e0f255a561ece55c8425760c39f873f68e4..4f093939b4f38b5f9cf53b218baf23f5ec30195c 100644
--- a/pkg/front_end/lib/src/fasta/scanner/abstract_scanner.dart
+++ b/pkg/front_end/lib/src/fasta/scanner/abstract_scanner.dart
@@ -162,6 +162,16 @@ abstract class AbstractScanner implements Scanner {
void appendSubstringToken(TokenType type, int start, bool asciiOnly,
[int extraOffset]);
+ /**
+ * Appends a substring from the scan offset [:start:] to the current
scheglov 2017/06/01 16:48:17 I have not seen using "[:X:]" anywhere recently.
danrubel 2017/06/01 17:25:42 Whoops. Copy/paste bug from old style dartdoc. Fix
+ * [:scanOffset:] plus [closingQuotes]. The closing quote(s) will be added
+ * to the unterminated string literal's lexeme but the returned
+ * token's length will *not* include those closing quotes
+ * so as to be true to the original source.
+ */
+ void appendSyntheticSubstringToken(
+ TokenType type, int start, bool asciiOnly, String closingQuotes);
+
/** Documentation in subclass [ArrayBasedScanner]. */
void appendPrecedenceToken(TokenType type);
@@ -1024,7 +1034,7 @@ abstract class AbstractScanner implements Scanner {
identical(next, $CR) ||
identical(next, $EOF))) {
if (!asciiOnly) handleUnicode(start);
- return unterminatedString(quoteChar);
+ return unterminatedString(quoteChar, start, asciiOnly);
}
if (next > 127) asciiOnly = false;
next = advance();
@@ -1089,14 +1099,14 @@ abstract class AbstractScanner implements Scanner {
return next;
} else if (identical(next, $LF) || identical(next, $CR)) {
if (!asciiOnly) handleUnicode(start);
- return unterminatedRawString(quoteChar);
+ return unterminatedRawString(quoteChar, start, asciiOnly);
} else if (next > 127) {
asciiOnly = false;
}
next = advance();
}
if (!asciiOnly) handleUnicode(start);
- return unterminatedRawString(quoteChar);
+ return unterminatedRawString(quoteChar, start, asciiOnly);
}
int tokenizeMultiLineRawString(int quoteChar, int start) {
@@ -1134,7 +1144,7 @@ abstract class AbstractScanner implements Scanner {
}
}
if (!asciiOnlyLine) handleUnicode(unicodeStart);
- return unterminatedRawMultiLineString(quoteChar);
+ return unterminatedRawMultiLineString(quoteChar, start, asciiOnlyLine);
}
int tokenizeMultiLineString(int quoteChar, int start, bool raw) {
@@ -1185,7 +1195,7 @@ abstract class AbstractScanner implements Scanner {
next = advance();
}
if (!asciiOnlyLine) handleUnicode(unicodeStart);
- return unterminatedMultiLineString(quoteChar);
+ return unterminatedMultiLineString(quoteChar, start, asciiOnlyString);
}
int unexpected(int character) {
@@ -1198,22 +1208,37 @@ abstract class AbstractScanner implements Scanner {
return advanceAfterError(shouldAdvance);
}
- int unterminatedString(int quoteChar) {
- return unterminated(new String.fromCharCodes([quoteChar]));
+ void terminateUnterminatedString(
+ int start, bool asciiOnlyString, String closingQuotes) {
+ appendSyntheticSubstringToken(
+ TokenType.STRING, start, asciiOnlyString, closingQuotes);
+ beginToken();
+ }
+
+ int unterminatedString(int quoteChar, int start, bool asciiOnlyString) {
+ String suffix = new String.fromCharCodes([quoteChar]);
+ terminateUnterminatedString(start, asciiOnlyString, suffix);
+ return unterminated(suffix);
}
- int unterminatedRawString(int quoteChar) {
- return unterminated('r${new String.fromCharCodes([quoteChar])}');
+ int unterminatedRawString(int quoteChar, int start, bool asciiOnlyString) {
+ String suffix = new String.fromCharCodes([quoteChar]);
+ terminateUnterminatedString(start, asciiOnlyString, suffix);
+ return unterminated('r$suffix');
}
- int unterminatedMultiLineString(int quoteChar) {
- return unterminated(
- new String.fromCharCodes([quoteChar, quoteChar, quoteChar]));
+ int unterminatedMultiLineString(
+ int quoteChar, int start, bool asciiOnlyString) {
+ String suffix = new String.fromCharCodes([quoteChar, quoteChar, quoteChar]);
+ terminateUnterminatedString(start, asciiOnlyString, suffix);
+ return unterminated(suffix);
}
- int unterminatedRawMultiLineString(int quoteChar) {
- return unterminated(
- 'r${new String.fromCharCodes([quoteChar, quoteChar, quoteChar])}');
+ int unterminatedRawMultiLineString(
+ int quoteChar, int start, bool asciiOnlyString) {
+ String suffix = new String.fromCharCodes([quoteChar, quoteChar, quoteChar]);
+ terminateUnterminatedString(start, asciiOnlyString, suffix);
+ return unterminated('r$suffix');
}
int advanceAfterError(bool shouldAdvance) {
« no previous file with comments | « no previous file | pkg/front_end/lib/src/fasta/scanner/array_based_scanner.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698