diff options
Diffstat (limited to 'src/pprint.cpp')
-rw-r--r-- | src/pprint.cpp | 38 |
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; } |