diff options
author | David Robillard <d@drobilla.net> | 2009-03-30 19:46:51 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2009-03-30 19:46:51 +0000 |
commit | b0a77c63d82a1b6e46f37c29e07a29047315cd63 (patch) | |
tree | 7212eaf55c44a5bbcc612198bbd0644a40176c4c /write.cpp | |
parent | fdc794f5dc9de5b55fff71939ee4374ea38efa8f (diff) | |
download | resp-b0a77c63d82a1b6e46f37c29e07a29047315cd63.tar.gz resp-b0a77c63d82a1b6e46f37c29e07a29047315cd63.tar.bz2 resp-b0a77c63d82a1b6e46f37c29e07a29047315cd63.zip |
Add really primitive pretty printer.
git-svn-id: http://svn.drobilla.net/resp/tuplr@110 ad02d1e2-f140-0410-9f75-f8b11f17cedd
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; +} + |