Chromium Code Reviews| 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 |
| 11 import 'src/error.dart'; | 11 import 'src/error.dart'; |
| 12 import 'src/generated/ast.dart'; | 12 import 'src/generated/ast.dart'; |
| 13 import 'src/generated/error.dart'; | 13 import 'src/generated/error.dart'; |
| 14 import 'src/generated/java_io.dart'; | 14 import 'src/generated/java_io.dart'; |
| 15 import 'src/generated/parser.dart'; | 15 import 'src/generated/parser.dart'; |
| 16 import 'src/generated/scanner.dart'; | 16 import 'src/generated/scanner.dart'; |
| 17 import 'src/generated/source_io.dart'; | 17 import 'src/generated/source_io.dart'; |
| 18 | 18 |
| 19 export 'src/error.dart'; | 19 export 'src/error.dart'; |
| 20 export 'src/generated/ast.dart'; | 20 export 'src/generated/ast.dart'; |
| 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 Dart file into an AST. | 24 /// Parses a Dart file into an AST. |
| 25 CompilationUnit parseDartFile(String path) { | 25 CompilationUnit parseDartFile(String path) { |
| 26 var contents = new File(path).readAsStringSync(); | 26 var contents = new File(path).readAsStringSync(); |
| 27 var errorCollector = new _ErrorCollector(); | 27 var errorCollector = new _ErrorCollector(); |
| 28 var sourceFactory = new SourceFactory.con2([new FileUriResolver()]); | 28 var sourceFactory = new SourceFactory.con2([new FileUriResolver()]); |
| 29 var source = sourceFactory.forUri(pathos.toUri(path).toString()); | 29 |
| 30 var absolutePath = pathos.absolute(path); | |
| 31 var source = sourceFactory.forUri(pathos.toUri(absolutePath).toString()); | |
| 32 if (source == null) { | |
|
Brian Wilkerson
2013/07/30 14:03:01
We might also want to check whether the source exi
| |
| 33 throw new ArgumentError("Can't get source for path $path"); | |
| 34 } | |
| 35 | |
| 30 var scanner = new StringScanner(source, contents, errorCollector); | 36 var scanner = new StringScanner(source, contents, errorCollector); |
| 31 var token = scanner.tokenize(); | 37 var token = scanner.tokenize(); |
| 32 var parser = new Parser(source, errorCollector); | 38 var parser = new Parser(source, errorCollector); |
| 33 var unit = parser.parseCompilationUnit(token); | 39 var unit = parser.parseCompilationUnit(token); |
| 34 unit.lineInfo = new LineInfo(scanner.lineStarts); | 40 unit.lineInfo = new LineInfo(scanner.lineStarts); |
| 35 | 41 |
| 36 if (errorCollector.hasErrors) throw errorCollector.group; | 42 if (errorCollector.hasErrors) throw errorCollector.group; |
| 37 | 43 |
| 38 return unit; | 44 return unit; |
| 39 } | 45 } |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 57 bool get hasErrors => !_errors.isEmpty; | 63 bool get hasErrors => !_errors.isEmpty; |
| 58 | 64 |
| 59 /// The group of errors collected. | 65 /// The group of errors collected. |
| 60 AnalyzerErrorGroup get group => | 66 AnalyzerErrorGroup get group => |
| 61 new AnalyzerErrorGroup.fromAnalysisErrors(_errors); | 67 new AnalyzerErrorGroup.fromAnalysisErrors(_errors); |
| 62 | 68 |
| 63 _ErrorCollector(); | 69 _ErrorCollector(); |
| 64 | 70 |
| 65 void onError(AnalysisError error) => _errors.add(error); | 71 void onError(AnalysisError error) => _errors.add(error); |
| 66 } | 72 } |
| OLD | NEW |