[m-rev.] For post commit review: minor pretty-printer fixes

Ralph Becket rafe at csse.unimelb.edu.au
Wed Aug 15 16:04:03 AEST 2007


Estimated hours taken: 4 (mostly testing)
Branches: main

library/array.m:
	Simplify the handling of separators in array_to_doc.

library/list.m:
	Simplify the handling of separators in list_to_doc.
	Change the indentation for list docs from two spaces
	to one: if, as is often the case, the opening bracket
	starts a new line, then this slightly improves the look
	of the output.

library/pretty_printer.m:
	Use a new constant `ellipsis' rather than `str("...")'
	throughout.

tests/debugger/browse_pretty.inp:
	Use a larger depth to see the whole term (the new pretty
	printer counts terms in a slightly different - more
	accurate - way to the old one).

tests/hard_coded/test_pretty_printer_defaults.exp:
	Update the expected output.

Index: library/array.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/array.m,v
retrieving revision 1.157
diff -u -r1.157 array.m
--- library/array.m	14 Aug 2007 04:21:06 -0000	1.157
+++ library/array.m	15 Aug 2007 05:02:42 -0000
@@ -1675,8 +1675,8 @@
         str("")
       else
         docs([
-            group([nl, format_arg(format(A ^ elem(I)))]),
-            str((if I = array.max(A) then "" else ", ")),
+            format_arg(format(A ^ elem(I))),
+            ( if I = array.max(A) then str("") else group([str(", "), nl]) ),
             format_susp((func) = array_to_doc_2(I + 1, A))
         ])
     ).
Index: library/list.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/list.m,v
retrieving revision 1.166
diff -u -r1.166 list.m
--- library/list.m	14 Aug 2007 04:21:07 -0000	1.166
+++ library/list.m	15 Aug 2007 05:01:55 -0000
@@ -2579,7 +2579,7 @@
 
 %-----------------------------------------------------------------------------%
 
-list_to_doc(Xs) = indent([str("["), list_to_doc_2(Xs), str("]")]).
+list_to_doc(Xs) = indent(" ", [str("["), list_to_doc_2(Xs), str("]")]).
 
 
 :- func list_to_doc_2(list(T)) = doc.
@@ -2588,8 +2588,8 @@
 
 list_to_doc_2([X | Xs]) =
     docs([
-        group([nl, format_arg(format(X))]),
-        str((if Xs = [] then "" else ", ")),
+        format_arg(format(X)),
+        ( if Xs = [] then str("") else group([str(", "), nl]) ),
         format_susp((func) = list_to_doc_2(Xs))
     ]).
 
Index: library/pretty_printer.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/pretty_printer.m,v
retrieving revision 1.2
diff -u -r1.2 pretty_printer.m
--- library/pretty_printer.m	14 Aug 2007 04:21:07 -0000	1.2
+++ library/pretty_printer.m	15 Aug 2007 03:34:43 -0000
@@ -633,7 +633,7 @@
     ( if
         limit_overrun(!.Limit)
       then
-        Doc = str("...")
+        Doc = ellipsis
       else if
         Value = univ_value(Univ),
         type_ctor_and_args(type_of(Value), TypeCtorDesc, ArgTypeDescs),
@@ -661,7 +661,7 @@
 
 expand_format_list([Univ | Univs], Sep, Doc, !Limit) :-
     ( if limit_overrun(!.Limit) then
-        Doc = str("...")
+        Doc = ellipsis
       else
         (
             Univs = [],
@@ -688,7 +688,7 @@
     ( if Args = [] then
         Doc0 = str(term_io.quoted_atom(Name))
       else if limit_overrun(!.Limit) then
-        Doc0 = str("...")
+        Doc0 = ellipsis
       else if expand_format_op(Name, Args, CurrentPri, OpDoc) then
         Doc0 = OpDoc
       else if Name = "{}" then
@@ -710,7 +710,7 @@
 
 expand_format_susp(Susp, Doc, !Limit) :-
     ( if limit_overrun(!.Limit) then
-        Doc = str("...")
+        Doc = ellipsis
       else
         decrement_limit(!Limit),
         Doc = set_formatting_limit_correctly(!.Limit, apply(Susp))
@@ -979,4 +979,10 @@
     ).
 
 %-----------------------------------------------------------------------------%
+
+:- func ellipsis = doc.
+
+ellipsis = str("...").
+
+%-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
Index: tests/debugger/browse_pretty.inp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/browse_pretty.inp,v
retrieving revision 1.6
diff -u -r1.6 browse_pretty.inp
--- tests/debugger/browse_pretty.inp	4 Apr 2006 07:37:17 -0000	1.6
+++ tests/debugger/browse_pretty.inp	15 Aug 2007 05:00:52 -0000
@@ -3,7 +3,7 @@
 print *
 browse 1
 format pretty
-depth 10
+depth 20
 ls
 width 131
 ls
Index: tests/hard_coded/test_pretty_printer_defaults.exp
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/test_pretty_printer_defaults.exp,v
retrieving revision 1.1
diff -u -r1.1 test_pretty_printer_defaults.exp
--- tests/hard_coded/test_pretty_printer_defaults.exp	14 Aug 2007 04:21:09 -0000	1.1
+++ tests/hard_coded/test_pretty_printer_defaults.exp	15 Aug 2007 05:55:11 -0000
@@ -1,7 +1,7 @@
 two("builtin", two("float", two(0, '<<function>>', empty, empty), two("character", two(0, '<<function>>', empty, empty), empty, empty), three("int", two(0, '<<function>>', empty, empty), "string", two(0, '<<function>>', empty, empty), empty, empty, empty)), two("array", two("array", two(1, '<<function>>', empty, empty), empty, empty), empty, empty), three("list", two("list", two(1, '<<function>>', empty, empty), empty, empty), "tree234", two("tree234", two(2, '<<function>>', empty, empty), empty, empty), empty, empty, empty))
 list:    [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 
-  20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 
-  39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, ...]
+ 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 
+ 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, ...]
 array:   array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 
   18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 
   37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, ..., ...])
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list