70 stream.string_writer
%--------------------------------------------------%
% vim: ft=mercury ts=4 sw=4 et
%--------------------------------------------------%
% Copyright (C) 2006-2007, 2011 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.
%--------------------------------------------------%
%
% File: stream.string_writer.m.
% Authors: trd, fjh, stayl
%
% Predicates to write to streams that accept strings.
%
%--------------------------------------------------%
%--------------------------------------------------%
:- module stream.string_writer.
:- interface.
:- import_module char.
:- import_module deconstruct.
:- import_module io.
:- import_module list.
:- import_module string.
:- import_module univ.
%--------------------------------------------------%
:- pred put_int(Stream::in, int::in, State::di, State::uo) is det
<= stream.writer(Stream, string, State).
:- pred put_float(Stream::in, float::in, State::di, State::uo) is det
<= stream.writer(Stream, string, State).
:- pred put_char(Stream::in, char::in, State::di, State::uo) is det
<= stream.writer(Stream, string, State).
% A version of io.format that works for arbitrary string writers.
%
:- pred format(Stream::in, string::in, list(string.poly_type)::in,
State::di, State::uo) is det <= stream.writer(Stream, string, State).
:- pred nl(Stream::in, State::di, State::uo) is det
<= stream.writer(Stream, string, State).
% print/3 writes its argument to the standard output stream.
% print/4 writes its second argument to the output stream specified
% in its first argument. In all cases, the argument to output can be
% of any type. It is output in a format that is intended to be human
% readable.
%
% If the argument is just a single string or character, it will be printed
% out exactly as is (unquoted). If the argument is of type univ, then
% it will print out the value stored in the univ, but not the type.
%
% print/5 is the same as print/4 except that it allows the caller
% to specify how non-canonical types should be handled. print/3 and
% print/4 implicitly specify `canonicalize' as the method for handling
% non-canonical types. This means that for higher-order types, or types
% with user-defined equality axioms, or types defined using the foreign
% language interface (i.e. pragma foreign_type), the text output will
% only describe the type that is being printed, not the value.
%
% print_cc/3 is the same as print/3 except that it specifies
% `include_details_cc' rather than `canonicalize'. This means that it will
% print the details of non-canonical types. However, it has determinism
% `cc_multi'.
%
% Note that even if `include_details_cc' is specified, some implementations
% may not be able to print all the details for higher-order types or types
% defined using the foreign language interface.
%
:- pred print(Stream::in, T::in, State::di, State::uo) is det
<= (stream.writer(Stream, string, State),
stream.writer(Stream, char, State)).
:- pred print(Stream, deconstruct.noncanon_handling, T, State, State)
<= (stream.writer(Stream, string, State),
stream.writer(Stream, char, State)).
:- mode print(in, in(do_not_allow), in, di, uo) is det.
:- mode print(in, in(canonicalize), in, di, uo) is det.
:- mode print(in, in(include_details_cc), in, di, uo) is cc_multi.
:- mode print(in, in, in, di, uo) is cc_multi.
:- pred print_cc(Stream::in, T::in, State::di, State::uo) is cc_multi
<= (stream.writer(Stream, string, State),
stream.writer(Stream, char, State)).
% write/4 writes its second argument to the output stream specified
% in its first argument. In all cases, the argument to output may be
% of any type. The argument is written in a format that is intended to
% be valid Mercury syntax whenever possible.
%
% Strings and characters are always printed out in quotes, using backslash
% escapes if necessary. For higher-order types, or for types defined
% using the foreign language interface (pragma foreign_code), the text
% output will only describe the type that is being printed, not the value,
% and the result may not be parsable by `read'. For the types
% containing existential quantifiers, the type `type_desc' and closure
% types, the result may not be parsable by `read', either. But in all
% other cases the format used is standard Mercury syntax, and if you append
% a period and newline (".\n"), then the results can be read in again
% using `read'.
%
% write/5 is the same as write/4 except that it allows the caller
% to specify how non-canonical types should be handled. write_cc/4
% is the same as write/4 except that it specifies `include_details_cc'
% rather than `canonicalize'.
%
:- pred write(Stream::in, T::in, State::di, State::uo) is det
<= (stream.writer(Stream, string, State),
stream.writer(Stream, char, State)).
:- pred write(Stream, deconstruct.noncanon_handling, T, State, State) is det
<= (stream.writer(Stream, string, State),
stream.writer(Stream, char, State)).
:- mode write(in, in(do_not_allow), in, di, uo) is det.
:- mode write(in, in(canonicalize), in, di, uo) is det.
:- mode write(in, in(include_details_cc), in, di, uo) is cc_multi.
:- mode write(in, in, in, di, uo) is cc_multi.
:- pred write_cc(Stream::in, T::in, State::di, State::uo) is cc_multi
<= (stream.writer(Stream, string, State),
stream.writer(Stream, char, State)).
%--------------------------------------------------%
%--------------------------------------------------%