From 0cbe31fcf90899f40c782f171f8bac8436b68d79 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 29 Dec 2010 05:47:36 +0000 Subject: Improve pretty-printing (fix broken indent when call head is a list). git-svn-id: http://svn.drobilla.net/resp/resp@371 ad02d1e2-f140-0410-9f75-f8b11f17cedd --- src/pprint.cpp | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/pprint.cpp b/src/pprint.cpp index 4e0d036..7b0ec3c 100644 --- a/src/pprint.cpp +++ b/src/pprint.cpp @@ -89,9 +89,11 @@ print_list(ostream& out, const ATuple* tup, ATuple::const_iterator i, if (next != tup->end()) { newline(out, indent); print_to(out, *next++, indent, cenv, types); - if (split_pairs) - newline(out, 0); - newline(out, indent); + if (next != tup->end()) { + if (split_pairs) + newline(out, 0); + newline(out, indent); + } } i = next; @@ -115,12 +117,15 @@ print_to(ostream& out, const AST* ast, unsigned indent, CEnv* cenv, bool types) if (i == tup->end()) return out << ")"; - std::string form = ""; - const ASymbol* sym = (*i)->to_symbol(); - if (sym) + std::string form = ""; + const ASymbol* sym = (*i)->to_symbol(); + unsigned head_width = 1; + if (sym) { form = sym->sym(); + head_width = form.length() + 2; + } - out << (*i++); + print_to(out, *i++, indent + 1, cenv, types); if (i != tup->end()) out << " "; @@ -132,7 +137,7 @@ print_to(ostream& out, const AST* ast, unsigned indent, CEnv* cenv, bool types) newline(out, child_indent); } out << " "; - print_to(out, (*i++), child_indent, cenv, types); + print_to(out, *i++, child_indent, cenv, types); out << ")"; newline(out, 0); @@ -146,7 +151,7 @@ print_to(ostream& out, const AST* ast, unsigned indent, CEnv* cenv, bool types) // Print prototype (possibly with parameter type annotations) const ATuple* pat = (*i++)->as_tuple(); out << "("; - print_list_one_line(out, pat, pat->begin(), indent, cenv, types, types); + print_list_one_line(out, pat, pat->begin(), indent + 2, cenv, types, types); // Print body expression(s) indented on the following lines newline(out, indent + 2); @@ -179,8 +184,21 @@ print_to(ostream& out, const AST* ast, unsigned indent, CEnv* cenv, bool types) newline(out, indent + 2); print_list(out, tup, i, indent + 2, cenv, types, true); + } else if (form == "do") { + newline(out, indent + 2); + print_list(out, tup, i, indent + 2, cenv, types, false); + } else { - print_list_one_line(out, tup, i, indent + 1, cenv, types, false); + // Print on multiple lines if list contains lists + for (ATuple::const_iterator ti = tup->begin(); ti != tup->end(); ++ti) { + if ((*ti)->to_tuple()) { + print_list(out, tup, i, indent + head_width, cenv, types, false); + return out; + } + } + + // Print on single line if list contains only atoms + print_list_one_line(out, tup, i, indent + head_width, cenv, types, false); } return out; } -- cgit v1.2.1