In my existing version (PHP, ) of my language there is a command line option to have the errors output as either one of:
- plain text (console use)
- JSON
- XML
I currently have errors coming out but I am passing in the File as I have so far failed to figure out how to use the prefix(File:Location) feature. I have been using this as my guide:
www.pathwayslms.com/swipltuts/message/index.html
The only code I have so far is this:
prolog:message(ast_error(syntax(map, uneven_elements, (L,C), File))) -->
['~s:~d:~d: map has an odd number of elements.'-[File, L, C]].
which is following the rules but I would then like to be able to decide how to subsequently render it out as JSON, XML or plain text according to some command line option previously set.
I have yet to succeed playing with message_property/2 etc, the error message handler I have basically unpacks then repacks the error term so convert the location, and make that and the source file name available, here’s the code, totally in flux, warts and all…
% ALL ERRORS are of the form:
% <module>_error( ErrorType ( Topic, Reason, Pos ) )
%
% ast_error( syntax( map, uneven_elements, 1234 ) ).
handle_error(File, Code, Error) :-
Error =.. [Sender, Exception],
Exception =.. [ErrorType, TopicOrKeyword, Reason, Pos],
( Pos >= 0
-> pos_linecol(Code, Pos, Locn)
; Locn = (-1,-1)
),
NewExc =.. [ErrorType, TopicOrKeyword, Reason, Locn, File],
NewError =.. [Sender, NewExc],
print_message(error, NewError).
So… looking for advice, enlightenment, suggestions for more idiomatic Prolog as I continue to learn!
Thanks,
Sean.