[m-rev.] Fixes for test output
Ralph Becket
rafe at csse.unimelb.edu.au
Wed Aug 22 11:59:44 AEST 2007
Here's an interdiff that I believe addresses your complaints:
diff -u library/pretty_printer.m library/pretty_printer.m
--- library/pretty_printer.m 21 Aug 2007 01:20:10 -0000
+++ library/pretty_printer.m 21 Aug 2007 07:04:29 -0000
@@ -686,7 +686,7 @@
expand_format_term(Name, Args, Doc, !Limit, CurrentPri) :-
decrement_limit(!Limit),
( if Args = [] then
- Doc0 = str(quote_name_if_needed(Name))
+ Doc0 = str(term_io.quoted_atom(Name))
else if limit_overrun(!.Limit) then
Doc0 = ellipsis
else if expand_format_op(Name, Args, CurrentPri, OpDoc) then
@@ -697,7 +697,7 @@
])
else
Doc0 = docs([
- str(quote_name_if_needed(Name)),
+ str(term_io.quoted_atom(Name)),
str("("), indent([format_list(Args, str(", "))]), str(")")
])
),
@@ -705,19 +705,6 @@
%-----------------------------------------------------------------------------%
- % Add quotes and escape characters to a functor name if needed.
- % We casually assume that full stop characters ('.') are module
- % qualifiers and don't warrant quoting.
- %
-:- func quote_name_if_needed(string) = string.
-
-quote_name_if_needed(Name0) = Name :-
- Parts0 = string.split_at_char(('.'), Name0),
- Parts = list.map(term_io.quoted_atom, Parts0),
- Name = string.join_list(".", Parts).
-
-%-----------------------------------------------------------------------------%
-
:- pred expand_format_susp(((func) = doc)::in, doc::out,
formatting_limit::in, formatting_limit::out) is det.
@@ -766,7 +753,11 @@
group([
pp_internal(set_op_priority(adjust_priority(OpPri, AssocA))),
format_univ(ArgA),
- str(" "), str(Op), str(" "),
+ ( if Op = "." then
+ str(Op)
+ else
+ docs([str(" "), str(Op), str(" ")])
+ ),
indent([
nl,
pp_internal(set_op_priority(adjust_priority(OpPri,
only in patch2:
unchanged:
--- browser/browse.m 14 Aug 2007 05:25:24 -0000 1.70
+++ browser/browse.m 22 Aug 2007 01:55:44 -0000
@@ -184,6 +184,7 @@
:- import_module stream.
:- import_module stream.string_writer.
:- import_module string.
+:- import_module term_io.
:- import_module term_to_xml.
:- import_module type_desc.
@@ -1690,8 +1691,48 @@
%
:- func synthetic_term_to_doc(string, list(univ), maybe(univ)) = doc.
-synthetic_term_to_doc(Functor, Args, no) = format_term(Functor, Args).
-synthetic_term_to_doc(Functor, Args, yes(Return)) =
- docs([format_term(Functor, Args), str(" = "), format_univ(Return)]).
+synthetic_term_to_doc(Functor0, Args, MaybeReturn) = Doc :-
+ ( if
+ ( Functor0 = "!."
+ ; Functor0 = "."
+ ; Functor0 = ".."
+ ; Functor0 = "=.."
+ ; not string.contains_char(Functor0, ('.'))
+ )
+ then
+ Doc0 = format_term(Functor0, Args)
+ else
+ FunctorDoc = parts_to_doc(string.split_at_char(('.'), Functor0)),
+ (
+ Args = [],
+ Doc0 = FunctorDoc
+ ;
+ Args = [_ | _],
+ Doc0 = indent([
+ FunctorDoc, str("("),
+ format_list(Args, group([str(", "), nl])),
+ str(")")
+ ])
+ )
+ ),
+ (
+ MaybeReturn = no,
+ Doc = Doc0
+ ;
+ MaybeReturn = yes(Return),
+ Doc = docs([Doc0, str(" = "), format_arg(format_univ(Return))])
+ ).
+
+%-----------------------------------------------------------------------------%
+
+:- func parts_to_doc(list(string)) = doc.
+
+parts_to_doc([]) = str("").
+
+parts_to_doc([Part]) = str(term_io.quoted_atom(Part)).
+
+parts_to_doc([PartA, PartB | Parts]) =
+ docs([str(term_io.quoted_atom(PartA)), str("."),
+ parts_to_doc([PartB | Parts])]).
%---------------------------------------------------------------------------%
--------------------------------------------------------------------------
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