[m-dev.] for review: fixing formatting of HLDS dumps
Fergus Henderson
fjh at cs.mu.OZ.AU
Thu Feb 18 19:47:53 AEDT 1999
On 18-Feb-1999, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> On 18-Feb-1999, Zoltan Somogyi <zs at cs.mu.OZ.AU> wrote:
> > +++ prog_out.m 1999/02/18 06:21:08
> > @@ -40,6 +40,9 @@
> > :- pred prog_out__write_sym_name(sym_name, io__state, io__state).
> > :- mode prog_out__write_sym_name(in, di, uo) is det.
> >
> > +:- pred prog_out__write_quoted_sym_name(sym_name, io__state, io__state).
> > +:- mode prog_out__write_quoted_sym_name(in, di, uo) is det.
>
> I think it might be better to just change the behaviour of
> prog_out__write_sym_name. Is there ever any reason to
> write out a sym_name not properly quoted?
To answer my own question: yes. In particular, when writing out error
messages, we already put the sym_name inside a back/forward-quote pair
`...', so adding a forward-quote pair '...' would leave you with `'...'',
which is horrible. So having a separate prog_out__write_sym_name and
prog_out__write_quoted_sym is correct.
However, even when writing out error messages, we still ought to escape
any special characters. For example, if you by mistake write
:- func newline = char.
newline = '\n '.
% ^ oops
then the error message that you currently get is very ugly,
foo.m:001: In clause for function `foo:x/0':
foo.m:001: in argument 1 of clause head:
foo.m:001: error: undefined symbol `
/0'.
and can't even be parsed properly by utilites such as emacs, error,
vim -e, etc. It would be better, IMHO, to use an error message
like this:
...
foo.m:001: error: undefined symbol `\n /0'.
(Trying to print out the symbol name in quotes, i.e.
foo.m:001: error: undefined symbol `'\n '/0'.
would be worse, IMHO.)
So I think prog_out__write_sym_name should be changed to call
term_io__write_escaped_string, while the new prog_out__write_quoted_string
that you have added should call term_io__write_atom.
Some comments are needed. I suggest the following:
% Write out a symbol name, with special characters escaped,
% but without any quotes. This is suitable for use in
% error messages, where the caller should print out an
% enclosing forward/backward-quote pair (`...').
:- pred prog_out__write_sym_name(sym_name, io__state, io__state).
:- mode prog_out__write_sym_name(in, di, uo) is det.
% Write out a symbol name, enclosed in single forward quotes ('...')
% if necessary, and with any special characters escaped.
% The output should be a syntactically valid Mercury term.
:- pred prog_out__write_quoted_sym_name(sym_name, io__state, io__state).
:- mode prog_out__write_quoted_sym_name(in, di, uo) is det.
--
Fergus Henderson <fjh at cs.mu.oz.au> | "Binaries may die
WWW: <http://www.cs.mu.oz.au/~fjh> | but source code lives forever"
PGP: finger fjh at 128.250.37.3 | -- leaked Microsoft memo.
More information about the developers
mailing list