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:pathos/path.dart' as pathos; |
| 10 |
9 import 'src/error.dart'; | 11 import 'src/error.dart'; |
10 import 'src/generated/ast.dart'; | 12 import 'src/generated/ast.dart'; |
11 import 'src/generated/error.dart'; | 13 import 'src/generated/error.dart'; |
12 import 'src/generated/java_io.dart'; | 14 import 'src/generated/java_io.dart'; |
13 import 'src/generated/parser.dart'; | 15 import 'src/generated/parser.dart'; |
14 import 'src/generated/scanner.dart'; | 16 import 'src/generated/scanner.dart'; |
15 import 'src/generated/source_io.dart'; | 17 import 'src/generated/source_io.dart'; |
16 import 'src/utils.dart'; | |
17 | 18 |
18 export 'src/error.dart'; | 19 export 'src/error.dart'; |
19 export 'src/generated/ast.dart'; | 20 export 'src/generated/ast.dart'; |
20 export 'src/generated/error.dart'; | 21 export 'src/generated/error.dart'; |
21 export 'src/generated/utilities_dart.dart'; | 22 export 'src/generated/utilities_dart.dart'; |
22 | 23 |
23 /// Parses a Dart file into an AST. | 24 /// Parses a Dart file into an AST. |
24 CompilationUnit parseDartFile(String path) { | 25 CompilationUnit parseDartFile(String path) { |
25 var contents = new File(path).readAsStringSync(); | 26 var contents = new File(path).readAsStringSync(); |
26 var errorCollector = new _ErrorCollector(); | 27 var errorCollector = new _ErrorCollector(); |
27 var sourceFactory = new SourceFactory.con2([new FileUriResolver()]); | 28 var sourceFactory = new SourceFactory.con2([new FileUriResolver()]); |
28 var source = sourceFactory.forUri(pathToFileUri(path).toString()); | 29 var source = sourceFactory.forUri(pathos.toUri(path).toString()); |
29 var scanner = new StringScanner(source, contents, errorCollector); | 30 var scanner = new StringScanner(source, contents, errorCollector); |
30 var token = scanner.tokenize(); | 31 var token = scanner.tokenize(); |
31 var parser = new Parser(source, errorCollector); | 32 var parser = new Parser(source, errorCollector); |
32 var unit = parser.parseCompilationUnit(token); | 33 var unit = parser.parseCompilationUnit(token); |
33 unit.lineInfo = new LineInfo(scanner.lineStarts); | 34 unit.lineInfo = new LineInfo(scanner.lineStarts); |
34 | 35 |
35 if (errorCollector.hasErrors) throw errorCollector.group; | 36 if (errorCollector.hasErrors) throw errorCollector.group; |
36 | 37 |
37 return unit; | 38 return unit; |
38 } | 39 } |
(...skipping 17 matching lines...) Expand all Loading... |
56 bool get hasErrors => !_errors.isEmpty; | 57 bool get hasErrors => !_errors.isEmpty; |
57 | 58 |
58 /// The group of errors collected. | 59 /// The group of errors collected. |
59 AnalyzerErrorGroup get group => | 60 AnalyzerErrorGroup get group => |
60 new AnalyzerErrorGroup.fromAnalysisErrors(_errors); | 61 new AnalyzerErrorGroup.fromAnalysisErrors(_errors); |
61 | 62 |
62 _ErrorCollector(); | 63 _ErrorCollector(); |
63 | 64 |
64 void onError(AnalysisError error) => _errors.add(error); | 65 void onError(AnalysisError error) => _errors.add(error); |
65 } | 66 } |
OLD | NEW |