Преглед изворни кода

Added nice pretty print for tree

Yentl Van Tendeloo пре 7 година
родитељ
комит
1d0c10b06c
1 измењених фајлова са 3 додато и 0 уклоњено
  1. 3 0
      interface/HUTN/hutn_compiler/hutnparser.py

+ 3 - 0
interface/HUTN/hutn_compiler/hutnparser.py

@@ -122,6 +122,9 @@ class Tree(object):
             if isinstance(f, Tree):
                 f.fix_tracability(self.inputfile)
 
+    def pretty_print(self, i=0):
+        return "\t" * i + str(self.head) + "\n" + "\n".join([("\t" * (i+1) + st) if isinstance(st, str) else st.pretty_print(i+1) for st in self.get_tail()])
+
 class Parser(object):
     class Constants(object):
         Token = 'token'