From b0a77c63d82a1b6e46f37c29e07a29047315cd63 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 30 Mar 2009 19:46:51 +0000 Subject: Add really primitive pretty printer. git-svn-id: http://svn.drobilla.net/resp/tuplr@110 ad02d1e2-f140-0410-9f75-f8b11f17cedd --- write.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'write.cpp') 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(); + 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; +} + -- cgit v1.2.1