YAP 7.1.0
messages.yap
Go to the documentation of this file.
1/*************************************************************************
2* *
3* YAP Prolog *
4* *
5* Yap Prolog was developed at NCCUP - Universidade do Porto *
6* *
7* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
8* *
9**************************************************************************
10* *
11* File: utilities for displaying messages in YAP. *
12* comments: error messages for YAP *
13* *
14* Last rev: $Date: 2008-07-16 10:58:59 $,$Author: vsc $ *
15* *
16* *
17*************************************************************************/
18
19/**
20 * @file messages.yap
21 * @author VITOR SANTOS COSTA <vsc@VITORs-MBP.lan>
22 * @date Thu Nov 19 10:22:26 2015
23 *
24 * @brief The YAP Message Handler
25 *
26 *
27*/
28
29:- module(system('$messages',[]),
30 [system_message/4,
31 file_location/3]).
32
33/**
34
35 @defgroup YAPMessages Message Handling
36 @{
37 @ingroup YAPControl
38
39The interaction between YAP and the user relies on YAP's ability to
40portray messages. These messages range from prompts to error
41information. All message processing is performed through the builtin
42print_message/2, in two steps:
43
44+ The message is processed into a list of commands
45+ The commands in the list are sent to the `format/3` builtin
46in sequence.
47
48
49The first argument to print_message/2 specifies the importance of
50the message. The options are:
51
52+ `error`
53error handling
54+ `warning`
55compilation and run-time warnings,
56+ `informational`
57generic informational messages
58+ `help`
59help messages (not currently implemented in YAP)
60+ `query`
61query used in query processing (not currently implemented in YAP)
62+ `silent`,M,Na,Ar,File, FilePos]],
63 [nl, nl].
64messages that do not produce output but that can be intercepted by hooks.
65
66
67The next table shows the main predicates and hooks associated to message
68handling in YAP:
69
70
71An error record comsists of An ISO compatible descriptor of the format
72
73error(errror_kind(Culprit,..), In)
74
75In YAP, the info field describes:
76
77- what() more detauls on the event
78
79- input_stream, may be one of;
80
81 - loop_stream
82 - file()
83 - none
84
85 - prolog_source(_) a record containing file, line, predicate, and clause
86 that activated the goal, or a list therof. YAP tries to search for the user
87 code generatinng the error.
88
89 - c_source(0), a record containing the line of C-code thhat caused the event. This
90 is reported under systm debugging mode, or if this is user code.
91
92 - stream_source() - a record containg data on the the I/O stream datum causisng the evwnt.
93
94 - user_message () - ttext on the event.
95
96
97*/
98
99:- message_hook/3use_system_module( user, []).
100
101:- dynamic prolog:message//1.
102:- multifile prolog:message//1.
103:- multifile message_hook/3.
104
105
106:- multifile user:portray_message/2.
107
108:- dynamic user:portray_message/2.
109
110/** @pred message_to_string(+ _Term_, - _String_)
111
112
113Translates a message-term into a string object. Primarily intended for SWI-Prolog emulation.
114
115
116
117 */
118use_system_module:message_to_string(Event, Message) :-
119 translate_message(Event, Message, []).
120
121
122%% @pred translate_message(+Term, +Lines, -Lines0) is det
123%
124% Print the message if the user did not intercept the message.
125% The first is used for errors and warnings that can be related
126% to source-location. Note that syntax errors have their own
127% source-location and should therefore not be handled this way.
128translate_message( Term ) -->
129 message(Term), message.
130translate_message(answer(Vs, GVs, LGs, Extras)) -->
131 translate_message,
132 write_query_answer( Vs, GVs , LGs, Extras).
133translate_message( absolute_file_path(File)) -->
134 translate_message,
135 [ '~N~n absolute_file of ~w' - [File] ].
136translate_message( absolute_file_path(Msg, Args)) -->
137 translate_message,
138 [ ' : ' - [],
139 Msg - Args,
140 nl ].
141translate_message( absolute_file_path_component(Msg, Args)) -->
142 translate_message,
143 [ ' ~s: ' - [Msg]],
144 ['$messages':seq(Args) ].
145translate_message( arguments([])) -->
146 translate_message.
147translate_message( arguments([A|As])) -->
148 translate_message,
149 [ ' ~w' - [A],
150 nl ],
151 translate_message( arguments(As)).
152translate_message( ancestors([])) -->
153 translate_message,
154 [ 'There are no ancestors.' ].
155translate_message( breakp(bp(debugger,_,_,M:F/N,_),add,already)) -->
156 translate_message,
157 [ 'There is already a spy point on ~w:~w/~w.' - [M,F,N] ].
158translate_message( breakp(bp(debugger,_,_,M:F/N,_),add,ok)) -->
159 translate_message,
160 [ 'Spy point set on ~w:~w/~w.' - [M,F,N] ].
161translate_message( breakp(bp(debugger,_,_,M:F/N,_),remove,last)) -->
162 translate_message,
163 [ 'Spy point on ~w:~w/~w removed.' - [M,F,N] ].
164translate_message( breakp(no,breakpoint_for,M:F/N)) -->
165 translate_message,
166 [ 'There is no spy point on ~w:~w/~w.' - [M,F,N] ].
167translate_message( breakpoints([])) -->
168 translate_message,
169 [ 'There are no spy-points set.' ].
170translate_message( breakpoints(L)) -->
171 translate_message,
172 [ 'Spy-points set on:' ],
173 list_of_preds(L).
174translate_message( clauses_not_together(P)) -->
175 translate_message,
176 [ 'Discontiguous definition of ~q.' - [P] ].
177translate_message( debug(debug)) -->
178 translate_message,
179 [ 'Debug mode on.' - [] ].
180translate_message( debug(off)) -->
181 translate_message,
182 [ 'Debug mode off.'- [] ].
183translate_message( debug(trace)) -->
184 translate_message,
185 [ 'Trace mode on.'- [] ].
186translate_message( declaration(Args,Action)) -->
187 translate_message,
188 [ 'declaration ~w ~w.' - [Args,Action] ].
189translate_message( defined_elsewhere(P,F)) -->
190 translate_message,
191 [ 'predicate ~q previously defined in file ~w' - [P,F] ].
192translate_message( functionality(Library)) -->
193 translate_message,
194 [ '~q not available' - [Library] ].
195translate_message( import(Pred,To,From,private)) -->
196 translate_message,
197 [ 'Importing private predicate ~w:~w to ~w.' - [From,Pred,To] ].
198translate_message( redefine_imported(M,M0,PI)) -->
199 translate_message,
200 { source_location(ParentF, Line) },
201 [ '~N~w:~w:~w Module ~w redefines imported predicate ~w:~w.' - [ParentF, Line,0, M,M0,PI] ].
202translate_message( leash([])) -->
203 translate_message,
204 [ 'No leashing.' ].
205translate_message( leash([A|B])) -->
206 translate_message,
207 [ 'Leashing set to ~w.' - [[A|B]] ].
208translate_message(yes) -->
209 translate_message,
210 [ '.' - [],
211 nl,
212 'yes~n'- [] ].
213translate_message(false) -->
214 translate_message,
215 [ '~Nno~n'- [] ].
216translate_message( no) -->
217 translate_message,
218 [ '~Nno~n' - [] ].
219translate_message( no_match(P)) -->
220 translate_message,
221 [ 'No matching predicate for ~w.' - [P] ].
222translate_message( leash([A|B])) -->
223 translate_message,
224 [ 'Leashing set to ~w.' - [[A|B]] ].
225translate_message( halt) -->
226 translate_message,
227 [ 'YAP execution halted.'-[] ].
228translate_message( '$abort') --> translate_message,
229 [ 'YAP execution aborted'-[] ].
230translate_message( abort(user)) --> translate_message,
231 [ 'YAP execution aborted' - [] ].
232translate_message( loading(_,F)) --> { F == user }, .
233translate_message( loading(What,FileName)) --> translate_message,
234 { '$show_consult_level'(LC) },
235 [ '~N~*|~a ~w...' - [LC, What, FileName] ].
236translate_message( loaded(_,user,_,_,_)) --> translate_message.
237translate_message( loaded(What,AbsFileName,Mod,Time,Space)) --> translate_message,
238 { '$show_consult_level'(LC) },
239 [ '~N~*|~a ~a in module ~a, ~d msec ~d bytes' - [LC, AbsFileName,What,Mod,Time,Space] ].
240translate_message(signal(SIG,_)) -->
241 translate_message,
242 [ 'UNEXPECTED SIGNAL: ~a' - [SIG] ].
243translate_message(trace_command(C)) -->
244 translate_message,
245 [ '~a is not a valid debugger command.' - [C] ].
246translate_message(trace_help) -->
247 translate_message,
248 [ ' Please enter a valid debugger command (h for help).' ].
249translate_message(version(yap(Mj,Mi,Patch,_),VersionGit,AT,Saved)) -->
250 translate_message,
251 { sub_atom( VersionGit, 0, 8, _, VERSIONGIT ) },
252 [ 'YAP ~d.~d.~d-~a (compiled ~a)~n' - [Mj,Mi, Patch, VERSIONGIT, AT],
253 'database loaded from ~a~n' - [Saved] ].
254translate_message(myddas_version(Version)) -->
255 translate_message,
256 [ 'MYDDAS version ~a' - [Version] ].
257translate_message(throw(BALL)) -->
258 translate_message,
259 [ 'WARNING: throw of ~W had no catch' - [BALL,[]] ].
260translate_message(error(syntax_error(E),Exc)) -->
261 translate_message,
262 {
263 error_descriptor(Exc, Desc),
264 '$show_consult_level'(LC)
265 },
266 location(Desc, error, short, LC),
267 main_message(error(syntax_error(E),Exc), error, LC ).
268translate_message(error(style_check(What,File,Line,Clause),Exc))-->
269 translate_message,
270 { error_descriptor(Exc, Desc),
271 '$show_consult_level'(LC) },
272 location( Desc, error, short, LC),
273 main_message(error(style_check(What,File,Line,Clause),Exc), warning, LC ).
274translate_message(error(E, Info)) -->
275 {
276 '$show_consult_level'(LC),
277 error_descriptor(Info, Desc),
278 Level = error_descriptor
279 },
280 %{start_low_level_trace},
281 location( Desc, Level,full , LC),
282 main_message(error(E,Info) , Level, LC ),
283 c_goal( Desc, Level, LC ),
284 extra_info( Desc, Level, LC ),
285 stack_info( Desc, Level, LC ),
286 stack_info,
287 [nl],
288 [nl].
289translate_message(error(user_defined_error(Error),Info))-->
290 translate_message,
291 { '$show_consult_level'(LC),
292 error_descriptor(Info, Desc) },
293 location(Desc, error, short, LC),
294 translate_message(Error).
295translate_message(error(Exc, Info)) -->
296 {
297 '$show_consult_level'(LC),
298 error_descriptor(Info, Desc),
299% Level = error,
300 Exc \= exception(_)
301 },
302 !,
303 c_goal( Desc, error, LC ).
304translate_message(error(Descriptor,exception(Error))) -->
305 translate_message,
306 [ 'ERROR NOT RECOGNISED - ~w unsupported both by YAP system code and by user hooks:' - [Descriptor] , nl],
307 [ '~@' - ['print_exception'(Error)] ,nl].
308translate_message(Throw) -->
309 translate_message,
310 [Throw].
311
312seq([]) --> [].
313seq([A|Args]) -->
314 [['~w '] - A],
315 seq(Args).
316
317/** @pred location: output error location.
318 *
319 */
320:- set_prolog_flag(discontiguous_warnings, false).
321
322location( Desc, Level, More, LC ) -->
323 {
324 query_exception(prologConsulting, Desc, true),
325 % query_exception(parserReadingCode, Desc, true),
326 query_exception(parserLine, Desc, LN),
327 nonvar(LN),
328 query_exception(parserFile, Desc, FileName),
329 nonvar(FileName),
330 query_exception(parserPos, Desc, Pos),
331 (var(Pos) -> Pos=1;var)
332 },
333 [ '~N~s:~d:~d ~a:'-[FileName, LN,Pos,Level], nl ],
334 !,
335 ({More == }
336 ->
337 prolog_caller( Desc, Level, LC)
338 ;
339 []
340 ).
341location( Desc, Level, _, LC ) -->
342 prolog_caller( Desc, Level, LC).
343
344
345prolog_caller( Desc, Level, LC ) -->
346 {
347 query_exception(prologPredFile, Desc, FileName),
348 query_exception(prologPredLine, Desc, LN),
349 query_exception(prologPredName, Desc, Name),
350 query_exception(prologPredArity, Desc, Arity),
351 query_exception(prologPredModule, Desc, Module)
352 },
353 !,
354 [ '~N~s:~d:0 ~a executing ~s:~s/~d:'-[FileName, LN,Level,Module,Name,Arity] ],
355 [],
356 c_caller( Desc, Level, LC).
357
358prolog_caller( Desc, Level, LC ) -->
359 [ '~Nuser:~d:0 ~a in top-level goal.'-[0,Level]],
360 [nl],
361 c_caller( Desc, Level, LC).
362
363c_caller( Desc, Level, _LC ) -->
364 {
365 query_exception(errorFile, Desc, FileName),
366 query_exception(errorLine, Desc, LN),
367 query_exception(errorFunction, Desc, F)
368 },
369 !,
370 [ '~N~s:~d:0: ~a in ~s():'-[FileName, LN,Level,F] ].
371c_caller( _Desc, _Level, _LC ) --> [].
372
373event(redo, _Desc) --> {fail}.
374event(fail, _Desc) --> {fail}.
375event(abort, Desc) --> { throw(event(abort, Desc)) }.
376
377simplify_pred(user:F, F) :- simplify_pred.
378simplify_pred(prolog:F, F) :- simplify_pred.
379simplify_pred(F, F).
380
381%message(loaded(Past,AbsoluteFileName,user,Msec,Bytes), Prefix_, Suffix) :- !,
382
383main_message(error(Msg,In), _, _) --> {var(Msg)}, !,
384 [ 'Uninstantiated message ~w~n.' - [error(Msg,In)], nl ].
385main_message(error(style_check(singleton(SVs),_Pos, _File,P), _Exc), _Level, LC) -->
386 main_message,
387 {
388 clause_to_indicator(P, I),
389 svs(SVs, SVsL),
390 ( SVs = [_] -> NVs = 0 ; NVs = 1 )
391 },
392 [
393 ,
394 '~*|singleton variable~*c ~s in ~q.' -
395 [ LC, NVs, 0's, SVsL, I] % '
396 ].
397main_message(error(style_check(discontiguous(N,A,Mod),_Pos,_File,_P), _Exc), _Level, LC) -->
398 main_message,
399 [ '~*|discontiguous definition for ~p.' - [ LC,Mod:N/A] ].
400main_message(error(style_check(multiple(N,A,Mod,F0),L,F,_P ), _Info), Level, LC) -->
401 main_message,
402 [ '~N~*|~a:~d:0: ~a: ~q previously defined in ~a!!'-[LC,F, L, Level ,Mod:N/A,F0], nl, nl ].
403main_message( error(syntax_error(_Msg),Info), _Level, _LC ) -->
404 {
405 error_descriptor(Info, Desc),
406 query_exception(parserTextA, Desc, J),
407 J \= '',
408 J \= query_exception
409 query_exception(parserTextB, Desc, K),
410 K > 0
411 },
412 !,
413 {
414 sub_text(J,0,K,_,Jb),
415 atomic_concat(Jb,Je,J)
416 },
417 !,
418 ['~N%%%'-[],
419 ,
420 '~s <<SYNTAX ERROR>> ~s' - [Jb,Je],
421 ,
422 '~N%%%'-[],
423 ,
424 ].
425main_message(error(ErrorInfo,_), _Level, LC) -->
426 [nl],
427 main_error_message( ErrorInfo, LC ).
428
429
430main_error_message(consistency_error(Who),LC) -->
431 [ '~*|%%% argument ~a not consistent with type.'-[ LC,Who] ].
432main_error_message(domain_error(Who , Type),LC) -->
433 [ '~*|%%% ~a: ~q does not belong to domain.' - [ LC,Type,Who] ].
434main_error_message(evaluation_error(What),LC) -->
435 [ '~*|%%% found ~w during evaluation of arithmetic expression.' - [ LC,What] ].
436main_error_message(evaluation_error(What, Who),LC) -->
437 [ '~*|%%% ~w caused ~a during evaluation of arithmetic expressions.' - [ LC,Who,What]].
438main_error_message(existence_error(Type , Who),LC) -->
439 [ '~*|%%% ~q ~q does not exist.' - [ LC,Type, Who] ].
440main_error_message(permission_error(Op, Type, Id),LC) -->
441 [ '~*|%%% value ~q is not allowed in ~a ~q.' - [ LC, Op, Type,Id] ].
442main_error_message(instantiation_error,LC) -->
443 [ '~*|%%% unbound variable.' - [LC] ].
444main_error_message(representation_error(Type),LC) -->
445 [ '~*|%%% YAP cannot represent ~w.' - [LC, Type] ].
446main_error_message(resource_error(Who),LC) -->
447 [ '~*|%%% ~q.' - [LC,Who]].
448main_error_message(syntax_error(Who),LC) -->
449 [ '~*|%%% ~w while parsing.' - [ LC,Who]].
450main_error_message(type_error(Type,Who),LC) -->
451 [ '~*|%%% ~q should be of type ~a.' - [LC,Who,Type]].
452main_error_message(system_error(Who, In),LC) -->
453 [ '~*|%%% ~q ~q.' - [LC,Who, In]].
454mainw_error_message(uninstantiation_error(T),LC) -->
455 [ '~*|%%% found ~q, expected unbound variable.' - [LC,T]].
456
457display_consulting( _F, Level, Info, LC) -->
458 { LC > 0,
459 error_descriptor(Info, Desc),
460 query_exception(prologParserFile, Desc, F0),
461 query_exception(prologParserLine, Desc, L),
462 integer(L)
463% , F \= F0
464 }, !,
465 [ '~a:~d:0: ~a raised!!:'-[F0,Level], ].
466
467display_consulting(_F, _, _, _LC) -->
468 [].
469
470c_goal( Desc,_, LC) -->
471 {
472 query_exception(errorGoal, Desc, G) },
473 !,
474 ['~*|call was: ~w' - [LC,G]].
475c_goal(_,_,_) --> [].
476
477
478extra_info( Desc, _, LC ) -->
479 {
480 query_exception(errorMsg, Desc, Msg),
481 Msg \= '',
482 Msg \= "",
483 Msg \= []
484 },
485 !,
486 [],
487 ['~*|%'-[LC]],
488 [],
489 ['~*|% info: ~s' - [LC,Msg]],
490 [].
491extra_info( _, _, _ ) -->
492 [nl].
493
494stack_info( _, _, _ ) --> stack_info.
495stack_info( Desc,_, LC) -->
496 {
497 query_exception(prologStack, Desc, Stack),
498 Stack \= []
499
500 },
501 !,
502 ['~*|Prolog execution stack is:' - [LC]],
503 [],
504 [Stack - []].
505stack_info( _, _ ) -->
506 [].
507
508
509
510prolog_message(X) -->
511 system_message(X).
512
513system_message(error(Msg,In)) -->
514 ( { var(Msg) } ; { var(In)} ), !,
515 ['bad error ~w' - [error(Msg,In)]].
516system_message(error(consistency_error(Who),Where)) -->
517 [ 'CONSISTENCY ERROR (arguments not compatible with format)- ~w ~w' - [Who,Where] ].
518system_message(error(context_error(Goal,Who),Where)) -->
519 [ 'CONTEXT ERROR- ~w: ~w appeared in ~w' - [Goal,Who,Where] ].
520system_message(error(domain_error(DomainType,Opt), Where)) -->
521 [ 'DOMAIN ERROR- ~w: ' - Where],
522 domain_error(DomainType, Opt).
523system_message(error(format_argument_type(Type,Arg), Where)) -->
524 [ 'FORMAT ARGUMENT ERROR- ~~~a called with ~w in ~w: ' - [Type,Arg,Where]].
525system_message(error(existence_error(directory,Key), Where)) -->
526 [ 'EXISTENCE ERROR- ~w: ~w not an existing directory' - [Where,Key] ].
527system_message(error(existence_error(key,Key), Where)) -->
528 [ 'EXISTENCE ERROR- ~w: ~w not an existing key' - [Where,Key] ].
529system_message(error(existence_error(mutex,Key), Where)) -->
530 [ 'EXISTENCE ERROR- ~w: ~w is an erased mutex' - [Where,Key] ].
531system_message(existence_error(prolog_flag,F)) -->
532 [ 'Prolog Flag ~w: new Prolog flags must be created using create_prolog_flag/3.' - [F] ].
533system_message(error(existence_error(prolog_flag,P), Where)) --> system_message,
534 [ 'EXISTENCE ERROR- ~w: prolog flag ~w is undefined' - [Where,P] ].
535system_message(error(existence_error(procedure,P), context(Call,Parent))) --> system_message, [ 'EXISTENCE ERROR- procedure ~w is undefined, called fromcontext ~w~n Goal was ~w' - [P,Parent,Call] ].
536system_message(error(existence_error(stream,Stream), Where)) -->
537 [ 'EXISTENCE ERROR- ~w: ~w not an open stream' - [Where,Stream] ].
538system_message(error(existence_error(thread,Thread), Where)) -->
539 [ 'EXISTENCE ERROR- ~w: ~w not a running thread' - [Where,Thread] ].
540system_message(error(existence_error(variable,Var), Where)) -->
541 [ 'EXISTENCE ERROR- ~w: variable ~w does not exist' - [Where,Var] ].
542system_message(error(existence_error(Name,F), W)) -->
543 { object_name(Name, ObjName) },
544 [ 'EXISTENCE ERROR- ~w could not open ~a ~w' - [W,ObjName,F] ].
545system_message(error(evaluation_error(int_overflow), Where)) -->
546 [ 'INTEGER OVERFLOW ERROR- ~w' - [Where] ].
547system_message(error(evaluation_error(float_overflow), Where)) -->
548 [ 'FLOATING POINT OVERFLOW ERROR- ~w' - [Where] ].
549system_message(error(evaluation_error(undefined), Where)) -->
550 [ 'UNDEFINED ARITHMETIC RESULT ERROR- ~w' - [Where] ].
551system_message(error(evaluation_error(underflow), Where)) -->
552 [ 'UNDERFLOW ERROR- ~w' - [Where] ].
553system_message(error(evaluation_error(float_underflow), Where)) -->
554 [ 'FLOATING POINT UNDERFLOW ERROR- ~w' - [Where] ].
555system_message(error(evaluation_error(zero_divisor), Where)) -->
556 [ 'ZERO DIVISOR ERROR- ~w' - [Where] ].
557system_message(error(not_implemented(Type, What), Where)) -->
558 [ '~w: ~w not implemented- ~w' - [Where, Type, What] ].
559system_message(error(operating_SYSTEM_ERROR_INTERNAL, Where)) -->
560 [ 'OPERATING SYSTEM ERROR- ~w' - [Where] ].
561system_message(error(out_of_heap_error, Where)) -->
562 [ 'OUT OF DATABASE SPACE ERROR- ~w' - [Where] ].
563system_message(error(out_of_stack_error, Where)) -->
564 [ 'OUT OF STACK SPACE ERROR- ~w' - [Where] ].
565system_message(error(out_of_trail_error, Where)) -->
566 [ 'OUT OF TRAIL SPACE ERROR- ~w' - [Where] ].
567system_message(error(out_of_attvars_error, Where)) -->
568 [ 'OUT OF STACK SPACE ERROR- ~w' - [Where] ].
569system_message(error(out_of_auxspace_error, Where)) -->
570 [ 'OUT OF AUXILIARY STACK SPACE ERROR- ~w' - [Where] ].
571system_message(error(permission_error(access,private_procedure,P), Where)) -->
572 [ 'PERMISSION ERROR- ~w: cannot see clauses for ~w' - [Where,P] ].
573system_message(error(permission_error(access,static_procedure,P), Where)) -->
574 [ 'PERMISSION ERROR- ~w: cannot access static procedure ~w' - [Where,P] ].
575system_message(error(permission_error(alias,new,P), Where)) -->
576 [ 'PERMISSION ERROR- ~w: cannot create alias ~w' - [Where,P] ].
577system_message(error(permission_error(create,Name,P), Where)) -->
578 [ 'PERMISSION ERROR- ~w: cannot create ~a ~w' - [Where,Name,P] ].
579system_message(error(permission_error(import,M1:I,redefined,SecondMod), Where)) -->
580 [ 'PERMISSION ERROR- loading ~w: modules ~w and ~w both define ~w' - [Where,M1,SecondMod,I] ].
581system_message(error(permission_error(input,binary_stream,Stream), Where)) -->
582 [ 'PERMISSION ERROR- ~w: cannot read from binary stream ~w' - [Where,Stream] ].
583system_message(error(permission_error(input,closed_stream,Stream), Where)) -->
584 [ 'PERMISSION ERROR- ~w: trying to read from closed stream ~w' - [Where,Stream] ].
585system_message(error(permission_error(input,past_end_of_stream,Stream), Where)) -->
586 [ 'PERMISSION ERROR- ~w: past end of stream ~w' - [Where,Stream] ].
587system_message(error(permission_error(input,stream,Stream), Where)) -->
588 [ 'PERMISSION ERROR- ~w: cannot read from ~w' - [Where,Stream] ].
589system_message(error(permission_error(input,text_stream,Stream), Where)) -->
590 [ 'PERMISSION ERROR- ~w: cannot read from text stream ~w' - [Where,Stream] ].
591system_message(error(permission_error(modify,dynamic_procedure,_), Where)) -->
592 [ 'PERMISSION ERROR- ~w: modifying a dynamic procedure' - [Where] ].
593system_message(error(permission_error(modify,flag,W), _)) -->
594 [ 'PERMISSION ERROR- cannot modify flag ~w' - [W] ].
595system_message(error(permission_error(modify,operator,W), Q)) -->
596 [ 'PERMISSION ERROR- ~w: cannot modify operator ~q' - [Q,W] ].
597system_message(error(permission_error(modify,dynamic_procedure,F), Where)) -->
598 [ 'PERMISSION ERROR- ~w: modifying dynamic procedure ~w' - [Where,F] ].
599system_message(error(permission_error(modify,static_procedure,F), Where)) -->
600 [ 'PERMISSION ERROR- ~w: modifying static procedure ~w' - [Where,F] ].
601system_message(error(permission_error(modify,static_procedure_in_use,_), Where)) -->
602 [ 'PERMISSION ERROR- ~w: modifying a static procedure in use' - [Where] ].
603system_message(error(permission_error(modify,table,P), _)) -->
604 [ 'PERMISSION ERROR- cannot table procedure ~w' - [P] ].
605system_message(error(permission_error(module,redefined,Mod), Who)) -->
606 [ 'PERMISSION ERROR ~w- redefining module ~a in a different file' - [Who,Mod] ].
607system_message(error(permission_error(open,source_sink,Stream), Where)) -->
608 [ 'PERMISSION ERROR- ~w: cannot open file ~w' - [Where,Stream] ].
609system_message(error(permission_error(output,binary_stream,Stream), Where)) -->
610 [ 'PERMISSION ERROR- ~w: cannot write to binary stream ~w' - [Where,Stream] ].
611system_message(error(permission_error(output,stream,Stream), Where)) -->
612 [ 'PERMISSION ERROR- ~w: cannot write to ~w' - [Where,Stream] ].
613system_message(error(permission_erroro(utput,text_stream,Stream), Where)) -->
614 [ 'PERMISSION ERROR- ~w: cannot write to text stream ~w' - [Where,Stream] ].
615system_message(error(permission_error(resize,array,P), Where)) -->
616 [ 'PERMISSION ERROR- ~w: cannot resize array ~w' - [Where,P] ].
617system_message(error(permission_error(unlock,mutex,P), Where)) -->
618 [ 'PERMISSION ERROR- ~w: cannot unlock mutex ~w' - [Where,P] ].
619system_message(error(representation_error(character), Where)) -->
620 [ 'REPRESENTATION ERROR- ~w: expected character' - [Where] ].
621system_message(error(representation_error(character_code), Where)) -->
622 [ 'REPRESENTATION ERROR- ~w: expected character code' - [Where] ].
623system_message(error(representation_error(max_arity), Where)) -->
624 [ 'REPRESENTATION ERROR- ~w: number too big' - [Where] ].
625system_message(error(representation_error(variable), Where)) -->
626 [ 'REPRESENTATION ERROR- ~w: should be a variable' - [Where] ].
627system_message(error(resource_error(code_space), Where)) -->
628 [ 'RESOURCE ERROR- not enough code space' - [Where] ].
629system_message(error(resource_error(huge_int), Where)) -->
630 [ 'RESOURCE ERROR- too large an integer in absolute value' - [Where] ].
631system_message(error(resource_error(memory), Where)) -->
632
633 [ 'RESOURCE ERROR- not enough virtual memory' - [Where] ].
634system_message(error(resource_error(stack), Where)) -->
635 [ 'RESOURCE ERROR- not enough stack' - [Where] ].
636system_message(error(resource_error(streams), Where)) -->
637 [ 'RESOURCE ERROR- could not find a free stream' - [Where] ].
638system_message(error(resource_error(threads), Where)) -->
639 [ 'RESOURCE ERROR- too many open threads' - [Where] ].
640system_message(error(resource_error(trail), Where)) -->
641 [ 'RESOURCE ERROR- not enough trail space' - [Where] ].
642system_message(error(signal(SIG,_), _)) -->
643 [ 'UNEXPECTED SIGNAL: ~a' - [SIG] ].
644% SWI like I/O error message.
645system_message(error(_,exception(Error))) -->
646 [ 'UNHANDLED ERROR - unsupported by YAP engine or hooks: ~@' - [print_exception(Error)] ].
647system_message(error(unhandled_exception,Throw)) -->
648 [ 'UNHANDLED EXCEPTION - message ~w unknown' - [Throw] ].
649system_message(error(uninstantiation_error(TE), _Where)) -->
650 [ 'UNINSTANTIATION ERROR - expected unbound term, got ~q' - [TE] ].
651system_message(Messg) -->
652 [ '~q' - Messg ].
653
654
655domain_error(array_overflow, Opt) --> domain_error,
656 [ 'invalid static index ~w for array' - Opt ].
657domain_error(array_type, Opt) --> domain_error,
658 [ 'invalid static array type ~w' - Opt ].
659domain_error(builtin_procedure, _) --> domain_error,
660 [ 'non-iso built-in procedure' - [] ].
661domain_error(character_code_list, Opt) --> domain_error,
662 [ 'invalid list of codes ~w' - [Opt] ].
663domain_error(close_option, Opt) --> domain_error,
664 [ 'invalid close option ~w' - [Opt] ].
665domain_error(delete_file_option, Opt) --> domain_error,
666 [ 'invalid list of options ~w' - [Opt] ].
667domain_error(encoding, Opt) --> domain_error,
668 [ 'invalid encoding ~w' - [Opt] ].
669domain_error(flag_value, [Opt,Flag]) --> domain_error,
670 [ 'invalid value ~w for flag ~w' - [Opt,Flag] ].
671domain_error(flag_value, Opt) --> domain_error,
672 [ 'invalid value ~w for flag' - [Opt] ].
673domain_error(io_mode, Opt) --> domain_error,
674 [ 'invalid io mode ~w' - [Opt] ].
675domain_error(mutable, Opt) --> domain_error,
676 [ 'invalid id mutable ~w' - [Opt] ].
677domain_error(module_decl_options, Opt) --> domain_error,
678 [ 'expect module declaration options, found ~w' - [Opt] ].
679domain_error(non_empty_list, Opt) --> domain_error,
680 [ 'found empty list' - [Opt] ].
681domain_error(not_less_than_zero, Opt) --> domain_error,
682 [ 'number ~w less than zero' - [Opt] ].
683domain_error(not_newline, Opt) --> domain_error,
684 [ 'number ~w not newline' - [Opt] ].
685domain_error(not_zero, Opt) --> domain_error,
686 [ '~w is not allowed in the domain' - [Opt] ].
687domain_error(operator_priority, Opt) --> domain_error,
688 [ '~w invalid operator priority' - [Opt] ].
689domain_error(operator_specifier, Opt) --> domain_error,
690 [ 'invalid operator specifier ~w' - [Opt] ].
691domain_error(out_of_range, Opt) --> domain_error,
692 [ 'expression ~w is out of range' - [Opt] ].
693domain_error(predicate_spec, Opt) --> domain_error,
694 [ '~w invalid predicate specifier' - [Opt] ].
695domain_error(radix, Opt) --> domain_error,
696 [ 'invalid radix ~w' - [Opt] ].
697domain_error(read_option, Opt) --> domain_error,
698 [ '~w invalid option to read_term' - [Opt] ].
699domain_error(semantics_indicator, Opt) --> domain_error,
700 [ 'predicate indicator, got ~w' - [Opt] ].
701domain_error(shift_count_overflow, Opt) --> domain_error,
702 [ 'shift count overflow in ~w' - [Opt] ].
703domain_error(source_sink, Opt) --> domain_error,
704 [ '~w is not a source sink term' - [Opt] ].
705domain_error(stream, Opt) --> domain_error,
706 [ '~w is not a stream' - [Opt] ].
707domain_error(stream_or_alias, Opt) --> domain_error,
708 [ '~w is not a stream (or alias)' - [Opt] ].
709domain_error(stream_encoding, Opt) --> domain_error,
710 [ '~w is not a supported stream encoding' - [Opt] ].
711domain_error(stream_position, Opt) --> domain_error,
712 [ '~w is not a stream position' - [Opt] ].
713domain_error(stream_property, Opt) --> domain_error,
714 [ '~w is not a stream property' - [Opt] ].
715domain_error(syntax_error_handler, Opt) --> domain_error,
716 [ '~w is not a syntax error handler' - [Opt] ].
717domain_error(table, Opt) --> domain_error,
718 [ 'non-tabled procedure ~w' - [Opt] ].
719domain_error(thread_create_option, Opt) --> domain_error,
720 [ '~w is not a thread_create option' - [Opt] ].
721domain_error(time_out_spec, Opt) --> domain_error,
722 [ '~w is not valid specificatin for time_out' - [Opt] ].
723domain_error(unimplemented_option, Opt) --> domain_error,
724 [ '~w is not yet implemented' - [Opt] ].
725domain_error(write_option, Opt) --> domain_error,
726 [ '~w invalid write option' - [Opt] ].
727domain_error(Domain, Opt) -->
728 [ '~w does not belong to domain ~w' - [Opt,Domain] ].
729
730object_name(array, array).
731object_name(atom, atom).
732object_name(atomic, atomic).
733object_name(byte, byte).
734object_name(callable, 'callable goal').
735object_name(char, char).
736object_name(character_code, 'character code').
737object_name(compound, 'compound term').
738object_name(db_reference, 'data base reference').
739object_name(evaluable, 'evaluable term').
740object_name(file, file).
741object_name(float, float).
742object_name(in_byte, byte).
743object_name(in_character, character).
744object_name(integer, integer).
745
746object_name(key, 'database key').
747object_name(leash_mode, 'leash mode').
748object_name(library, library).
749object_name(list, list).
750object_name(message_queue, 'message queue').
751object_name(mutex, mutex).
752object_name(number, number).
753object_name(operator, operator).
754object_name(pointer, pointer).
755object_name(predicate_indicator, 'predicate indicator').
756object_name(source_sink, file).
757object_name(unsigned_byte, 'unsigned byte').
758object_name(unsigned_char, 'unsigned char').
759object_name(variable, 'unbound variable').
760
761svs([A=_VA], S) :- svs,
762 atom_string(A, S).
763svs([A=_VA,B=_VB], SN) :- svs,
764 atom_string(A, SA),
765 atom_string(B, SB),
766 string_concat([SA,` and `,SB], SN).
767svs([A=_V|L], SN) :-
768 atom_string(A, S),
769 svs(L, S1 ),
770 string_concat([S, `, `, S1], SN).
771
772list_of_preds([]) --> [].
773list_of_preds([P|L]) -->
774 ['~q' - [P]],
775 list_of_preds(L).
776
777syntax_error_term(between(_I,J,_L),[S|T],_LC) -->
778 {string(S)},
779 !,
780 [ '~s' - [S] ],
781 [' <<<< at line ~d >>>> ~s' - [J,T], ].
782syntax_error_term(between(_I,J,_L),LTaL,LC) -->
783 syntax_error_tokens(LTaL, J, LC).
784
785syntax_error_tokens([], _, _LC) --> [].
786syntax_error_tokens([T|L], J, LC) -->
787 syntax_error_token(T, J, LC),
788 syntax_error_tokens(L, J, LC).
789
790syntax_error_token(atom(A), _, _LC) --> syntax_error_token,
791 [ '~q' - [A] ].
792syntax_error_token(number(N), _, _LC) --> syntax_error_token,
793 [ '~w' - [N] ].
794syntax_error_token(var(_,S), _, _LC) --> syntax_error_token,
795 [ '~a' - [S] ].
796syntax_error_token(string(S), _, _LC) --> syntax_error_token,
797 [ '`~s`' - [S] ].
798syntax_error_token(error, L, _LC) --> syntax_error_token,
799 [ ' <<<< at line ~d >>>> ' - [L] ].
800syntax_error_token('EOT',_, _LC) --> syntax_error_token,
801 [ '.' - [], nl ].
802syntax_error_token('(',_, _LC) --> syntax_error_token,
803 [ '( '- [] ].
804syntax_error_token('{',_, _LC) --> syntax_error_token,
805 [ '{ '- [] ].
806syntax_error_token('[', _, _LC) --> syntax_error_token,
807 [ '[' - [] ].
808syntax_error_token(')',_, _LC) --> syntax_error_token,
809 [ ' )'- [] ].
810syntax_error_token(']',_, _LC) --> syntax_error_token,
811 [ ']'- [] ].
812syntax_error_token('}',_, _LC) --> syntax_error_token,
813 [ ' }' - [] ].
814syntax_error_token(',',_, _LC) --> syntax_error_token,
815 [ ', ' - [] ].
816syntax_error_token('.',_, _LC) --> syntax_error_token,
817 [ '.' - [] ].
818syntax_error_token(';', _, _LC) --> syntax_error_token,
819 [ '; ' - [] ].
820syntax_error_token(':', _, _LC) --> syntax_error_token,
821 [ ':' - [] ].
822syntax_error_token('|', _, _LC) --> syntax_error_token,
823 [ '|' - [] ].
824syntax_error_token('l',_, _LC) --> syntax_error_token,
825 [ '|' - [] ].
826syntax_error_token(nl, _, LC) --> syntax_error_token,
827 [ '~*| ' -[LC], nl ].
828syntax_error_token(B,_, _LC) --> syntax_error_token,
829 [ nl, 'bad_token: ~q' - [B], nl ].
830%%%%%%%%%%%%%%%%%%%%
831
832 -->
833 { current_prolog_flag(break_level, BL ), BL > 0 },
834 !
835 ->
836 ['[~p] ' -[BL]].
837write_break_level -->
838 [].
839
840write_query_answer( [], [] , [], _ ) -->
841 write_query_answer,
842 [flush],
843 ,
844 [yes-[]].
845write_query_answer(_, Vs0, GVs0, Extras ) -->
846 [flush],
847 ,
848 {
849 copy_term_nat(Vs0+GVs0, Vs+Gs),
850 name_vars(Vs, Gs, VGs, []),
851 '$singleton_vs_numbervars'(VGs,0,_)
852 },
853 vars(VGs, Extras).
854
855name_vars([A='$VAR'(A)|Vs], Gs) -->
856 name_vars,
857 name_vars(Vs, Gs).
858name_vars([_A='$VAR'(-1)|Vs], Gs) -->
859 name_vars,
860 name_vars(Vs, Gs).
861name_vars([A='$VAR'(B)|Vs], Gs) -->
862 [var(A,'$VAR'(B))],
863 !,
864 name_vars(Vs, Gs).
865name_vars([A=V|Vs], Gs) -->
866[nonvar(A,V)],
867 !,
868 name_vars(Vs, Gs).
869name_vars([], [G|Gs]) -->
870 [goal(G)],
871 !,
872 name_vars([], Gs).
873name_vars([],[]) --> [].
874
875vars( [var(A,B)|VGs], Extra) -->
876 ['~a = '-[A],'~q'-[B]],
877 ,
878 extra_vars(VGs, Extra).
879vars([nonvar(A,V)|VGs], Extra) -->
880 ['~a = '-[A],'~W'-[V,[priority(699)|Opts]]],
881 !,
882 {
883 yap_flag(toplevel_print_options, Opts)
884 },
885 extra_vars(VGs, Extra).
886vars( [goal(G)|Gs], Extra) -->
887 vars,
888 {
889 yap_flag(toplevel_print_options, Opts)
890 },
891 ['~W'-[G,[priority(699)|Opts]]],
892 extra_vars(Gs, Extra).
893vars([],_Extra) --> [].
894
895extra_vars([], Extra) -->
896 extra_vars,
897 [Extra-[], flush].
898extra_vars( VGs, Extra) -->
899 [','-[],nl],
900 vars( VGs, Extra).
901
902write_goal_output(var([V|VL]), First, next) -->
903 add_nl(First),
904 ['~a'-V],
905 write_output_vars(VL).
906write_goal_output(nonvar([V|VL],B), First, next) -->
907 write_goal_output,
908 add_nl(First),
909 ['~a'-V],
910 write_output_vars(VL),
911 [ ' = ' - []],
912 write_goal_g(B).
913write_goal_output(nl, First, First) -->
914 write_goal_output,
915 ['~N'-[]].
916write_goal_output(Format-G, First, Next) -->
917 write_goal_output,
918 G = [_|_], ,
919 % dump on string first so that we can check whether we actually
920 % had any output from the solver.
921 { format(codes(String),Format,G) },
922 ( {String == [] }->
923 % we didn't
924 { First = Next }
925 ;
926 % we did
927 add_nl(First),
928 [ '~s' - [String]],
929 { Next = next }
930 ).
931write_goal_output(_-G, First, next) -->
932 write_goal_output,
933 write_goal_output(G, First, next).
934write_goal_output(MG, First, next) -->
935 add_nl(First),
936 {
937 strip_module(MG,M,G0),
938 ( current_module(M) -> G=G0; G=M:G0)
939 },
940 write_goal_g(G).
941
942
943name_vars_in_goals(G, VL0, G) :-
944 name_well_known_vars(VL0),
945 variables_in_term(G, [], GVL),
946 name_vars_in_goals1(GVL, 0, _).
947
948name_well_known_vars([]).
949name_well_known_vars([Name=V|NVL0]) :-
950 var(V), var,
951 V = '$VAR'(Name),
952 name_well_known_vars(NVL0).
953name_well_known_vars([_|NVL0]) :-
954 name_well_known_vars(NVL0).
955
956name_vars_in_goals1([], I, I).
957name_vars_in_goals1([V|NGVL], I0, IF) :-
958 I is I0+1,
959 gen_name_string(I0,[],SName), gen_name_string,
960 atom_codes(Name, [95|SName]),
961 V = '$VAR'(Name),
962 name_vars_in_goals1(NGVL, I, IF).
963name_vars_in_goals1([NV|NGVL], I0, IF) :-
964 nonvar(NV),
965 name_vars_in_goals1(NGVL, I0, IF).
966
967%%%%%%%%%%%%%%%%%%%%%%
968print_lines( S, A, Key) -->
969 [Tok],
970 ,
971 print_lines_(Tok, S, A, Key).
972print_lines( _S, _A, _Key) -->
973 [].
974
975print_lines_( at_same_line, S, Prefix_, Key) -->
976 print_lines_,
977 print_lines( S, Prefix_, Key).
978print_lines_(begin(Severity, OtherKey), S, Prefix_es, Key) -->
979 print_lines_,
980 { prefix_( Severity, P ) },
981 print_message_lines(S, [P], OtherKey),
982 print_lines( S, Prefix_es, Key ).
983print_lines_( flush, S, _, Key) -->
984 [ end(Key0)],
985 { Key == Key0 },
986 !,
987 { flush_output(S) }.
988print_lines_( end(Key0), S, _, Key) -->
989 { Key0 == Key },
990 ,
991 { nl(S) }.
992print_lines_( end(_OtherKey), S, Prefix_es, Key) -->
993 print_lines_,
994 print_lines( S, Prefix_es, Key ).
995print_lines_(flush, S, Prefix_es, Key) -->
996 print_lines_,
997 { flush_output(S) },
998 print_lines( S, Prefix_es, Key ).
999print_lines_(format(Fmt,Args), S, Prefix_es, Key) -->
1000 print_lines_,
1001 { format(S, Fmt, Args) },
1002 print_lines( S, Prefix_es, Key ).
1003print_lines_( nl, S, _, Key) -->
1004 [ end(Key0)],
1005 { Key == Key0 },
1006 !,
1007 { nl(S),
1008 flush_output(S) }.
1009print_lines_(nl, S, Prefix_es, Key) -->
1010 print_lines_,
1011 { nl(S),
1012 Prefix_es = [Prefix_S - Cmds|More],
1013 format(S, Prefix_S, Cmds)
1014 },
1015 {
1016 More == []
1017 ->
1018 NPrefix_es = Prefix_es
1019 ;
1020 NPrefix_es = More
1021 },
1022 print_lines( S, NPrefix_es, Key).
1023% consider this a message within the message
1024print_lines_(prefix_(Fmt-Args), S, Prefix_es, Key) -->
1025 print_lines_,
1026 print_lines( S, [Fmt-Args|Prefix_es], Key ).
1027print_lines_(prefix_(Fmt), S, Prefix_es, Key) -->
1028 { atom( Fmt ) ; string( Fmt ) },
1029 !,
1030 print_lines( S, [Fmt-[]|Prefix_es], Key ).
1031print_lines_(Fmt-Args, S, Prefix_es, Key) -->
1032 print_lines_,
1033 { format(S, Fmt, Args) },
1034 print_lines( S, Prefix_es, Key ).
1035% deprecated....
1036print_lines_(Fmt, S, Prefix_es, Key) -->
1037 { atom(Fmt) ; string( Fmt ) },
1038 !,
1039 { format(S, Fmt, []) },
1040 print_lines(S, Prefix_es, Key).
1041print_lines_(Msg, S, _Prefix_es, _Key) -->
1042 { format(S, 'Illegal message Component: ~q !!!.~n', [Msg]) }.
1043
1044prefix_(help, '~N'-[]).
1045prefix_(query, '~N'-[]).
1046prefix_(debug, '~N'-[]).
1047prefix_(warning, '~N'-[]).
1048prefix_(error, '~N'-[]).
1049prefix_(banner, '~N'-[]).
1050prefix_(informational, '~N~*|% '-[LC]) :-
1051 '$show_consult_level'(LC),
1052 LC > 0,
1053 '$show_consult_level'.
1054prefix_(informational, '~N'-[]).
1055prefix_(debug(_), '~N'-[]).
1056
1057/* { thread_self(Id) },
1058 ( { Id == main }
1059 -> [ 'warning, ' - [] ]
1060 ; { atom(Id) }
1061 -> ['warning [Thread ~a ], ' - [Id] ]
1062 ; ['warning [Thread ~d ], ' - [Id] ]
1063 ).
1064*/
1065
1066/*
1067 { thread_self(Id) },
1068 ( { Id == main }
1069 -> [ 'error ' ]
1070 ; { thread_main_name(Id) }
1071 -> [ 'error [ Thread ~w ] ' - [Id] ]
1072 ),
1073 !.
1074prefix_(error, '', user_error) -->
1075 { thread_self(Id) },
1076 ( { Id == main }
1077 -> [ 'error ' - [], nl ]
1078 ; { atom(Id) }
1079 -> [ 'error [ Thread ~a ] ' - [Id], nl ]
1080 ; [ 'error [ Thread ~d ] ' - [Id], nl ]
1081 ).
1082*/
1083
1084
1085
1086clause_to_indicator(T, MNameArity) :-
1087 strip_module(T, M0, T1),
1088 pred_arity( T1, M0, MNameArity ).
1089
1090call/1pred_arity(V, M, M:) :- var(V), var.
1091pred_arity((:- _Path), _M, prolog:(:-)/1 ) :- pred_arity.
1092pred_arity((?- _Path), _M, prolog:(?)/1 ) :- pred_arity.
1093pred_arity((H:-_),M, MNameArity) :-
1094 nonvar(H),
1095 nonvar,
1096 strip_module(M:H, M1, H1),
1097 pred_arity( H1, M1, MNameArity).
1098pred_arity((H-->_), M, M2:Name//Arity) :-
1099 nonvar(H),
1100 nonvar,
1101 strip_module(M:H, M1, H1),
1102 pred_arity( H1, M1, M2:Name/Arity).
1103% special for a, [x] --> b, [y].
1104pred_arity((H,_), M, MNameArity) :-
1105 nonvar(H),
1106 nonvar,
1107 strip_module(M:H, M1, H1),
1108 pred_arity( H1, M1, MNameArity).
1109pred_arity(Name/Arity, M, M:Name/Arity) :-
1110 pred_arity.
1111pred_arity(Name//Arity, M, M:Name//Arity) :-
1112 pred_arity.
1113pred_arity(H,M, M:Name/Arity) :-
1114 functor(H,Name,Arity).
1115
1116
1117% print_message_lines(+Stream, +Prefix_, +Lines)
1118%
1119% Quintus/SICStus/SWI compatibility predicate to print message lines
1120% using a prefix_.
1121
1122/** @pred print_message_lines(+ _Stream_, + _Prefix__, + _Lines_)
1123
1124Print a message (see print_message/2) that has been translated to
1125a list of message elements. The elements of this list are:
1126
1127+ _Format_-_Args_
1128Where _Format_ is an atom and _Args_ is a list
1129of format argument. Handed to `format/3`.
1130+ `flush`
1131If this appears as the last element, _stream_ is flushed
1132(see `flush_output/1`) and no final newline is generated.
1133+ `at_same_line`
1134If this appears as first element, no prefix_ is printed for
1135the line and the line-position is not forced to 0
1136(see `format/1`, `~N`).
1137+ `prefix_`(Prefix_)
1138define a prefix_ for the next line, say `''` will be seen as an
1139empty prefix_.
1140(see `format/1`, `~N`)+ `<Format>`
1141Handed to `format/3` as `format(Stream, Format, [])`, may get confused
1142with other commands.
1143+ nl
1144A new line is started and if the message is not complete
1145the _Prefix__ is printed too.
1146*/
1147functor:print_message_lines(S, Prefix_0, Lines) :-
1148 Lines = [begin(_, Key)|Msg],
1149 (
1150 atom(Prefix_0)
1151 ->
1152 Prefix_ = Prefix_0-[]
1153 ;
1154 string(Prefix_0)
1155 ->
1156 Prefix_ = Prefix_0-[]
1157 ;
1158 Prefix_ = Prefix_0
1159 ),
1160 (Msg = [at_same_line|Msg1]
1161 ->
1162 print_lines(S, [Prefix_], Key, Msg1, [])
1163 ;
1164 print_lines(S, [Prefix_], Key, [Prefix_|Msg], [])
1165 ).
1166
1167
1168
1169/** @pred prolog:print_message(+ Severity, +Term)
1170
1171The predicate print_message/2 is used to print messages, notably from
1172exceptions, in a human-readable format. _Kind_ is one of
1173`informational`, `banner`, `warning`, `error`, `help` or `silent`. In YAP, the message is always outut to the stream user_error.
1174
1175If the Prolog flag verbose is `silent`, messages with
1176 _Kind_ `informational`, or `banner` are treated as
1177 silent. See `-q` in [Running_YAP_Interactively].
1178
11794This predicate first translates the _Term_ into a list of `message
1180lines` (see print_message_lines/3 for details). Next it will
1181call the hook message_hook/3 to allow the user intercepting the
1182message. If message_hook/3 fails it will print the message unless
1183 _Kind_ is silent.
1184
1185If you need to report errors from your own predicates, we advise you to
1186
1187stick to the existing error terms if you can; but should you need to
1188invent new ones, you can define corresponding error messages by
1189asserting clauses for `prolog:message/2`. You will need to declare
1190the predicate as multifile/1.
1191
1192Note: errors in the implementation of print_message/2 are very
1193confusing to YAP (who will process the error?). So we write this small
1194stub to ensure everything os ok
1195
1196*/
1197
1198:- set_prolog_flag( redefine_warnings, false ).
1199
1200
1201%:- dynamic in/0.
1202set_prolog_flag
1203
1204:- set_prolog_flag( redefine_warnings, false ).
1205
1206set_prolog_flag:yap_error_descriptor(A,B) :-
1207 error_descriptor(A,B).
1208
1209error_descriptor( V, [] ) :-
1210 must_be_bound(V),
1211 must_be_bound.
1212error_descriptor( exception(Info), List ) :-
1213 error_descriptor,
1214 '$read_exception'(Info,List).
1215error_descriptor( (Info), Info ).
1216
1217
1218query_exception(K0,[H|L],V) :-
1219 (atom(K0) -> K=K0 ; atom_to_string(K, K0) ),
1220 !,
1221 lists:member(K0=V,[H|L]).
1222query_exception(M,K,V) :-
1223 '$query_exception'(M,K,V).
1224
1225:- set_prolog_flag(redefine_warnings,false).
1226:- set_prolog_flag(discontiguous_warnings,false).
1227
1228set_prolog_flag:print_message(Severity, Msg) :-
1229 (
1230 var(Severity)
1231 ->
1232 var,
1233 format(user_error, 'malformed message ~q: message level is unbound~n', [Msg])
1234 ;
1235 var(Msg)
1236 ->
1237 var,
1238 format(user_error, 'uninstantiated message~n', [])
1239 ;
1240 Severity == format
1241 ),
1242 !.
1243prolog:print_message(Level, _Msg) :-
1244 prolog_flag(compiling, true),
1245 prolog_flag(verbose_load, false),
1246 Level \= prolog_flag,
1247 Level \= prolog_flag,
1248 prolog_flag.
1249prolog_flag:print_message(Level, _Msg) :-
1250 prolog_flag(verbose, silent),
1251 Level \= prolog_flag,
1252 Level \= prolog_flag,
1253 prolog_flag.
1254prolog_flag:print_message(Severity, Msg) :-
1255 print_message:portray_message(Severity, Msg),
1256 portray_message.
1257portray_message:print_message(_, _Msg) :-
1258 % first step at hook processing
1259 '__NB_getval__'('$if_skip_mode',skip,fail),
1260 '__NB_getval__'.
1261'__NB_getval__':print_message(force(_Severity), Msg) :- print_message,
1262 print(user_error,Msg).
1263% This predicate has more hooks than a pirate ship!
1264print:print_message(Severity, Term) :-
1265 '$pred_exists'(message( Term,Lines0, [ end(Id)]),'$messages'),
1266 message( Term,Lines0, [ end(Id)]),
1267 Lines = [begin(Severity, Id)| Lines0],
1268 (
1269 :message_hook(Term, Severity, Lines)
1270 ->
1271 message_hook
1272 ;
1273 ignore((prefix_( Severity, Prefix_ ),
1274 print_message_lines(user_error, Prefix_, Lines)))
1275 ),
1276 !.
1277prolog:print_message(Severity, Term) :-
1278 translate_message( Term, Lines0, [ end(Id)]),
1279 Lines = [begin(Severity, Id)| Lines0],
1280 ignore(
1281 user:message_hook(Term, Severity, Lines)
1282 ),
1283 ignore(
1284 (
1285 prefix_( Severity, Prefix_ ),
1286 print_message_lines(user_error, Prefix_, Lines)
1287 )
1288 ),
1289 ignore.
1290ignore:print_message(_Severity, _Term) :-
1291 format(user_error,'failed to print ~w: ~w~n' ,[ _Severity, _Term]).
1292
1293
1294/**
1295 @}
1296*/
1297
1298
1299
1300
must_be_bound( ?_T_ )
throw(+ Ball)
yap_flag( ?Param, ?Value)
flush_output(+Stream)
nl(+ S)
current_module( ? Mod:atom)
atom_codes(?Atom, ?Codes)
sub_atom(+ A,? Bef, ? Size, ? After, ? At_out)
copy_term_nat(? TI,- TF)
print(+ S, T)
call( 0:P )
ignore(: Goal)
message_hook(+ Term, + Kind, + Lines)
current_prolog_flag(? Flag,- Value)
set_prolog_flag(+ Flag,+ Value)
message_to_string(+ Term, - String)
print_message(+ Severity, +Term)
print_message_lines(+ Stream, + Prefix__, + _Lines)
Definition: messages.yap:832
translate_message(+Term, +Lines, -Lines0)
variables_in_term( +_t, +_SetOfVariables_, +_ExtendedSetOfVariables_ )
atom( T)
functor( T, F, N)
integer( T)
nonvar( T)
var( T)
?_X_ == ?_Y_
member(?Element, ?Set) is true when Set is a list, and Element occurs in it