| 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:path/path.dart' as pathos; | 9 import 'package:path/path.dart' as pathos; |
| 10 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 export 'src/generated/error.dart'; | 21 export 'src/generated/error.dart'; |
| 22 export 'src/generated/utilities_dart.dart'; | 22 export 'src/generated/utilities_dart.dart'; |
| 23 | 23 |
| 24 /// Parses a string of Dart code into an AST. | 24 /// Parses a string of Dart code into an AST. |
| 25 /// | 25 /// |
| 26 /// If [name] is passed, it's used in error messages as the name of the code | 26 /// If [name] is passed, it's used in error messages as the name of the code |
| 27 /// being parsed. | 27 /// being parsed. |
| 28 /// | 28 /// |
| 29 /// Throws an [AnalyzerErrorGroup] if any errors occurred, unless | 29 /// Throws an [AnalyzerErrorGroup] if any errors occurred, unless |
| 30 /// [suppressErrors] is `true`, in which case any errors are discarded. | 30 /// [suppressErrors] is `true`, in which case any errors are discarded. |
| 31 /// |
| 32 /// If [parseFunctionBodies] is [false] then only function signatures will be |
| 33 /// parsed. |
| 31 CompilationUnit parseCompilationUnit(String contents, {String name, | 34 CompilationUnit parseCompilationUnit(String contents, {String name, |
| 32 bool suppressErrors: false}) { | 35 bool suppressErrors: false, bool parseFunctionBodies: true}) { |
| 33 if (name == null) name = '<unknown source>'; | 36 if (name == null) name = '<unknown source>'; |
| 34 var source = new StringSource(contents, name); | 37 var source = new StringSource(contents, name); |
| 35 var errorCollector = new _ErrorCollector(); | 38 var errorCollector = new _ErrorCollector(); |
| 36 var reader = new CharSequenceReader(contents); | 39 var reader = new CharSequenceReader(contents); |
| 37 var scanner = new Scanner(source, reader, errorCollector); | 40 var scanner = new Scanner(source, reader, errorCollector); |
| 38 var token = scanner.tokenize(); | 41 var token = scanner.tokenize(); |
| 39 var parser = new Parser(source, errorCollector); | 42 var parser = new Parser(source, errorCollector); |
| 43 parser.parseFunctionBodies = parseFunctionBodies; |
| 40 var unit = parser.parseCompilationUnit(token); | 44 var unit = parser.parseCompilationUnit(token); |
| 41 unit.lineInfo = new LineInfo(scanner.lineStarts); | 45 unit.lineInfo = new LineInfo(scanner.lineStarts); |
| 42 | 46 |
| 43 if (errorCollector.hasErrors && !suppressErrors) throw errorCollector.group; | 47 if (errorCollector.hasErrors && !suppressErrors) throw errorCollector.group; |
| 44 | 48 |
| 45 return unit; | 49 return unit; |
| 46 } | 50 } |
| 47 | 51 |
| 48 /// Parses a Dart file into an AST. | 52 /// Parses a Dart file into an AST. |
| 49 CompilationUnit parseDartFile(String path) { | 53 CompilationUnit parseDartFile(String path) { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 | 116 |
| 113 /// The group of errors collected. | 117 /// The group of errors collected. |
| 114 AnalyzerErrorGroup get group => | 118 AnalyzerErrorGroup get group => |
| 115 new AnalyzerErrorGroup.fromAnalysisErrors(_errors); | 119 new AnalyzerErrorGroup.fromAnalysisErrors(_errors); |
| 116 | 120 |
| 117 /// Whether any errors where collected. | 121 /// Whether any errors where collected. |
| 118 bool get hasErrors => !_errors.isEmpty; | 122 bool get hasErrors => !_errors.isEmpty; |
| 119 | 123 |
| 120 void onError(AnalysisError error) => _errors.add(error); | 124 void onError(AnalysisError error) => _errors.add(error); |
| 121 } | 125 } |
| OLD | NEW |