[m-dev.] io.read_named_file_as_*
Zoltan Somogyi
zoltan.somogyi at runbox.com
Fri Apr 7 10:44:36 AEST 2023
I am changing analysis.file.m to handle errors by returning error_specs
instead of throwing exceptions, and in the process found it
convenient to also change it from reading in one term at a time
to reading in the whole file at once, and parsing each term
without I/O. (There is no point in writing code to handle errors
arising from the reading of a term if we can just eliminate
that source of possible errors.)
The relevant documentation warns about the parser
that operates on the whole file as a string not being expected
to do the right thing given a malformed UTF-{8,16} string.
I could add a test for is_well_formed just after calling
read_file_as_string, but I expect that many callers of
read_file_as_string will want to do the same, so the logical
thing to do is factor out the commonality by adding
versions of read_file_as_string (and read_file_as_lines etc)
that include the well-formedness check.
I propose that we do so, in io.m, since we haven't started
migrating user-visible predicates to io.text_read.m yet.
Does anyone object? And what should the names
of the new versions be? I propose
- read_file_as_well_formed_string
- read_file_as_well_formed_lines
- read_well_formed_line
- read_well_formed_word
For at least the first two, it would be nice to say *what part*
of the file is not well formed. I could provide a companion
predicate to is_well_formed that *would* return that info,
if Peter says he will check my work.
Zoltan.
More information about the developers
mailing list