| Index: pkg/analyzer/lib/analyzer.dart
|
| diff --git a/pkg/analyzer/lib/analyzer.dart b/pkg/analyzer/lib/analyzer.dart
|
| index dc0b647a361304f9dc88e7f1b026e90b50471e05..2f52d8a34e9140e076b22f1f9f9f3e5dff8501d7 100644
|
| --- a/pkg/analyzer/lib/analyzer.dart
|
| +++ b/pkg/analyzer/lib/analyzer.dart
|
| @@ -21,6 +21,30 @@ export 'src/generated/ast.dart';
|
| export 'src/generated/error.dart';
|
| export 'src/generated/utilities_dart.dart';
|
|
|
| +/// Parses a string of Dart code into an AST.
|
| +///
|
| +/// If [name] is passed, it's used in error messages as the name of the code
|
| +/// being parsed.
|
| +///
|
| +/// Throws an [AnalyzerErrorGroup] if any errors occurred, unless
|
| +/// [suppressErrors] is `true`, in which case any errors are discarded.
|
| +CompilationUnit parseCompilationUnit(String contents, {String name,
|
| + bool suppressErrors: false}) {
|
| + if (name == null) name = '<unknown source>';
|
| + var source = new StringSource(contents, name);
|
| + var errorCollector = new _ErrorCollector();
|
| + var reader = new CharSequenceReader(contents);
|
| + var scanner = new Scanner(source, reader, errorCollector);
|
| + var token = scanner.tokenize();
|
| + var parser = new Parser(source, errorCollector);
|
| + var unit = parser.parseCompilationUnit(token);
|
| + unit.lineInfo = new LineInfo(scanner.lineStarts);
|
| +
|
| + if (errorCollector.hasErrors && !suppressErrors) throw errorCollector.group;
|
| +
|
| + return unit;
|
| +}
|
| +
|
| /// Parses a Dart file into an AST.
|
| CompilationUnit parseDartFile(String path) {
|
| String contents = new File(path).readAsStringSync();
|
| @@ -48,30 +72,6 @@ CompilationUnit parseDartFile(String path) {
|
| return unit;
|
| }
|
|
|
| -/// Parses a string of Dart code into an AST.
|
| -///
|
| -/// If [name] is passed, it's used in error messages as the name of the code
|
| -/// being parsed.
|
| -///
|
| -/// Throws an [AnalyzerErrorGroup] if any errors occurred, unless
|
| -/// [suppressErrors] is `true`, in which case any errors are discarded.
|
| -CompilationUnit parseCompilationUnit(String contents,
|
| - {String name, bool suppressErrors: false}) {
|
| - if (name == null) name = '<unknown source>';
|
| - var source = new StringSource(contents, name);
|
| - var errorCollector = new _ErrorCollector();
|
| - var reader = new CharSequenceReader(contents);
|
| - var scanner = new Scanner(source, reader, errorCollector);
|
| - var token = scanner.tokenize();
|
| - var parser = new Parser(source, errorCollector);
|
| - var unit = parser.parseCompilationUnit(token);
|
| - unit.lineInfo = new LineInfo(scanner.lineStarts);
|
| -
|
| - if (errorCollector.hasErrors && !suppressErrors) throw errorCollector.group;
|
| -
|
| - return unit;
|
| -}
|
| -
|
| /// Parses the script tag and directives in a string of Dart code into an AST.
|
| ///
|
| /// Stops parsing when the first non-directive is encountered. The rest of the
|
| @@ -82,8 +82,8 @@ CompilationUnit parseCompilationUnit(String contents,
|
| ///
|
| /// Throws an [AnalyzerErrorGroup] if any errors occurred, unless
|
| /// [suppressErrors] is `true`, in which case any errors are discarded.
|
| -CompilationUnit parseDirectives(String contents,
|
| - {String name, bool suppressErrors: false}) {
|
| +CompilationUnit parseDirectives(String contents, {String name,
|
| + bool suppressErrors: false}) {
|
| if (name == null) name = '<unknown source>';
|
| var source = new StringSource(contents, name);
|
| var errorCollector = new _ErrorCollector();
|
| @@ -108,14 +108,14 @@ String stringLiteralToString(StringLiteral literal) {
|
| class _ErrorCollector extends AnalysisErrorListener {
|
| final _errors = <AnalysisError>[];
|
|
|
| - /// Whether any errors where collected.
|
| - bool get hasErrors => !_errors.isEmpty;
|
| + _ErrorCollector();
|
|
|
| /// The group of errors collected.
|
| AnalyzerErrorGroup get group =>
|
| - new AnalyzerErrorGroup.fromAnalysisErrors(_errors);
|
| + new AnalyzerErrorGroup.fromAnalysisErrors(_errors);
|
|
|
| - _ErrorCollector();
|
| + /// Whether any errors where collected.
|
| + bool get hasErrors => !_errors.isEmpty;
|
|
|
| void onError(AnalysisError error) => _errors.add(error);
|
| }
|
|
|