diff python/c3/astprinter.py @ 163:8104fc8b5e90

Added visitor to c3
author Windel Bouwman
date Mon, 18 Mar 2013 20:13:57 +0100
parents
children c1ccb1cb4cef
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/python/c3/astprinter.py	Mon Mar 18 20:13:57 2013 +0100
@@ -0,0 +1,16 @@
+from .astnodes import *
+from .scope import *
+from .visitor import Visitor
+
+class AstPrinter:
+   def __init__(self):
+      self.visitor = Visitor(self.print1, self.print2)
+   def printAst(self, pkg):
+      self.indent = 0
+      self.visitor.visit(pkg)
+   def print1(self, node):
+      print(' ' * self.indent + str(node))
+      self.indent += 2
+   def print2(self, node):
+      self.indent -= 2
+