move most everything to messages.yap

This commit is contained in:
Vítor Santos Costa 2015-08-18 15:05:43 -05:00
parent 72776e3b14
commit 08733b815c

View File

@ -258,97 +258,3 @@ to allow user-control.
'$process_error'(Throw, _) :-
print_message(error,error(unhandled_exception,Throw)).
/** @pred message_to_string(+ _Term_, - _String_)
Translates a message-term into a string object. Primarily intended for SWI-Prolog emulation.
*/
message_to_string(Event, Message) :-
'$messages':generate_message(Event, Message, []).
/** @pred print_message(+ _Kind_, _Term_)
The predicate print_message/2 is used to print messages, notably from
exceptions in a human-readable format. _Kind_ is one of
`informational`, `banner`, `warning`, `error`,
`help` or `silent`. A human-readable message is printed to
the stream user_error.
If the Prolog flag verbose is `silent`, messages with
_Kind_ `informational`, or `banner` are treated as
silent. See `-q` in [Running_YAP_Interactively].
This predicate first translates the _Term_ into a list of `message
lines` (see print_message_lines/3 for details). Next it will
call the hook message_hook/3 to allow the user intercepting the
message. If message_hook/3 fails it will print the message unless
_Kind_ is silent.
If you need to report errors from your own predicates, we advise you to
stick to the existing error terms if you can; but should you need to
invent new ones, you can define corresponding error messages by
asserting clauses for `prolog:message/2`. You will need to declare
the predicate as multifile.
*/
print_message(_, _) :-
'$nb_getval'('$if_skip_mode',skip,fail),
!.
print_message(force(_Severity), Msg) :- !,
print(user_error,Msg).
print_message(error, error(Msg,Info)) :- var(Info), !,
print_message(error, error(Msg, '')).
print_message(error, error(Msg,[Info|local_sp(P,CP,Envs,CPs)])) :- !,
recorda(sp_info,local_sp(P,CP,Envs,CPs),R),
print_message(error, error(Msg, Info)),
erase(R).
print_message(Severity, Msg) :-
nonvar(Severity), nonvar(Msg),
user:portray_message(Severity, Msg), !.
% This predicate has more hooks than a pirate ship!
print_message(Severity, Term) :-
% first step at hook processing
'$messages':translate_message(Term, Lines, []),
( nonvar(Term),
user:message_hook(Term, Severity, Lines)
->
true
;
'$print_system_message'(Term, Severity, Lines)
), !.
print_message(silent, _) :- !.
print_message(_, loading(A, F)) :- !,
format(user_error,' % ~a ~a~n',[A,F]).
print_message(_, loaded(A, F, _, Time, Space)) :- !,
format(user_error,' % ~a ~a ~d bytes in ~d msecs~n',[F,A,Space,Time]).
print_message(_, Term) :-
format(user_error,'~q~n',[Term]).
% print_system_message(+Term, +Level, +Lines)
%
% Print the message if the user did not intercept the message.
% The first is used for errors and warnings that can be related
% to source-location. Note that syntax errors have their own
% source-location and should therefore not be handled this way.
'$print_system_message'(_, silent, _) :- !.
'$print_system_message'(_, informational, _) :-
current_prolog_flag(verbose, silent), !.
'$print_system_message'(_, banner, _) :-
current_prolog_flag(verbose, silent), !.
'$print_system_message'(Term, Level, Lines) :-
( Level == error -> true ; Level == warning ),
'$messages':prefix(Level, LinePrefix, Stream, Lines2, Lines),
'$messages':file_location(Term, LinesF, Lines2), !,
flush_output(user_output),
flush_output(user_error),
print_message_lines(Stream, LinePrefix, [nl|LinesF]).
'$print_system_message'(_Error, Level, Lines) :-
flush_output(user_output),
flush_output(user_error),
'$messages':prefix(Level, LinePrefix, Stream, LinesF, Lines), !,
print_message_lines(Stream, LinePrefix, LinesF).