mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-16 18:03:36 +00:00
library/array.m:
library/char.m:
library/float.m:
library/int.m:
library/int16.m:
library/int32.m:
library/int64.m:
library/int8.m:
library/list.m:
library/one_or_more.m:
library/string.m:
library/tree234.m:
library/uint.m:
library/uint16.m:
library/uint32.m:
library/uint64.m:
library/uint8.m:
library/version_array.m:
Mark the X_to_doc function in each of these modules as obsolete,
and make it a forwarding function to the actual implementation
in pretty_printer.m. The intention is that when these forwarding
functions are eventually removed, this will also remove the dependency
of these modules on pretty_printer.m. This should help at least some
of these modules escape the giant SCC in the library's dependency graph.
(It does not make sense that a library module that adds code to increment
an int thereby becomes dependent on pretty_printer.m through int.m.)
library/pretty_printer.m:
Move all the X_to_doc functions from the above modules here.
Fix the one_or_more_to_doc function, which was
- missing the comma between the two arguments of the one_or_more
function symbol, and
- would print "..., ...]" instead of just "...]" at the end of the
tail list when that list exceeded the limits of the specified pp_params.
Rename one of the moved types along with its function symbols,
to reduce ambiguity.
Put arrays before their indexes in the argument lists of some of
the moved functions.
Some of the moved X_to_doc functions for compound types returned
a doc that had an indent wrapper. These indents differed between the
various X_to_doc functions without any visible reason, but they are
also redundant. The callers can trivially add such wrappers if they
want to, but taking them off, if they want them off, is harder.
Eliminate the problem by deleting all such indent wrappers.
Add formatters for the intN, uintN and one_or_more types to the
default formatter map. Their previous absence was an oversight.
Add a function, get_formatter_map_entry_types, that returns the ids
of the types in the formatter_map given to the function. It is intended
for tests/hard_coded/test_pretty_printer_defaults.m, but is exported
for anyone to use.
tests/hard_coded/test_pretty_printer_defaults.{m,exp}:
Use get_formatter_map_entry_types to print the default formatter map
in a format that is much more easily readable.
NEWS:
Announce all the user-visible changes above.
81 lines
2.6 KiB
Mathematica
81 lines
2.6 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ts=4 sw=4 et ft=mercury
|
|
%---------------------------------------------------------------------------%
|
|
%
|
|
% test_pretty_printer_defaults.m
|
|
% Ralph Becket <rafe@csse.unimelb.edu.au>
|
|
% Tue Aug 7 15:29:20 EST 2007
|
|
%
|
|
% Test the default pretty_printer formatters.
|
|
%
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- module test_pretty_printer_defaults.
|
|
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is det.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module array.
|
|
:- import_module char.
|
|
:- import_module int.
|
|
:- import_module list.
|
|
:- import_module one_or_more.
|
|
:- import_module map.
|
|
:- import_module pretty_printer.
|
|
:- import_module string.
|
|
:- import_module version_array.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
main(!IO) :-
|
|
pretty_printer.get_default_formatter_map(FMap, !IO),
|
|
% We print only the type names. Even if we could get them, there would be
|
|
% no point in printing the corresponding formatters, since they would
|
|
% all be printed as just "<<function>>".
|
|
FMapTypes = get_formatter_map_entry_types(FMap),
|
|
io.write_string("The types in the default formatter map:\n", !IO),
|
|
list.foldl(io.write_line, FMapTypes, !IO),
|
|
io.nl(!IO),
|
|
|
|
format_and_write_items("ints", 42, -123, !IO),
|
|
format_and_write_items("floats", 3.141, -10.0, !IO),
|
|
format_and_write_item("chars", [a, '*', '\n'], !IO),
|
|
format_and_write_item("string", "this is a string", !IO),
|
|
format_and_write_item("tuple", {1, '2', 3.0, "four"}, !IO),
|
|
|
|
A = array(L),
|
|
VA = version_array(L),
|
|
L = 1..100,
|
|
OoM = one_or_more(1, 2..100),
|
|
map.from_corresponding_lists(L, L, M),
|
|
|
|
format_and_write_item("array", A, !IO),
|
|
format_and_write_item("version_array", VA, !IO),
|
|
format_and_write_item("list", L, !IO),
|
|
format_and_write_item("one_or_more", OoM, !IO),
|
|
format_and_write_item("map", M, !IO).
|
|
|
|
:- pred format_and_write_item(string::in, T::in, io::di, io::uo) is det.
|
|
|
|
format_and_write_item(Label, Item, !IO) :-
|
|
Doc = docs([str(Label ++ ":"), nl, format(Item), nl]),
|
|
pretty_printer.write_doc(Doc, !IO),
|
|
io.nl(!IO).
|
|
|
|
:- pred format_and_write_items(string::in, T::in, T::in, io::di, io::uo)
|
|
is det.
|
|
|
|
format_and_write_items(Label, ItemA, ItemB, !IO) :-
|
|
Doc = docs([str(Label ++ ":"), nl,
|
|
format(ItemA), str(" "), format(ItemB), nl]),
|
|
pretty_printer.write_doc(Doc, !IO),
|
|
io.nl(!IO).
|