aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2010-12-29 05:47:36 +0000
committerDavid Robillard <d@drobilla.net>2010-12-29 05:47:36 +0000
commit0cbe31fcf90899f40c782f171f8bac8436b68d79 (patch)
treee7bad53816ab4b0114591e761173c73d54305b1a /src
parentc52b0560cc0005cfa9030c74ac23d5622ec8bfa3 (diff)
downloadresp-0cbe31fcf90899f40c782f171f8bac8436b68d79.tar.gz
resp-0cbe31fcf90899f40c782f171f8bac8436b68d79.tar.bz2
resp-0cbe31fcf90899f40c782f171f8bac8436b68d79.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/pprint.cpp38
1 files changed, 28 insertions, 10 deletions
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;
}