@@ -50,6 +50,10 @@ class Scrape {
5050 int get scrapedLineCount => _scrapedLineCount;
5151 int _scrapedLineCount = 0 ;
5252
53+ /// The number of files that could not be parsed.
54+ int get errorFileCount => _errorFileCount;
55+ int _errorFileCount = 0 ;
56+
5357 final Map <String , Histogram > _histograms = {};
5458
5559 /// Whether we're in the middle of writing the running file count and need a
@@ -151,10 +155,22 @@ class Scrape {
151155 histogram.printCounts (name);
152156 });
153157
158+ String count (int n, String unit) {
159+ if (n == 1 ) return '1 $unit ' ;
160+ return '$n ${unit }s' ;
161+ }
162+
154163 var elapsed = _formatDuration (watch.elapsed);
155- var lines = _scrapedLineCount != 1 ? '$_scrapedLineCount lines' : '1 line' ;
156- var files = _scrapedFileCount != 1 ? '$_scrapedFileCount files' : '1 file' ;
157- print ('Took $elapsed to scrape $lines in $files .' );
164+ var lines = count (_scrapedLineCount, 'line' );
165+ var files = count (_scrapedFileCount, 'file' );
166+ var message = 'Took $elapsed to scrape $lines in $files .' ;
167+
168+ if (_errorFileCount > 0 ) {
169+ var errors = count (_errorFileCount, 'file' );
170+ message += ' ($errors could not be parsed.)' ;
171+ }
172+
173+ print (message);
158174 }
159175
160176 /// Display [message] , clearing the line if necessary.
@@ -242,16 +258,18 @@ class Scrape {
242258 var source = file.readAsStringSync ();
243259
244260 var errorListener = ErrorListener (this , _printErrors);
261+ var featureSet = FeatureSet .latestLanguageVersion ();
245262
246263 // Tokenize the source.
247264 var reader = CharSequenceReader (source);
248265 var stringSource = StringSource (source, file.path);
249266 var scanner = Scanner (stringSource, reader, errorListener);
267+ scanner.configureFeatures (
268+ featureSet: featureSet, featureSetForOverriding: featureSet);
250269 var startToken = scanner.tokenize ();
251270
252271 // Parse it.
253- var parser = Parser (stringSource, errorListener,
254- featureSet: FeatureSet .latestLanguageVersion ());
272+ var parser = Parser (stringSource, errorListener, featureSet: featureSet);
255273 parser.enableOptionalNewAndConst = true ;
256274 parser.enableSetLiterals = true ;
257275
@@ -277,6 +295,12 @@ class Scrape {
277295 return ;
278296 }
279297
298+ // Don't process files with syntax errors.
299+ if (errorListener.hadError) {
300+ _errorFileCount++ ;
301+ return ;
302+ }
303+
280304 var lineInfo = LineInfo (scanner.lineStarts);
281305
282306 _scrapedFileCount++ ;
0 commit comments