| OLD | NEW |
| 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 license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import 'dart:convert' show UTF8; | 5 import 'dart:convert' show UTF8; |
| 6 | 6 |
| 7 import 'package:front_end/src/fasta/scanner/recover.dart' | 7 import 'package:front_end/src/fasta/scanner/recover.dart' |
| 8 show defaultRecoveryStrategy; | 8 show defaultRecoveryStrategy; |
| 9 import 'package:front_end/src/fasta/scanner.dart' as fasta; | 9 import 'package:front_end/src/fasta/scanner.dart' as fasta; |
| 10 import 'package:front_end/src/fasta/scanner/token.dart' as fasta; | 10 import 'package:front_end/src/fasta/scanner/token.dart' as fasta; |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 var token = firstToken; | 312 var token = firstToken; |
| 313 // The default recovery strategy used by scanString | 313 // The default recovery strategy used by scanString |
| 314 // places all error tokens at the head of the stream. | 314 // places all error tokens at the head of the stream. |
| 315 while (token.type == analyzer.TokenType.BAD_INPUT) { | 315 while (token.type == analyzer.TokenType.BAD_INPUT) { |
| 316 translateErrorToken(token, | 316 translateErrorToken(token, |
| 317 (ScannerErrorCode errorCode, int offset, List<Object> arguments) { | 317 (ScannerErrorCode errorCode, int offset, List<Object> arguments) { |
| 318 listener.errors.add(new TestError(offset, errorCode, arguments)); | 318 listener.errors.add(new TestError(offset, errorCode, arguments)); |
| 319 }); | 319 }); |
| 320 token = token.next; | 320 token = token.next; |
| 321 } | 321 } |
| 322 if (!token.previousToken.isEof) { | 322 if (!token.previous.isEof) { |
| 323 var head = new fasta.SymbolToken(analyzer.TokenType.EOF, -1); | 323 var head = new fasta.SymbolToken(analyzer.TokenType.EOF, -1); |
| 324 token.previous = head; | 324 token.previous = head; |
| 325 head.next = token; | 325 head.next = token; |
| 326 } | 326 } |
| 327 return token; | 327 return token; |
| 328 } | 328 } |
| 329 | 329 |
| 330 /// Assert that the tokens in the stream are correctly connected prev/next. | 330 /// Assert that the tokens in the stream are correctly connected prev/next. |
| 331 void assertValidTokenStream(fasta.Token firstToken, | 331 void assertValidTokenStream(fasta.Token firstToken, |
| 332 {bool errorsFirst: false}) { | 332 {bool errorsFirst: false}) { |
| 333 fasta.Token token = firstToken; | 333 fasta.Token token = firstToken; |
| 334 fasta.Token previous = token.previousToken; | 334 fasta.Token previous = token.previous; |
| 335 expect(previous.isEof, isTrue, reason: 'Missing leading EOF'); | 335 expect(previous.isEof, isTrue, reason: 'Missing leading EOF'); |
| 336 expect(previous.next, token, reason: 'Invalid leading EOF'); | 336 expect(previous.next, token, reason: 'Invalid leading EOF'); |
| 337 expect(previous.previous, previous, reason: 'Invalid leading EOF'); | 337 expect(previous.previous, previous, reason: 'Invalid leading EOF'); |
| 338 if (errorsFirst) { | 338 if (errorsFirst) { |
| 339 while (!token.isEof && token is fasta.ErrorToken) { | 339 while (!token.isEof && token is fasta.ErrorToken) { |
| 340 token = token.next; | 340 token = token.next; |
| 341 } | 341 } |
| 342 } | 342 } |
| 343 var isNotErrorToken = isNot(new isInstanceOf<fasta.ErrorToken>()); | 343 var isNotErrorToken = isNot(new isInstanceOf<fasta.ErrorToken>()); |
| 344 while (!token.isEof) { | 344 while (!token.isEof) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 369 } else if (token is fasta.UnmatchedToken) { | 369 } else if (token is fasta.UnmatchedToken) { |
| 370 expect(lastClosedGroup?.endGroup?.next, same(token), | 370 expect(lastClosedGroup?.endGroup?.next, same(token), |
| 371 reason: 'Unexpected error token for group: $lastClosedGroup'); | 371 reason: 'Unexpected error token for group: $lastClosedGroup'); |
| 372 expect(token.begin, lastClosedGroup); | 372 expect(token.begin, lastClosedGroup); |
| 373 } | 373 } |
| 374 token = token.next; | 374 token = token.next; |
| 375 } | 375 } |
| 376 expect(openerStack, isEmpty, reason: 'Missing closers'); | 376 expect(openerStack, isEmpty, reason: 'Missing closers'); |
| 377 } | 377 } |
| 378 } | 378 } |
| OLD | NEW |