[m-rev.] for review: better error messages for string.format

Zoltan Somogyi zoltan.somogyi at runbox.com
Thu Nov 13 16:17:53 AEDT 2014


For review by anyone.

The motivation for the change should be apparent from
reading the diffs for the expected output files.

I am interested in comments on the XXX about whether
we should generate an error if a format string specifies
a useless precision for a %c conversion.

I believe the compiler won't be able to use exactly the same code
for parsing the format string as string.format itself, because
the representation of the list of polytypes is necessarily different.
For string.format, all values are manifest; for the compiler,
some are manifest, and some come from variables. While
I can see how one piece of polymorphic code can handle this
for values to be printed, I don't see any good enough way
to handle this for field widths and precisions, because while
most widths and precisions are manifest in the format string
itself, some come from the value list itself, when the format
string contains stuff like %*d. Besides the fact that any code
generic enough to handle this correctly for the compiler would
be too slow for interpreting format strings at runtime, I think
it would also generate less-than-optimally-useful error messages.

I am therefore thinking that I will move the format string
parsing code to either a new module, or two new modules
(one for runtime use, one for compiler use). Any objections?
FYI, string.format.m is now over 2000 lines (the parsing code
is a bit less than half of this). So even though string.format.m
is the newest module in the Mercury implementation, it is
already one of the biggest modules.

Zoltan.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Log.format_errors
Type: application/octet-stream
Size: 831 bytes
Desc: not available
URL: <http://lists.mercurylang.org/archives/reviews/attachments/20141113/531592f4/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: DIFF.format_errors
Type: application/octet-stream
Size: 39244 bytes
Desc: not available
URL: <http://lists.mercurylang.org/archives/reviews/attachments/20141113/531592f4/attachment-0001.obj>


More information about the reviews mailing list