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

Unified Diff: dart/sdk/lib/_internal/compiler/implementation/scanner/scanner.dart

Issue 87813002: Fix crashes in scanner. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 1 month 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
Index: dart/sdk/lib/_internal/compiler/implementation/scanner/scanner.dart
diff --git a/dart/sdk/lib/_internal/compiler/implementation/scanner/scanner.dart b/dart/sdk/lib/_internal/compiler/implementation/scanner/scanner.dart
index 8659eadef771a064a9d722556c46d2f6b8b5a5ba..b6e098b13706fd6a71b36e39934d34008c390620 100644
--- a/dart/sdk/lib/_internal/compiler/implementation/scanner/scanner.dart
+++ b/dart/sdk/lib/_internal/compiler/implementation/scanner/scanner.dart
@@ -17,6 +17,8 @@ abstract class Scanner {
}
abstract class AbstractScanner implements Scanner {
+ // TODO(ahe): Move this class to implementation.
+
final bool includeComments;
/**
@@ -186,14 +188,21 @@ abstract class AbstractScanner implements Scanner {
/** Documentation in subclass [ArrayBasedScanner]. */
void discardOpenLt();
- // TODO(ahe): Move this class to implementation.
+ /// Return true when at EOF.
+ bool atEndOfFile();
Token tokenize() {
- int next = advance();
- while (!identical(next, $EOF)) {
- next = bigSwitch(next);
+ while (!atEndOfFile()) {
+ int next = advance();
+ while (!identical(next, $EOF)) {
+ next = bigSwitch(next);
+ }
+ if (atEndOfFile()) {
+ appendEofToken();
+ } else {
+ error('blah');
Johnni Winther 2013/11/26 12:11:12 Strange error message!
ahe 2013/11/29 10:48:38 Done.
+ }
}
- appendEofToken();
if (file != null) {
file.length = stringOffset;
@@ -921,7 +930,14 @@ abstract class AbstractScanner implements Scanner {
int tokenizeInterpolatedIdentifier(int next) {
appendPrecedenceToken(STRING_INTERPOLATION_IDENTIFIER_INFO);
beginToken(); // The identifier starts here.
- next = tokenizeKeywordOrIdentifier(next, false);
+
+ if ($a <= next && next <= $z) {
+ next = tokenizeKeywordOrIdentifier(next, false);
+ } else if (($A <= next && next <= $Z) || identical(next, $_)) {
+ next = tokenizeIdentifier(next, scanOffset, false);
+ } else {
+ error("expected identifier or '{'", shouldAdvance: false);
+ }
beginToken(); // The string interpolation suffix starts here.
return next;
}
@@ -1035,9 +1051,14 @@ abstract class AbstractScanner implements Scanner {
return error("unterminated string literal");
}
- int error(String message) {
+ int error(String message, {bool shouldAdvance: true}) {
appendStringToken(BAD_INPUT_INFO, message);
- return advance(); // Ensure progress.
+ if (atEndOfFile()) return $EOF;
+ if (shouldAdvance) {
+ return advance(); // Ensure progress.
+ } else {
+ return -1;
+ }
}
void unmatchedBeginGroup(BeginGroupToken begin) {

Powered by Google App Engine
This is Rietveld 408576698