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

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

Issue 2915093002: improve fasta unterminated string recovery (Closed)
Patch Set: fix dartdoc 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
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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.array_based_scanner; 5 library fasta.scanner.array_based_scanner;
6 6
7 import 'error_token.dart' show ErrorToken, UnmatchedToken; 7 import 'error_token.dart' show ErrorToken, UnmatchedToken;
8 8
9 import '../../scanner/token.dart' 9 import '../../scanner/token.dart'
10 show 10 show
11 BeginToken, 11 BeginToken,
12 BeginTokenWithComment, 12 BeginTokenWithComment,
13 Keyword, 13 Keyword,
14 KeywordTokenWithComment, 14 KeywordTokenWithComment,
15 SyntheticToken, 15 SyntheticToken,
16 Token, 16 Token,
17 TokenType, 17 TokenType,
18 TokenWithComment; 18 TokenWithComment;
19 19
20 import 'token.dart' show StringToken; 20 import '../../scanner/token.dart' as analyzer show StringToken;
21 21
22 import 'token_constants.dart' 22 import 'token_constants.dart'
23 show 23 show
24 LT_TOKEN, 24 LT_TOKEN,
25 OPEN_CURLY_BRACKET_TOKEN, 25 OPEN_CURLY_BRACKET_TOKEN,
26 OPEN_PAREN_TOKEN, 26 OPEN_PAREN_TOKEN,
27 STRING_INTERPOLATION_TOKEN; 27 STRING_INTERPOLATION_TOKEN;
28 28
29 import 'characters.dart' show $LF, $STX; 29 import 'characters.dart' show $LF, $STX;
30 30
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 groupingStack.head.endGroup = tail; 215 groupingStack.head.endGroup = tail;
216 groupingStack = groupingStack.tail; 216 groupingStack = groupingStack.tail;
217 } 217 }
218 } 218 }
219 219
220 void appendErrorToken(ErrorToken token) { 220 void appendErrorToken(ErrorToken token) {
221 hasErrors = true; 221 hasErrors = true;
222 appendToken(token); 222 appendToken(token);
223 } 223 }
224 224
225 @override
225 void appendSubstringToken(TokenType type, int start, bool asciiOnly, 226 void appendSubstringToken(TokenType type, int start, bool asciiOnly,
226 [int extraOffset = 0]) { 227 [int extraOffset = 0]) {
227 appendToken(createSubstringToken(type, start, asciiOnly, extraOffset)); 228 appendToken(createSubstringToken(type, start, asciiOnly, extraOffset));
228 } 229 }
229 230
231 @override
232 void appendSyntheticSubstringToken(
233 TokenType type, int start, bool asciiOnly, String closingQuotes) {
234 appendToken(
235 createSyntheticSubstringToken(type, start, asciiOnly, closingQuotes));
236 }
237
230 /** 238 /**
231 * Returns a new substring from the scan offset [start] to the current 239 * Returns a new substring from the scan offset [start] to the current
232 * [scanOffset] plus the [extraOffset]. For example, if the current 240 * [scanOffset] plus the [extraOffset]. For example, if the current
233 * scanOffset is 10, then [appendSubstringToken(5, -1)] will append the 241 * scanOffset is 10, then [appendSubstringToken(5, -1)] will append the
234 * substring string [5,9). 242 * substring string [5,9).
235 * 243 *
236 * Note that [extraOffset] can only be used if the covered character(s) are 244 * Note that [extraOffset] can only be used if the covered character(s) are
237 * known to be ASCII. 245 * known to be ASCII.
238 */ 246 */
239 StringToken createSubstringToken(TokenType type, int start, bool asciiOnly, 247 analyzer.StringToken createSubstringToken(
248 TokenType type, int start, bool asciiOnly,
240 [int extraOffset = 0]); 249 [int extraOffset = 0]);
241 250
242 /** 251 /**
252 * Returns a new synthetic substring from the scan offset [start]
253 * to the current [scanOffset] plus the [closingQuotes].
254 * The [closingQuotes] are appended to the unterminated string
255 * literal's lexeme but the returned token's length will *not* include
256 * those closing quotes so as to be true to the original source.
257 */
258 analyzer.StringToken createSyntheticSubstringToken(
259 TokenType type, int start, bool asciiOnly, String closingQuotes);
260
261 /**
243 * This method is called to discard '<' from the "grouping" stack. 262 * This method is called to discard '<' from the "grouping" stack.
244 * 263 *
245 * [PartialParser.skipExpression] relies on the fact that we do not 264 * [PartialParser.skipExpression] relies on the fact that we do not
246 * create groups for stuff like: 265 * create groups for stuff like:
247 * [:a = b < c, d = e > f:]. 266 * [:a = b < c, d = e > f:].
248 * 267 *
249 * In other words, this method is called when the scanner recognizes 268 * In other words, this method is called when the scanner recognizes
250 * something which cannot possibly be part of a type parameter/argument 269 * something which cannot possibly be part of a type parameter/argument
251 * list, like the '=' in the above example. 270 * list, like the '=' in the above example.
252 */ 271 */
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 // | 334 // |
316 // next 335 // next
317 // v 336 // v
318 // EOF 337 // EOF
319 TokenType type = closeBraceInfoFor(begin); 338 TokenType type = closeBraceInfoFor(begin);
320 appendToken(new SyntheticToken(type, tokenStart)); 339 appendToken(new SyntheticToken(type, tokenStart));
321 begin.endGroup = tail; 340 begin.endGroup = tail;
322 appendErrorToken(new UnmatchedToken(begin)); 341 appendErrorToken(new UnmatchedToken(begin));
323 } 342 }
324 } 343 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698