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

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

Issue 2899043006: cleanup fasta token classes (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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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 licenset hat can be found in the LICENSE file. 3 // BSD-style licenset hat can be found in the LICENSE file.
4 4
5 library fasta.scanner.recover; 5 library fasta.scanner.recover;
6 6
7 import '../../scanner/token.dart' show TokenType; 7 import '../../scanner/token.dart' show TokenType;
8 8
9 import '../fasta_codes.dart' 9 import '../fasta_codes.dart'
10 show 10 show
11 FastaCode, 11 FastaCode,
12 codeAsciiControlCharacter, 12 codeAsciiControlCharacter,
13 codeEncoding, 13 codeEncoding,
14 codeExpectedHexDigit, 14 codeExpectedHexDigit,
15 codeMissingExponent, 15 codeMissingExponent,
16 codeNonAsciiIdentifier, 16 codeNonAsciiIdentifier,
17 codeNonAsciiWhitespace, 17 codeNonAsciiWhitespace,
18 codeUnexpectedDollarInString, 18 codeUnexpectedDollarInString,
19 codeUnmatchedToken, 19 codeUnmatchedToken,
20 codeUnterminatedComment, 20 codeUnterminatedComment,
21 codeUnterminatedString; 21 codeUnterminatedString;
22 22
23 import '../../scanner/token.dart' show Token; 23 import '../../scanner/token.dart' show Token;
24 24
25 import 'token.dart' show StringToken, SymbolToken; 25 import 'token.dart' show StringToken;
26 26
27 import 'error_token.dart' show NonAsciiIdentifierToken, ErrorToken; 27 import 'error_token.dart' show NonAsciiIdentifierToken, ErrorToken;
28 28
29 /// Recover from errors in [tokens]. The original sources are provided as 29 /// Recover from errors in [tokens]. The original sources are provided as
30 /// [bytes]. [lineStarts] are the beginning character offsets of lines, and 30 /// [bytes]. [lineStarts] are the beginning character offsets of lines, and
31 /// must be updated if recovery is performed rewriting the original source 31 /// must be updated if recovery is performed rewriting the original source
32 /// code. 32 /// code.
33 Token defaultRecoveryStrategy( 33 Token defaultRecoveryStrategy(
34 List<int> bytes, Token tokens, List<int> lineStarts) { 34 List<int> bytes, Token tokens, List<int> lineStarts) {
35 // See [Parser.reportErrorToken](../parser/src/parser.dart) for how 35 // See [Parser.reportErrorToken](../parser/src/parser.dart) for how
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 if (goodTail == null) { 209 if (goodTail == null) {
210 good = current; 210 good = current;
211 } else { 211 } else {
212 goodTail.next = current; 212 goodTail.next = current;
213 current.previous = goodTail; 213 current.previous = goodTail;
214 } 214 }
215 beforeGoodTail = goodTail; 215 beforeGoodTail = goodTail;
216 goodTail = current; 216 goodTail = current;
217 } 217 }
218 218
219 error.previous = new SymbolToken.eof(-1)..next = error; 219 error.previous = new Token.eof(-1)..next = error;
220 Token tail; 220 Token tail;
221 if (good != null) { 221 if (good != null) {
222 errorTail.next = good; 222 errorTail.next = good;
223 good.previous = errorTail; 223 good.previous = errorTail;
224 tail = goodTail; 224 tail = goodTail;
225 } else { 225 } else {
226 tail = errorTail; 226 tail = errorTail;
227 } 227 }
228 if (!tail.isEof) tail.next = new SymbolToken.eof(tail.end)..previous = tail; 228 if (!tail.isEof) tail.next = new Token.eof(tail.end)..previous = tail;
229 return error; 229 return error;
230 } 230 }
231 231
232 Token synthesizeToken(int charOffset, String value, TokenType type) { 232 Token synthesizeToken(int charOffset, String value, TokenType type) {
233 return new StringToken.fromString(type, value, charOffset); 233 return new StringToken.fromString(type, value, charOffset);
234 } 234 }
235 235
236 Token skipToEof(Token token) { 236 Token skipToEof(Token token) {
237 while (!token.isEof) { 237 while (!token.isEof) {
238 token = token.next; 238 token = token.next;
239 } 239 }
240 return token; 240 return token;
241 } 241 }
242 242
243 String closeBraceFor(String openBrace) { 243 String closeBraceFor(String openBrace) {
244 return const { 244 return const {
245 '(': ')', 245 '(': ')',
246 '[': ']', 246 '[': ']',
247 '{': '}', 247 '{': '}',
248 '<': '>', 248 '<': '>',
249 r'${': '}', 249 r'${': '}',
250 }[openBrace]; 250 }[openBrace];
251 } 251 }
OLDNEW
« no previous file with comments | « pkg/front_end/lib/src/fasta/scanner/error_token.dart ('k') | pkg/front_end/lib/src/fasta/scanner/token.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698