| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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.analyzer.token_utils; | 5 library fasta.analyzer.token_utils; |
| 6 | 6 |
| 7 import 'package:front_end/src/scanner/token.dart' show Token; | 7 import 'package:front_end/src/scanner/token.dart' show Token; |
| 8 | 8 |
| 9 import 'package:front_end/src/fasta/scanner/token.dart' show SymbolToken; | |
| 10 | |
| 11 import 'package:front_end/src/fasta/scanner/token_constants.dart'; | 9 import 'package:front_end/src/fasta/scanner/token_constants.dart'; |
| 12 | 10 |
| 13 import 'package:front_end/src/scanner/errors.dart' show translateErrorToken; | 11 import 'package:front_end/src/scanner/errors.dart' show translateErrorToken; |
| 14 | 12 |
| 15 import 'package:front_end/src/scanner/errors.dart' as analyzer | 13 import 'package:front_end/src/scanner/errors.dart' as analyzer |
| 16 show ScannerErrorCode; | 14 show ScannerErrorCode; |
| 17 | 15 |
| 18 /// Class capable of converting a stream of Fasta tokens to a stream of analyzer | 16 /// Class capable of converting a stream of Fasta tokens to a stream of analyzer |
| 19 /// tokens. | 17 /// tokens. |
| 20 /// | 18 /// |
| 21 /// This is a class rather than an ordinary method so that it can be subclassed | 19 /// This is a class rather than an ordinary method so that it can be subclassed |
| 22 /// in tests. | 20 /// in tests. |
| 23 class ToAnalyzerTokenStreamConverter { | 21 class ToAnalyzerTokenStreamConverter { |
| 24 /// Converts a stream of Fasta tokens (starting with [token] and continuing to | 22 /// Converts a stream of Fasta tokens (starting with [token] and continuing to |
| 25 /// EOF) to a stream of analyzer tokens. This modifies the fasta token stream | 23 /// EOF) to a stream of analyzer tokens. This modifies the fasta token stream |
| 26 /// to be an analyzer token stream by removing error tokens and reporting | 24 /// to be an analyzer token stream by removing error tokens and reporting |
| 27 /// those errors to the associated error listener. | 25 /// those errors to the associated error listener. |
| 28 Token convertTokens(Token firstToken) { | 26 Token convertTokens(Token firstToken) { |
| 29 Token previous = new SymbolToken.eof(-1); | 27 Token previous = new Token.eof(-1); |
| 30 Token token = firstToken; | 28 Token token = firstToken; |
| 31 token.previous = previous; | 29 token.previous = previous; |
| 32 previous.next = token; | 30 previous.next = token; |
| 33 while (!token.isEof) { | 31 while (!token.isEof) { |
| 34 if (token.type.kind == BAD_INPUT_TOKEN) { | 32 if (token.type.kind == BAD_INPUT_TOKEN) { |
| 35 translateErrorToken(token, reportError); | 33 translateErrorToken(token, reportError); |
| 36 previous.next = token.next; | 34 previous.next = token.next; |
| 37 token.next.previous = previous; | 35 token.next.previous = previous; |
| 38 } else { | 36 } else { |
| 39 previous = token; | 37 previous = token; |
| 40 } | 38 } |
| 41 token = token.next; | 39 token = token.next; |
| 42 } | 40 } |
| 43 return firstToken; | 41 return firstToken; |
| 44 } | 42 } |
| 45 | 43 |
| 46 /// Handles an error found during [convertTokens]. | 44 /// Handles an error found during [convertTokens]. |
| 47 /// | 45 /// |
| 48 /// Intended to be overridden by derived classes; by default, does nothing. | 46 /// Intended to be overridden by derived classes; by default, does nothing. |
| 49 void reportError(analyzer.ScannerErrorCode errorCode, int offset, | 47 void reportError(analyzer.ScannerErrorCode errorCode, int offset, |
| 50 List<Object> arguments) {} | 48 List<Object> arguments) {} |
| 51 } | 49 } |
| OLD | NEW |