OLD | NEW |
1 #!/usr/bin/env dart | 1 #!/usr/bin/env dart |
2 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 2 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
3 // for details. All rights reserved. Use of this source code is governed by a | 3 // for details. All rights reserved. Use of this source code is governed by a |
4 // BSD-style license that can be found in the LICENSE file. | 4 // BSD-style license that can be found in the LICENSE file. |
5 | 5 |
6 import 'dart:io'; | 6 import 'dart:io'; |
7 | 7 |
8 import 'package:analyzer/src/generated/ast.dart'; | 8 import 'package:analyzer/src/generated/ast.dart'; |
9 import 'package:analyzer/src/generated/error.dart'; | 9 import 'package:analyzer/src/generated/error.dart'; |
10 import 'package:analyzer/src/generated/parser.dart'; | 10 import 'package:analyzer/src/generated/parser.dart'; |
11 import 'package:analyzer/src/generated/scanner.dart'; | 11 import 'package:analyzer/src/generated/scanner.dart'; |
12 | 12 |
13 | |
14 main(List<String> args) { | 13 main(List<String> args) { |
15 | |
16 print('working dir ${new File('.').resolveSymbolicLinksSync()}'); | 14 print('working dir ${new File('.').resolveSymbolicLinksSync()}'); |
17 | 15 |
18 if (args.length == 0) { | 16 if (args.length == 0) { |
19 print('Usage: parser_driver [files_to_parse]'); | 17 print('Usage: parser_driver [files_to_parse]'); |
20 exit(0); | 18 exit(0); |
21 } | 19 } |
22 | 20 |
23 for (var arg in args) { | 21 for (var arg in args) { |
24 _parse(new File(arg)); | 22 _parse(new File(arg)); |
25 } | 23 } |
26 | |
27 } | 24 } |
28 | 25 |
29 _parse(File file) { | 26 _parse(File file) { |
30 var src = file.readAsStringSync(); | 27 var src = file.readAsStringSync(); |
31 var errorListener = new _ErrorCollector(); | 28 var errorListener = new _ErrorCollector(); |
32 var reader = new CharSequenceReader(src); | 29 var reader = new CharSequenceReader(src); |
33 var scanner = new Scanner(null, reader, errorListener); | 30 var scanner = new Scanner(null, reader, errorListener); |
34 var token = scanner.tokenize(); | 31 var token = scanner.tokenize(); |
35 var parser = new Parser(null, errorListener); | 32 var parser = new Parser(null, errorListener); |
36 var unit = parser.parseCompilationUnit(token); | 33 var unit = parser.parseCompilationUnit(token); |
(...skipping 11 matching lines...) Expand all Loading... |
48 print('${node.runtimeType} : <"$node">'); | 45 print('${node.runtimeType} : <"$node">'); |
49 return super.visitNode(node); | 46 return super.visitNode(node); |
50 } | 47 } |
51 } | 48 } |
52 | 49 |
53 class _ErrorCollector extends AnalysisErrorListener { | 50 class _ErrorCollector extends AnalysisErrorListener { |
54 List<AnalysisError> errors; | 51 List<AnalysisError> errors; |
55 _ErrorCollector() : errors = new List<AnalysisError>(); | 52 _ErrorCollector() : errors = new List<AnalysisError>(); |
56 onError(error) => errors.add(error); | 53 onError(error) => errors.add(error); |
57 } | 54 } |
OLD | NEW |