| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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; | 5 library analyzer; |
| 6 | 6 |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/src/dart/scanner/reader.dart'; | 10 import 'package:analyzer/src/dart/scanner/reader.dart'; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 /// Stops parsing when the first non-directive is encountered. The rest of the | 70 /// Stops parsing when the first non-directive is encountered. The rest of the |
| 71 /// string will not be parsed. | 71 /// string will not be parsed. |
| 72 /// | 72 /// |
| 73 /// If [name] is passed, it's used in error messages as the name of the code | 73 /// If [name] is passed, it's used in error messages as the name of the code |
| 74 /// being parsed. | 74 /// being parsed. |
| 75 /// | 75 /// |
| 76 /// Throws an [AnalyzerErrorGroup] if any errors occurred, unless | 76 /// Throws an [AnalyzerErrorGroup] if any errors occurred, unless |
| 77 /// [suppressErrors] is `true`, in which case any errors are discarded. | 77 /// [suppressErrors] is `true`, in which case any errors are discarded. |
| 78 CompilationUnit parseDirectives(String contents, | 78 CompilationUnit parseDirectives(String contents, |
| 79 {String name, bool suppressErrors: false}) { | 79 {String name, bool suppressErrors: false}) { |
| 80 if (name == null) name = '<unknown source>'; | |
| 81 var source = new StringSource(contents, name); | 80 var source = new StringSource(contents, name); |
| 82 var errorCollector = new _ErrorCollector(); | 81 var errorCollector = new _ErrorCollector(); |
| 83 var reader = new CharSequenceReader(contents); | 82 var reader = new CharSequenceReader(contents); |
| 84 var scanner = new Scanner(source, reader, errorCollector); | 83 var scanner = new Scanner(source, reader, errorCollector); |
| 85 var token = scanner.tokenize(); | 84 var token = scanner.tokenize(); |
| 86 var parser = new Parser(source, errorCollector); | 85 var parser = new Parser(source, errorCollector); |
| 87 var unit = parser.parseDirectives(token); | 86 var unit = parser.parseDirectives(token); |
| 88 unit.lineInfo = new LineInfo(scanner.lineStarts); | 87 unit.lineInfo = new LineInfo(scanner.lineStarts); |
| 89 | 88 |
| 90 if (errorCollector.hasErrors && !suppressErrors) throw errorCollector.group; | 89 if (errorCollector.hasErrors && !suppressErrors) throw errorCollector.group; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 /// The group of errors collected. | 121 /// The group of errors collected. |
| 123 AnalyzerErrorGroup get group => | 122 AnalyzerErrorGroup get group => |
| 124 new AnalyzerErrorGroup.fromAnalysisErrors(_errors); | 123 new AnalyzerErrorGroup.fromAnalysisErrors(_errors); |
| 125 | 124 |
| 126 /// Whether any errors where collected. | 125 /// Whether any errors where collected. |
| 127 bool get hasErrors => !_errors.isEmpty; | 126 bool get hasErrors => !_errors.isEmpty; |
| 128 | 127 |
| 129 @override | 128 @override |
| 130 void onError(AnalysisError error) => _errors.add(error); | 129 void onError(AnalysisError error) => _errors.add(error); |
| 131 } | 130 } |
| OLD | NEW |