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

Unified Diff: packages/analyzer/example/parser_driver.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 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 | « packages/analyzer/README.md ('k') | packages/analyzer/example/resolver_driver.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packages/analyzer/example/parser_driver.dart
diff --git a/packages/analyzer/example/parser_driver.dart b/packages/analyzer/example/parser_driver.dart
new file mode 100644
index 0000000000000000000000000000000000000000..8fdf1a99af06f3b4a9a5b8427d8ca8199e5021bd
--- /dev/null
+++ b/packages/analyzer/example/parser_driver.dart
@@ -0,0 +1,54 @@
+#!/usr/bin/env dart
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'dart:io';
+
+import 'package:analyzer/src/generated/ast.dart';
+import 'package:analyzer/src/generated/error.dart';
+import 'package:analyzer/src/generated/parser.dart';
+import 'package:analyzer/src/generated/scanner.dart';
+
+main(List<String> args) {
+ print('working dir ${new File('.').resolveSymbolicLinksSync()}');
+
+ if (args.length == 0) {
+ print('Usage: parser_driver [files_to_parse]');
+ exit(0);
+ }
+
+ for (var arg in args) {
+ _parse(new File(arg));
+ }
+}
+
+_parse(File file) {
+ var src = file.readAsStringSync();
+ var errorListener = new _ErrorCollector();
+ var reader = new CharSequenceReader(src);
+ var scanner = new Scanner(null, reader, errorListener);
+ var token = scanner.tokenize();
+ var parser = new Parser(null, errorListener);
+ var unit = parser.parseCompilationUnit(token);
+
+ var visitor = new _ASTVisitor();
+ unit.accept(visitor);
+
+ for (var error in errorListener.errors) {
+ print(error);
+ }
+}
+
+class _ASTVisitor extends GeneralizingAstVisitor {
+ visitNode(AstNode node) {
+ print('${node.runtimeType} : <"$node">');
+ return super.visitNode(node);
+ }
+}
+
+class _ErrorCollector extends AnalysisErrorListener {
+ List<AnalysisError> errors;
+ _ErrorCollector() : errors = new List<AnalysisError>();
+ onError(error) => errors.add(error);
+}
« no previous file with comments | « packages/analyzer/README.md ('k') | packages/analyzer/example/resolver_driver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698