diff --git a/library/pretty_printer.m b/library/pretty_printer.m index 94cc6899f..78e727f52 100644 --- a/library/pretty_printer.m +++ b/library/pretty_printer.m @@ -1,7 +1,7 @@ %-----------------------------------------------------------------------------% % vim: ts=4 sw=4 expandtab tw=0 wm=0 ft=mercury %-----------------------------------------------------------------------------% -% Copyright (C) 2007 The University of Melbourne +% Copyright (C) 2007, 2009 The University of Melbourne % This file may only be copied under the terms of the GNU Library General % Public License - see the file COPYING.LIB in the Mercury distribution. %-----------------------------------------------------------------------------% @@ -712,7 +712,8 @@ expand_format_term(Name, Args, Doc, !Limit, CurrentPri) :- str("{"), indent([format_list(Args, str(", "))]), str("}") ]) else - Doc0 = docs([ + Doc0 = group([ + nl, str(term_io.quoted_atom(Name)), str("("), indent([format_list(Args, str(", "))]), str(")") ]) diff --git a/tests/hard_coded/test_pretty_printer.exp b/tests/hard_coded/test_pretty_printer.exp index ce5acf22b..dfaec8347 100644 --- a/tests/hard_coded/test_pretty_printer.exp +++ b/tests/hard_coded/test_pretty_printer.exp @@ -30,6 +30,11 @@ limit = triangular(1), max lines = 3, line width = 38 100.... |------------------------------------| +limit = triangular(1), max lines = 3, line width = 38 +|------------------------------------| +succ(...) +|------------------------------------| + limit = triangular(1), max lines = 3, line width = 38 |------------------------------------| -... @@ -86,6 +91,11 @@ limit = triangular(1), max lines = 3, line width = 78 100.... |----------------------------------------------------------------------------| +limit = triangular(1), max lines = 3, line width = 78 +|----------------------------------------------------------------------------| +succ(...) +|----------------------------------------------------------------------------| + limit = triangular(1), max lines = 3, line width = 78 |----------------------------------------------------------------------------| -... @@ -145,6 +155,11 @@ limit = triangular(1), max lines = 10, line width = 38 100.... |------------------------------------| +limit = triangular(1), max lines = 10, line width = 38 +|------------------------------------| +succ(...) +|------------------------------------| + limit = triangular(1), max lines = 10, line width = 38 |------------------------------------| -... @@ -204,6 +219,11 @@ limit = triangular(1), max lines = 10, line width = 78 100.... |----------------------------------------------------------------------------| +limit = triangular(1), max lines = 10, line width = 78 +|----------------------------------------------------------------------------| +succ(...) +|----------------------------------------------------------------------------| + limit = triangular(1), max lines = 10, line width = 78 |----------------------------------------------------------------------------| -... @@ -260,6 +280,11 @@ limit = linear(1), max lines = 3, line width = 38 100.... |------------------------------------| +limit = linear(1), max lines = 3, line width = 38 +|------------------------------------| +succ(...) +|------------------------------------| + limit = linear(1), max lines = 3, line width = 38 |------------------------------------| -... @@ -316,6 +341,11 @@ limit = linear(1), max lines = 3, line width = 78 100.... |----------------------------------------------------------------------------| +limit = linear(1), max lines = 3, line width = 78 +|----------------------------------------------------------------------------| +succ(...) +|----------------------------------------------------------------------------| + limit = linear(1), max lines = 3, line width = 78 |----------------------------------------------------------------------------| -... @@ -375,6 +405,11 @@ limit = linear(1), max lines = 10, line width = 38 100.... |------------------------------------| +limit = linear(1), max lines = 10, line width = 38 +|------------------------------------| +succ(...) +|------------------------------------| + limit = linear(1), max lines = 10, line width = 38 |------------------------------------| -... @@ -434,6 +469,11 @@ limit = linear(1), max lines = 10, line width = 78 100.... |----------------------------------------------------------------------------| +limit = linear(1), max lines = 10, line width = 78 +|----------------------------------------------------------------------------| +succ(...) +|----------------------------------------------------------------------------| + limit = linear(1), max lines = 10, line width = 78 |----------------------------------------------------------------------------| -... @@ -493,6 +533,14 @@ limit = triangular(10), max lines = 3, line width = 38 100.99.98.97.96........ |------------------------------------| +limit = triangular(10), max lines = 3, line width = 38 +|------------------------------------| +succ( + succ( + succ( + ... +|------------------------------------| + limit = triangular(10), max lines = 3, line width = 38 |------------------------------------| -(-(-(-((... + ...) * ... / @@ -560,6 +608,11 @@ limit = triangular(10), max lines = 3, line width = 78 100.99.98.97.96........ |----------------------------------------------------------------------------| +limit = triangular(10), max lines = 3, line width = 78 +|----------------------------------------------------------------------------| +succ(succ(succ(succ(succ(succ(succ(succ(succ(succ(...)))))))))) +|----------------------------------------------------------------------------| + limit = triangular(10), max lines = 3, line width = 78 |----------------------------------------------------------------------------| -(-(-(-((... + ...) * ... / (... * ...)) / (... / ... * ... + -...)) / @@ -629,6 +682,20 @@ limit = triangular(10), max lines = 10, line width = 38 100.99.98.97.96........ |------------------------------------| +limit = triangular(10), max lines = 10, line width = 38 +|------------------------------------| +succ( + succ( + succ( + succ( + succ( + succ( + succ( + succ( + succ( + succ(...)))))))))) +|------------------------------------| + limit = triangular(10), max lines = 10, line width = 38 |------------------------------------| -(-(-(-((... + ...) * ... / @@ -706,6 +773,11 @@ limit = triangular(10), max lines = 10, line width = 78 100.99.98.97.96........ |----------------------------------------------------------------------------| +limit = triangular(10), max lines = 10, line width = 78 +|----------------------------------------------------------------------------| +succ(succ(succ(succ(succ(succ(succ(succ(succ(succ(...)))))))))) +|----------------------------------------------------------------------------| + limit = triangular(10), max lines = 10, line width = 78 |----------------------------------------------------------------------------| -(-(-(-((... + ...) * ... / (... * ...)) / (... / ... * ... + -...)) / @@ -773,6 +845,14 @@ limit = triangular(100), max lines = 3, line width = 38 ... |------------------------------------| +limit = triangular(100), max lines = 3, line width = 38 +|------------------------------------| +succ( + succ( + succ( + ... +|------------------------------------| + limit = triangular(100), max lines = 3, line width = 38 |------------------------------------| -(-(-(-((x + x) * (x + x) / @@ -849,6 +929,11 @@ limit = triangular(100), max lines = 3, line width = 78 ....... |----------------------------------------------------------------------------| +limit = triangular(100), max lines = 3, line width = 78 +|----------------------------------------------------------------------------| +succ(succ(succ(succ(succ(succ(succ(succ(succ(succ(zero)))))))))) +|----------------------------------------------------------------------------| + limit = triangular(100), max lines = 3, line width = 78 |----------------------------------------------------------------------------| -(-(-(-((x + x) * (x + x) / (x / x * (x / x))) / @@ -936,6 +1021,20 @@ limit = triangular(100), max lines = 10, line width = 38 52.51........ |------------------------------------| +limit = triangular(100), max lines = 10, line width = 38 +|------------------------------------| +succ( + succ( + succ( + succ( + succ( + succ( + succ( + succ( + succ( + succ(zero)))))))))) +|------------------------------------| + limit = triangular(100), max lines = 10, line width = 38 |------------------------------------| -(-(-(-((x + x) * (x + x) / @@ -1049,6 +1148,11 @@ limit = triangular(100), max lines = 10, line width = 78 ....... |----------------------------------------------------------------------------| +limit = triangular(100), max lines = 10, line width = 78 +|----------------------------------------------------------------------------| +succ(succ(succ(succ(succ(succ(succ(succ(succ(succ(zero)))))))))) +|----------------------------------------------------------------------------| + limit = triangular(100), max lines = 10, line width = 78 |----------------------------------------------------------------------------| -(-(-(-((x + x) * (x + x) / (x / x * (x / x))) / @@ -1139,6 +1243,14 @@ limit = linear(10), max lines = 3, line width = 38 100.99.98.97.96........ |------------------------------------| +limit = linear(10), max lines = 3, line width = 38 +|------------------------------------| +succ( + succ( + succ( + ... +|------------------------------------| + limit = linear(10), max lines = 3, line width = 38 |------------------------------------| -(-(-(-((... + ...) * ... / ...) / @@ -1200,6 +1312,11 @@ limit = linear(10), max lines = 3, line width = 78 100.99.98.97.96........ |----------------------------------------------------------------------------| +limit = linear(10), max lines = 3, line width = 78 +|----------------------------------------------------------------------------| +succ(succ(succ(succ(succ(succ(succ(succ(succ(succ(...)))))))))) +|----------------------------------------------------------------------------| + limit = linear(10), max lines = 3, line width = 78 |----------------------------------------------------------------------------| -(-(-(-((... + ...) * ... / ...) / ...) / ...) / ...) @@ -1259,6 +1376,20 @@ limit = linear(10), max lines = 10, line width = 38 100.99.98.97.96........ |------------------------------------| +limit = linear(10), max lines = 10, line width = 38 +|------------------------------------| +succ( + succ( + succ( + succ( + succ( + succ( + succ( + succ( + succ( + succ(...)))))))))) +|------------------------------------| + limit = linear(10), max lines = 10, line width = 38 |------------------------------------| -(-(-(-((... + ...) * ... / ...) / @@ -1323,6 +1454,11 @@ limit = linear(10), max lines = 10, line width = 78 100.99.98.97.96........ |----------------------------------------------------------------------------| +limit = linear(10), max lines = 10, line width = 78 +|----------------------------------------------------------------------------| +succ(succ(succ(succ(succ(succ(succ(succ(succ(succ(...)))))))))) +|----------------------------------------------------------------------------| + limit = linear(10), max lines = 10, line width = 78 |----------------------------------------------------------------------------| -(-(-(-((... + ...) * ... / ...) / ...) / ...) / ...) @@ -1385,6 +1521,14 @@ limit = linear(100), max lines = 3, line width = 38 ... |------------------------------------| +limit = linear(100), max lines = 3, line width = 38 +|------------------------------------| +succ( + succ( + succ( + ... +|------------------------------------| + limit = linear(100), max lines = 3, line width = 38 |------------------------------------| -(-(-(-((x + x) * (x + x) / @@ -1461,6 +1605,11 @@ limit = linear(100), max lines = 3, line width = 78 ....... |----------------------------------------------------------------------------| +limit = linear(100), max lines = 3, line width = 78 +|----------------------------------------------------------------------------| +succ(succ(succ(succ(succ(succ(succ(succ(succ(succ(zero)))))))))) +|----------------------------------------------------------------------------| + limit = linear(100), max lines = 3, line width = 78 |----------------------------------------------------------------------------| -(-(-(-((x + x) * (x + x) / (x / x * (x / x))) / @@ -1548,6 +1697,20 @@ limit = linear(100), max lines = 10, line width = 38 52.51........ |------------------------------------| +limit = linear(100), max lines = 10, line width = 38 +|------------------------------------| +succ( + succ( + succ( + succ( + succ( + succ( + succ( + succ( + succ( + succ(zero)))))))))) +|------------------------------------| + limit = linear(100), max lines = 10, line width = 38 |------------------------------------| -(-(-(-((x + x) * (x + x) / @@ -1661,6 +1824,11 @@ limit = linear(100), max lines = 10, line width = 78 ....... |----------------------------------------------------------------------------| +limit = linear(100), max lines = 10, line width = 78 +|----------------------------------------------------------------------------| +succ(succ(succ(succ(succ(succ(succ(succ(succ(succ(zero)))))))))) +|----------------------------------------------------------------------------| + limit = linear(100), max lines = 10, line width = 78 |----------------------------------------------------------------------------| -(-(-(-((x + x) * (x + x) / (x / x * (x / x))) / diff --git a/tests/hard_coded/test_pretty_printer.m b/tests/hard_coded/test_pretty_printer.m index 885d7ea14..81132e507 100644 --- a/tests/hard_coded/test_pretty_printer.m +++ b/tests/hard_coded/test_pretty_printer.m @@ -52,6 +52,10 @@ ; op_tree * op_tree ; op_tree / op_tree. +:- type church + ---> zero + ; succ(church). + :- type non_canonical_bool ---> non_canonical_bool(int) where equality is non_canonical_bool_eq. @@ -209,6 +213,7 @@ test_case(test_case(LineWidth, MaxLines, Limit, Doc)) :- func(X, M) = M ^ elem(X) := float(X), List, map.init : map(int, float)), OpTree = mk_op_tree(200), + Church = list.foldl(func(_, X) = succ(X), 1..10, zero), Tuple = {1, 2.0, "three", '4', {5}}, Square = list.duplicate(10, 1..10) : list(list(int)), IndentTest = docs([ @@ -243,6 +248,7 @@ test_case(test_case(LineWidth, MaxLines, Limit, Doc)) :- ; Doc = format(MapFloat) ; Doc = format(MapStr) ; Doc = format(OpTree) + ; Doc = format(Church) ; Doc = fmt_susp_seq(100) ; Doc = format(Tuple) ; Doc = format(Square)