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

Unified Diff: pkg/analyzer-experimental/example/parser_driver.dart

Issue 12183033: Simple parser driver example. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 10 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-experimental/example/parser_driver.dart
===================================================================
--- pkg/analyzer-experimental/example/parser_driver.dart (revision 0)
+++ pkg/analyzer-experimental/example/parser_driver.dart (revision 0)
@@ -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 'package:analyzer-experimental/src/generated/ast.dart';
+import 'package:analyzer-experimental/src/generated/error.dart';
+import 'package:analyzer-experimental/src/generated/java_core.dart';
+import 'package:analyzer-experimental/src/generated/parser.dart';
+import 'package:analyzer-experimental/src/generated/scanner.dart';
+
+import 'dart:io';
+
+
+main() {
+
+ print('working dir ${new File('.').fullPathSync()}');
+
+ var args = new Options().arguments;
+ 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 scanner = new StringScanner(null, src, null);
scheglov 2013/02/05 00:16:40 You should pass listener to the scanner.
pquitslund 2013/02/05 00:24:14 Done.
+ var token = scanner.tokenize();
+ var listener = new _ErrorCollector();
+ var parser = new Parser(null, listener);
+ var unit = parser.parseCompilationUnit(token);
+ var visitor = new _ASTVisitor();
+ unit.accept(visitor);
+}
+
+class _ErrorCollector extends AnalysisErrorListener {
+ List<AnalysisError> errors;
+ onError(error) => errors.add(error);
scheglov 2013/02/05 00:16:40 Why do you add errors if you don't use them?
pquitslund 2013/02/05 00:24:14 Good point. Updated to print them out.
+}
+
+class _ASTVisitor extends GeneralizingASTVisitor {
+ visitNode(ASTNode node) {
+ print('${node.runtimeType} : <"${node.toString()}">');
+ return super.visitNode(node);
+ }
+}
+
« 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