diff options
Diffstat (limited to 'write.cpp')
-rw-r--r-- | write.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -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; +} + |