aboutsummaryrefslogtreecommitdiffstats
path: root/write.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'write.cpp')
-rw-r--r--write.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/write.cpp b/write.cpp
index aab3fb1..984e236 100644
--- a/write.cpp
+++ b/write.cpp
@@ -56,3 +56,30 @@ operator<<(ostream& out, const AST* ast)
return out << "?";
}
+void
+pprint_internal(ostream& out, const AST* ast, unsigned indent)
+{
+ out << string().insert(0, indent, ' ');
+ const ATuple* tup = ast->to<const ATuple*>();
+ if (tup) {
+ const string head = tup->at(0)->str();
+ out << "(" << head;
+ if (tup->size() > 1)
+ out << " " << tup->at(1);
+ for (size_t i = 2; i != tup->size(); ++i) {
+ out << endl;
+ pprint_internal(out, tup->at(i), indent + head.length() + 2);
+ }
+ out << ")";
+ } else {
+ out << ast;
+ }
+}
+
+void
+pprint(ostream& out, const AST* ast)
+{
+ pprint_internal(out, ast, 0);
+ out << endl;
+}
+