<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><span style="font-size: 12px;" class=""><font face="DankMono-Regular" class="">%---------------------------------------------------------------------------%<br class="">%---------------------------------------------------------------------------%<br class="">%<br class="">% File: errors.m<br class="">% Main authors: sjc<br class="">% Date: 27-04-2021 21:05 Hrs<br class="">%<br class="">% Outputs an error message to stdout in one of the formats as specified by<br class="">% the type: options.error_format<br class="">%<br class="">%---------------------------------------------------------------------------%<br class="">%---------------------------------------------------------------------------%<br class=""><br class="">:- module errors.<br class="">:- interface.<br class="">:- import_module io.<br class="">:- use_module options.<br class=""><br class="">:- type felt_error<br class=""> ---> error(<br class=""> line :: int,<br class=""> col :: int,<br class=""> pos :: int,<br class=""> file :: string,<br class=""> reason :: string<br class=""> ).<br class=""><br class="">:- pred write_error(<br class=""> options.error_format::in,<br class=""> felt_error::in,<br class=""> io::di, io::uo<br class=""> ) is cc_multi.<br class=""><br class="">:- func make_error(int::in, int::in, int::in, string::in, string::in)<br class=""> = (felt_error::out) is det.<br class=""><br class="">:- implementation.<br class="">:- import_module list, string.<br class=""><br class=""> % PLAIN -- the default human readable error format.<br class=""> %<br class=""> write_error(options.plain, error(Pos, Line, Col, File, Reason), !IO) :-<br class=""> io.format(<br class=""> "*** FELT-ERROR ***A syntax error has been detected in your source:\n" ++<br class=""> "file:%s:(%i) at line %i, column %i. The reported error is:\n" ++<br class=""> "%s\n",<br class=""> [s(File), i(Pos), i(Line), i(Col), s(Reason)], !IO).<br class=""><br class=""> % SIMPLE -- for simple line based parsing applications.<br class=""> %<br class="">write_error(options.simple, error(Pos, Line, Col, File, Reason), !IO) :-<br class=""> io.format(<br class=""> "%s\n%i\n%i\n%i\n%s\n",<br class=""> [s(File), i(Pos), i(Line), i(Col), s(Reason)], !IO).<br class=""><br class=""> % JSON -- because the internet.<br class=""> %<br class="">write_error(options.json, error(Pos, Line, Col, File, Reason), !IO) :-<br class=""> % poss might need to escape the string but it's MY string!<br class=""> io.format(<br class=""> "{\"file\": \"%s\", \"pos\": %i, \"line\": %i, \"col\": %i, \"error\": \"%s\"}\n",<br class=""> [s(File), i(Pos), i(Line), i(Col), s(Reason)], !IO).<br class=""><br class=""> % XML -- bare minimum xml output<br class=""> %<br class="">write_error(options.xml, error(Pos, Line, Col, File, Reason), !IO) :-<br class=""> io.format(<br class=""> "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ++<br class=""> "<error file=\"%s\" pos=\"%i\" line=\"%i\" col=\"%i\">\n" ++<br class=""> "%s\n</error>\n",<br class=""> [s(File), i(Pos), i(Line), i(Col), s(Reason)], !IO).<br class=""><br class="">write_error(_, _, !_IO).<br class=""><br class=""> % Create standard error packet.<br class=""> %<br class="">make_error(Pos, Line, Col, File, Reason) = Error :-<br class=""> Error = error(Pos, Line, Col, File, Reason).</font><br class=""><br class=""></span><div style=""><br class=""><blockquote type="cite" class=""><div class="">On 30 Apr 2021, at 22:29, Zoltan Somogyi <<a href="mailto:zoltan.somogyi@runbox.com" class="">zoltan.somogyi@runbox.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class=""><br class=""><br class="">On Fri, 30 Apr 2021 22:24:12 +0100, "Sean Charles (emacstheviking)" <<a href="mailto:objitsu@gmail.com" class="">objitsu@gmail.com</a>> wrote:<br class=""><blockquote type="cite" class="">I seek some reassurance that this is the correct reasoning and the correct determinism.<br class=""></blockquote><br class="">I cannot answer that without the part of the write_error predicate you deleted.<br class=""><br class="">Zoltan.<br class=""><br class=""><br class=""><br class=""></div></div></blockquote></div><br class=""></body></html>