[m-dev.] for review: new module for handling file offsets

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Mar 10 08:07:41 AEDT 1999


On 09-Mar-1999, Zoltan Somogyi <zs at cs.mu.OZ.AU> wrote:
> 
> > > library/file_offset.m:
> > > 	A new module to handle conversions from offsets into files into
> > > 	line number, column number pairs.
> > 
> > That module looks fine, but I don't think it is of sufficiently general
> > usefulness to warrant inclusion in the standard library.
> 
> I disagree. Many other programs (in fact, all well-written programs that
> handle complex input) want to be able to give good error messages for
> problems with their input, and this module is useful in helping them
> accomplish that.

Even for programs that want to give good error messages,
I don't think the current interface is general enough
for me to be confident that it would be helpful for all
or most such programs.

For example, an alternative to using the file_offset library is to
simply keep track of the line and column numbers as you go, rather than
using offsets.  This is probably a fair bit simpler than using the
file_offset library, so if efficiency isn't particularly important,
I'd say it was preferable.

If efficiency is important, then an obvious approach to parsing is to
first read the whole file into memory [or even mmap() it in] and then
parse it.  (Currently there are some reasons why this approach doesn't
work as efficiently as it should in Mercury, but hopefully we will
eventually fix those...)  If you get a parse error, the current file_offset
library would not be ideal, because you already have the file in
memory, so you don't want to re-read it from disk again, particularly
not if this would result in two in-memory copies of the same file.

So it seems the file_offset library, at least in its current form, is useful
only for applications with medium efficiency requirements, not for low
efficiency or high efficiency applications,

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.



More information about the developers mailing list