Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(759)

Unified Diff: pkg/analyzer/lib/analyzer.dart

Issue 1087943002: pkg/analyzer: DRY'd up the parse methods. Aligned arguments between parse File and String (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/analyzer.dart
diff --git a/pkg/analyzer/lib/analyzer.dart b/pkg/analyzer/lib/analyzer.dart
index 6b613035d69c0df9d19ad544ea95e79079cde945..83a72a19331afa8612966911762b648230d11fe9 100644
--- a/pkg/analyzer/lib/analyzer.dart
+++ b/pkg/analyzer/lib/analyzer.dart
@@ -35,24 +35,20 @@ CompilationUnit parseCompilationUnit(String contents,
{String name, bool suppressErrors: false, bool parseFunctionBodies: true}) {
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);
- parser.parseFunctionBodies = parseFunctionBodies;
- var unit = parser.parseCompilationUnit(token);
- unit.lineInfo = new LineInfo(scanner.lineStarts);
-
- if (errorCollector.hasErrors && !suppressErrors) throw errorCollector.group;
-
- return unit;
+ return _parseSource(contents, source,
+ suppressErrors: suppressErrors, parseFunctionBodies: parseFunctionBodies);
}
/// Parses a Dart file into an AST.
-CompilationUnit parseDartFile(String path) {
+///
+/// Throws an [AnalyzerErrorGroup] if any errors occurred, unless
+/// [suppressErrors] is `true`, in which case any errors are discarded.
+///
+/// If [parseFunctionBodies] is [false] then only function signatures will be
+/// parsed.
+CompilationUnit parseDartFile(String path,
+ {bool suppressErrors: false, bool parseFunctionBodies: true}) {
String contents = new File(path).readAsStringSync();
- var errorCollector = new _ErrorCollector();
var sourceFactory = new SourceFactory([new FileUriResolver()]);
var absolutePath = pathos.absolute(path);
@@ -64,14 +60,22 @@ CompilationUnit parseDartFile(String path) {
throw new ArgumentError("Source $source doesn't exist");
}
+ return _parseSource(contents, source,
+ suppressErrors: suppressErrors, parseFunctionBodies: parseFunctionBodies);
+}
+
+CompilationUnit _parseSource(String contents, Source source,
+ {bool suppressErrors: false, bool parseFunctionBodies: true}) {
var reader = new CharSequenceReader(contents);
+ var errorCollector = new _ErrorCollector();
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);
+ var parser = new Parser(source, errorCollector)
+ ..parseFunctionBodies = parseFunctionBodies;
+ var unit = parser.parseCompilationUnit(token)
+ ..lineInfo = new LineInfo(scanner.lineStarts);
- if (errorCollector.hasErrors) throw errorCollector.group;
+ if (errorCollector.hasErrors && !suppressErrors) throw errorCollector.group;
return unit;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698