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

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

Issue 2907093002: Revert "improve fasta unterminated string recovery" (Closed)
Patch Set: Created 3 years, 6 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 unified diff | Download patch
« no previous file with comments | « pkg/front_end/lib/src/fasta/quote.dart ('k') | pkg/front_end/lib/src/scanner/token.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library fasta.scanner.abstract_scanner; 5 library fasta.scanner.abstract_scanner;
6 6
7 import 'dart:collection' show ListMixin; 7 import 'dart:collection' show ListMixin;
8 8
9 import 'dart:typed_data' show Uint16List, Uint32List; 9 import 'dart:typed_data' show Uint16List, Uint32List;
10 10
11 import '../../scanner/token.dart' 11 import '../../scanner/token.dart' show BeginToken, Token, TokenType;
12 show BeginToken, SyntheticStringToken, Token, TokenType;
13 12
14 import '../scanner.dart' 13 import '../scanner.dart'
15 show ErrorToken, Keyword, Scanner, buildUnexpectedCharacterToken; 14 show ErrorToken, Keyword, Scanner, buildUnexpectedCharacterToken;
16 15
17 import 'error_token.dart' show UnterminatedToken; 16 import 'error_token.dart' show UnterminatedToken;
18 17
19 import 'keyword_state.dart' show KeywordState; 18 import 'keyword_state.dart' show KeywordState;
20 19
21 import 'token.dart' show CommentToken, DartDocToken; 20 import 'token.dart' show CommentToken, DartDocToken;
22 21
(...skipping 995 matching lines...) Expand 10 before | Expand all | Expand 10 after
1018 next = tokenizeStringInterpolation(start, asciiOnly); 1017 next = tokenizeStringInterpolation(start, asciiOnly);
1019 start = scanOffset; 1018 start = scanOffset;
1020 asciiOnly = true; 1019 asciiOnly = true;
1021 continue; 1020 continue;
1022 } 1021 }
1023 if (next <= $CR && 1022 if (next <= $CR &&
1024 (identical(next, $LF) || 1023 (identical(next, $LF) ||
1025 identical(next, $CR) || 1024 identical(next, $CR) ||
1026 identical(next, $EOF))) { 1025 identical(next, $EOF))) {
1027 if (!asciiOnly) handleUnicode(start); 1026 if (!asciiOnly) handleUnicode(start);
1028 return unterminatedString(quoteChar, start, asciiOnly); 1027 return unterminatedString(quoteChar);
1029 } 1028 }
1030 if (next > 127) asciiOnly = false; 1029 if (next > 127) asciiOnly = false;
1031 next = advance(); 1030 next = advance();
1032 } 1031 }
1033 if (!asciiOnly) handleUnicode(start); 1032 if (!asciiOnly) handleUnicode(start);
1034 // Advance past the quote character. 1033 // Advance past the quote character.
1035 next = advance(); 1034 next = advance();
1036 appendSubstringToken(TokenType.STRING, start, asciiOnly); 1035 appendSubstringToken(TokenType.STRING, start, asciiOnly);
1037 return next; 1036 return next;
1038 } 1037 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1083 int tokenizeSingleLineRawString(int next, int quoteChar, int start) { 1082 int tokenizeSingleLineRawString(int next, int quoteChar, int start) {
1084 bool asciiOnly = true; 1083 bool asciiOnly = true;
1085 while (next != $EOF) { 1084 while (next != $EOF) {
1086 if (identical(next, quoteChar)) { 1085 if (identical(next, quoteChar)) {
1087 if (!asciiOnly) handleUnicode(start); 1086 if (!asciiOnly) handleUnicode(start);
1088 next = advance(); 1087 next = advance();
1089 appendSubstringToken(TokenType.STRING, start, asciiOnly); 1088 appendSubstringToken(TokenType.STRING, start, asciiOnly);
1090 return next; 1089 return next;
1091 } else if (identical(next, $LF) || identical(next, $CR)) { 1090 } else if (identical(next, $LF) || identical(next, $CR)) {
1092 if (!asciiOnly) handleUnicode(start); 1091 if (!asciiOnly) handleUnicode(start);
1093 return unterminatedRawString(quoteChar, start, asciiOnly); 1092 return unterminatedRawString(quoteChar);
1094 } else if (next > 127) { 1093 } else if (next > 127) {
1095 asciiOnly = false; 1094 asciiOnly = false;
1096 } 1095 }
1097 next = advance(); 1096 next = advance();
1098 } 1097 }
1099 if (!asciiOnly) handleUnicode(start); 1098 if (!asciiOnly) handleUnicode(start);
1100 return unterminatedRawString(quoteChar, start, asciiOnly); 1099 return unterminatedRawString(quoteChar);
1101 } 1100 }
1102 1101
1103 int tokenizeMultiLineRawString(int quoteChar, int start) { 1102 int tokenizeMultiLineRawString(int quoteChar, int start) {
1104 bool asciiOnlyString = true; 1103 bool asciiOnlyString = true;
1105 bool asciiOnlyLine = true; 1104 bool asciiOnlyLine = true;
1106 int unicodeStart = start; 1105 int unicodeStart = start;
1107 int next = advance(); // Advance past the (last) quote (of three). 1106 int next = advance(); // Advance past the (last) quote (of three).
1108 outer: 1107 outer:
1109 while (!identical(next, $EOF)) { 1108 while (!identical(next, $EOF)) {
1110 while (!identical(next, quoteChar)) { 1109 while (!identical(next, quoteChar)) {
(...skipping 17 matching lines...) Expand all
1128 next = advance(); 1127 next = advance();
1129 if (identical(next, quoteChar)) { 1128 if (identical(next, quoteChar)) {
1130 if (!asciiOnlyLine) handleUnicode(unicodeStart); 1129 if (!asciiOnlyLine) handleUnicode(unicodeStart);
1131 next = advance(); 1130 next = advance();
1132 appendSubstringToken(TokenType.STRING, start, asciiOnlyString); 1131 appendSubstringToken(TokenType.STRING, start, asciiOnlyString);
1133 return next; 1132 return next;
1134 } 1133 }
1135 } 1134 }
1136 } 1135 }
1137 if (!asciiOnlyLine) handleUnicode(unicodeStart); 1136 if (!asciiOnlyLine) handleUnicode(unicodeStart);
1138 return unterminatedRawMultiLineString(quoteChar, start, asciiOnlyLine); 1137 return unterminatedRawMultiLineString(quoteChar);
1139 } 1138 }
1140 1139
1141 int tokenizeMultiLineString(int quoteChar, int start, bool raw) { 1140 int tokenizeMultiLineString(int quoteChar, int start, bool raw) {
1142 if (raw) return tokenizeMultiLineRawString(quoteChar, start); 1141 if (raw) return tokenizeMultiLineRawString(quoteChar, start);
1143 bool asciiOnlyString = true; 1142 bool asciiOnlyString = true;
1144 bool asciiOnlyLine = true; 1143 bool asciiOnlyLine = true;
1145 int unicodeStart = start; 1144 int unicodeStart = start;
1146 int next = advance(); // Advance past the (last) quote (of three). 1145 int next = advance(); // Advance past the (last) quote (of three).
1147 while (!identical(next, $EOF)) { 1146 while (!identical(next, $EOF)) {
1148 if (identical(next, $$)) { 1147 if (identical(next, $$)) {
(...skipping 30 matching lines...) Expand all
1179 unicodeStart = scanOffset; 1178 unicodeStart = scanOffset;
1180 } 1179 }
1181 lineFeedInMultiline(); 1180 lineFeedInMultiline();
1182 } else if (next > 127) { 1181 } else if (next > 127) {
1183 asciiOnlyString = false; 1182 asciiOnlyString = false;
1184 asciiOnlyLine = false; 1183 asciiOnlyLine = false;
1185 } 1184 }
1186 next = advance(); 1185 next = advance();
1187 } 1186 }
1188 if (!asciiOnlyLine) handleUnicode(unicodeStart); 1187 if (!asciiOnlyLine) handleUnicode(unicodeStart);
1189 return unterminatedMultiLineString(quoteChar, start, asciiOnlyString); 1188 return unterminatedMultiLineString(quoteChar);
1190 } 1189 }
1191 1190
1192 int unexpected(int character) { 1191 int unexpected(int character) {
1193 appendErrorToken(buildUnexpectedCharacterToken(character, tokenStart)); 1192 appendErrorToken(buildUnexpectedCharacterToken(character, tokenStart));
1194 return advanceAfterError(true); 1193 return advanceAfterError(true);
1195 } 1194 }
1196 1195
1197 int unterminated(String prefix, {bool shouldAdvance: true}) { 1196 int unterminated(String prefix, {bool shouldAdvance: true}) {
1198 appendErrorToken(new UnterminatedToken(prefix, tokenStart, stringOffset)); 1197 appendErrorToken(new UnterminatedToken(prefix, tokenStart, stringOffset));
1199 return advanceAfterError(shouldAdvance); 1198 return advanceAfterError(shouldAdvance);
1200 } 1199 }
1201 1200
1202 void terminateUnterminatedString( 1201 int unterminatedString(int quoteChar) {
1203 int start, bool asciiOnlyString, String suffix) { 1202 return unterminated(new String.fromCharCodes([quoteChar]));
1204 if (start < scanOffset) {
1205 appendSubstringToken(TokenType.STRING, start, asciiOnlyString);
1206 }
1207 beginToken();
1208 appendToken(
1209 new SyntheticStringToken(TokenType.STRING, suffix, tokenStart, 0));
1210 } 1203 }
1211 1204
1212 int unterminatedString(int quoteChar, int start, bool asciiOnlyString) { 1205 int unterminatedRawString(int quoteChar) {
1213 String suffix = new String.fromCharCodes([quoteChar]); 1206 return unterminated('r${new String.fromCharCodes([quoteChar])}');
1214 terminateUnterminatedString(start, asciiOnlyString, suffix);
1215 return unterminated(suffix);
1216 } 1207 }
1217 1208
1218 int unterminatedRawString(int quoteChar, int start, bool asciiOnlyString) { 1209 int unterminatedMultiLineString(int quoteChar) {
1219 String suffix = new String.fromCharCodes([quoteChar]); 1210 return unterminated(
1220 terminateUnterminatedString(start, asciiOnlyString, suffix); 1211 new String.fromCharCodes([quoteChar, quoteChar, quoteChar]));
1221 return unterminated('r$suffix');
1222 } 1212 }
1223 1213
1224 int unterminatedMultiLineString( 1214 int unterminatedRawMultiLineString(int quoteChar) {
1225 int quoteChar, int start, bool asciiOnlyString) { 1215 return unterminated(
1226 String suffix = new String.fromCharCodes([quoteChar, quoteChar, quoteChar]); 1216 'r${new String.fromCharCodes([quoteChar, quoteChar, quoteChar])}');
1227 terminateUnterminatedString(start, asciiOnlyString, suffix);
1228 return unterminated(suffix);
1229 }
1230
1231 int unterminatedRawMultiLineString(
1232 int quoteChar, int start, bool asciiOnlyString) {
1233 String suffix = new String.fromCharCodes([quoteChar, quoteChar, quoteChar]);
1234 terminateUnterminatedString(start, asciiOnlyString, suffix);
1235 return unterminated('r$suffix');
1236 } 1217 }
1237 1218
1238 int advanceAfterError(bool shouldAdvance) { 1219 int advanceAfterError(bool shouldAdvance) {
1239 if (atEndOfFile()) return $EOF; 1220 if (atEndOfFile()) return $EOF;
1240 if (shouldAdvance) { 1221 if (shouldAdvance) {
1241 return advance(); // Ensure progress. 1222 return advance(); // Ensure progress.
1242 } else { 1223 } else {
1243 return -1; 1224 return -1;
1244 } 1225 }
1245 } 1226 }
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1324 switchToUint32(newLength); 1305 switchToUint32(newLength);
1325 } 1306 }
1326 } 1307 }
1327 1308
1328 void switchToUint32(int newLength) { 1309 void switchToUint32(int newLength) {
1329 final newArray = new Uint32List(newLength); 1310 final newArray = new Uint32List(newLength);
1330 newArray.setRange(0, arrayLength, array); 1311 newArray.setRange(0, arrayLength, array);
1331 array = newArray; 1312 array = newArray;
1332 } 1313 }
1333 } 1314 }
OLDNEW
« no previous file with comments | « pkg/front_end/lib/src/fasta/quote.dart ('k') | pkg/front_end/lib/src/scanner/token.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698