OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 analyzer.src.dart.scanner.scanner; | 5 library analyzer.src.dart.scanner.scanner; |
6 | 6 |
7 import 'package:analyzer/error/error.dart'; | 7 import 'package:analyzer/error/error.dart'; |
8 import 'package:analyzer/error/listener.dart'; | 8 import 'package:analyzer/error/listener.dart'; |
9 import 'package:analyzer/src/dart/error/syntactic_errors.dart'; | 9 import 'package:analyzer/src/dart/error/syntactic_errors.dart'; |
10 import 'package:analyzer/src/dart/scanner/reader.dart'; | 10 import 'package:analyzer/src/dart/scanner/reader.dart'; |
11 import 'package:analyzer/src/generated/source.dart'; | 11 import 'package:analyzer/src/generated/source.dart'; |
12 import 'package:front_end/src/fasta/scanner.dart' as fasta; | 12 import 'package:front_end/src/fasta/scanner.dart' as fasta; |
13 import 'package:front_end/src/fasta/scanner/abstract_scanner.dart' | |
14 show fastaSupportsGenericMethodComments; | |
15 import 'package:front_end/src/fasta/scanner/precedence.dart' as fasta; | 13 import 'package:front_end/src/fasta/scanner/precedence.dart' as fasta; |
16 import 'package:front_end/src/scanner/errors.dart' show translateErrorToken; | 14 import 'package:front_end/src/scanner/errors.dart' show translateErrorToken; |
17 import 'package:front_end/src/scanner/scanner.dart' as fe; | 15 import 'package:front_end/src/scanner/scanner.dart' as fe; |
18 import 'package:front_end/src/scanner/token.dart' show Token; | 16 import 'package:front_end/src/scanner/token.dart' show Token; |
19 | 17 |
20 export 'package:analyzer/src/dart/error/syntactic_errors.dart'; | 18 export 'package:analyzer/src/dart/error/syntactic_errors.dart'; |
21 export 'package:front_end/src/scanner/scanner.dart' show KeywordState; | 19 export 'package:front_end/src/scanner/scanner.dart' show KeywordState; |
22 | 20 |
23 /** | 21 /** |
24 * The class `Scanner` implements a scanner for Dart code. | 22 * The class `Scanner` implements a scanner for Dart code. |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 | 140 |
143 @override | 141 @override |
144 Token get tail { | 142 Token get tail { |
145 throw 'unsupported operation'; | 143 throw 'unsupported operation'; |
146 } | 144 } |
147 | 145 |
148 @override | 146 @override |
149 Token tokenize() { | 147 Token tokenize() { |
150 // Note: Fasta always supports lazy assignment operators (`&&=` and `||=`), | 148 // Note: Fasta always supports lazy assignment operators (`&&=` and `||=`), |
151 // so we can ignore the `scanLazyAssignmentOperators` flag. | 149 // so we can ignore the `scanLazyAssignmentOperators` flag. |
152 if (scanGenericMethodComments && !fastaSupportsGenericMethodComments) { | 150 if (scanGenericMethodComments) { |
153 // Fasta doesn't support generic method comments. | 151 // Fasta doesn't support generic method comments. |
154 // TODO(danrubel): remove this once fasts support has been added. | 152 // TODO(danrubel): remove this once fasts support has been added. |
155 throw 'No generic method comment support in Fasta'; | 153 throw 'No generic method comment support in Fasta'; |
156 } | 154 } |
157 fasta.ScannerResult result = | 155 fasta.ScannerResult result = |
158 fasta.scanString(_contents, includeComments: _preserveComments); | 156 fasta.scanString(_contents, includeComments: _preserveComments); |
159 // fasta pretends there is an additional line at EOF | 157 // fasta pretends there is an additional line at EOF |
160 lineStarts = result.lineStarts.sublist(0, result.lineStarts.length - 1); | 158 lineStarts = result.lineStarts.sublist(0, result.lineStarts.length - 1); |
161 fasta.Token token = result.tokens; | 159 fasta.Token token = result.tokens; |
162 // The default recovery strategy used by scanString | 160 // The default recovery strategy used by scanString |
163 // places all error tokens at the head of the stream. | 161 // places all error tokens at the head of the stream. |
164 while (token.info == fasta.BAD_INPUT_INFO) { | 162 while (token.info == fasta.BAD_INPUT_INFO) { |
165 translateErrorToken(token, reportError); | 163 translateErrorToken(token, reportError); |
166 token = token.next; | 164 token = token.next; |
167 } | 165 } |
168 firstToken = token; | 166 firstToken = token; |
169 return firstToken; | 167 return firstToken; |
170 } | 168 } |
171 | 169 |
172 @override | 170 @override |
173 set preserveComments(bool preserveComments) { | 171 set preserveComments(bool preserveComments) { |
174 this._preserveComments = preserveComments; | 172 this._preserveComments = preserveComments; |
175 } | 173 } |
176 } | 174 } |
OLD | NEW |