-
-
Notifications
You must be signed in to change notification settings - Fork 178
/
Copy pathmessages.pl
2458 lines (2215 loc) · 76.2 KB
/
messages.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Part of SWI-Prolog
Author: Jan Wielemaker
E-mail: J.Wielemaker@vu.nl
WWW: http://www.swi-prolog.org
Copyright (c) 1997-2025, University of Amsterdam
VU University Amsterdam
CWI, Amsterdam
SWI-Prolog Solutions b.v.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
:- module('$messages',
[ print_message/2, % +Kind, +Term
print_message_lines/3, % +Stream, +Prefix, +Lines
message_to_string/2 % +Term, -String
]).
:- multifile
prolog:message//1, % entire message
prolog:error_message//1, % 1-st argument of error term
prolog:message_context//1, % Context of error messages
prolog:deprecated//1, % Deprecated features
prolog:message_location//1, % (File) location of error messages
prolog:message_line_element/2. % Extend printing
:- '$hide'((
prolog:message//1,
prolog:error_message//1,
prolog:message_context//1,
prolog:deprecated//1,
prolog:message_location//1,
prolog:message_line_element/2)).
% Lang, Term versions
:- multifile
prolog:message//2, % entire message
prolog:error_message//2, % 1-st argument of error term
prolog:message_context//2, % Context of error messages
prolog:message_location//2, % (File) location of error messages
prolog:deprecated//2. % Deprecated features
:- '$hide'((
prolog:message//2,
prolog:error_message//2,
prolog:message_context//2,
prolog:deprecated//2,
prolog:message_location//2)).
:- discontiguous
prolog_message/3.
:- public
translate_message//1, % +Message (deprecated)
prolog:translate_message//1. % +Message
:- create_prolog_flag(message_context, [thread], []).
%! translate_message(+Term)// is det.
%
% Translate a message Term into message lines. The produced lines
% is a list of
%
% - nl
% Emit a newline
% - Fmt-Args
% Emit the result of format(Fmt, Args)
% - Fmt
% Emit the result of format(Fmt)
% - ansi(Code, Fmt, Args)
% Use ansi_format/3 for color output.
% - flush
% Used only as last element of the list. Simply flush the
% output instead of producing a final newline.
% - at_same_line
% Start the messages at the same line (instead of using ~N)
%
% @deprecated Use code for message translation should call
% prolog:translate_message//1.
prolog:translate_message(Term) -->
translate_message(Term).
%! translate_message(+Term)// is det.
%
% Translate a message term into message lines. This version may be
% called from user and library definitions for message translation.
translate_message(Term) -->
{ nonvar(Term) },
( { message_lang(Lang) },
prolog:message(Lang, Term)
; prolog:message(Term)
),
!.
translate_message(Term) -->
{ nonvar(Term) },
translate_message2(Term),
!.
translate_message(Term) -->
{ nonvar(Term),
Term = error(_, _)
},
[ 'Unknown exception: ~p'-[Term] ].
translate_message(Term) -->
[ 'Unknown message: ~p'-[Term] ].
translate_message2(Term) -->
prolog_message(Term).
translate_message2(error(resource_error(stack), Context)) -->
!,
out_of_stack(Context).
translate_message2(error(resource_error(tripwire(Wire, Context)), _)) -->
!,
tripwire_message(Wire, Context).
translate_message2(error(existence_error(reset, Ball), SWI)) -->
swi_location(SWI),
tabling_existence_error(Ball, SWI).
translate_message2(error(ISO, SWI)) -->
swi_location(SWI),
term_message(ISO),
swi_extra(SWI).
translate_message2(unwind(Term)) -->
unwind_message(Term).
translate_message2(message_lines(Lines), L, T) :- % deal with old C-warning()
make_message_lines(Lines, L, T).
translate_message2(format(Fmt, Args)) -->
[ Fmt-Args ].
make_message_lines([], T, T) :- !.
make_message_lines([Last], ['~w'-[Last]|T], T) :- !.
make_message_lines([L0|LT], ['~w'-[L0],nl|T0], T) :-
make_message_lines(LT, T0, T).
%! term_message(+Term)//
%
% Deal with the formal argument of error(Format, ImplDefined)
% exception terms. The `ImplDefined` argument is handled by
% swi_location//2.
:- public term_message//1.
term_message(Term) -->
{var(Term)},
!,
[ 'Unknown error term: ~p'-[Term] ].
term_message(Term) -->
{ message_lang(Lang) },
prolog:error_message(Lang, Term),
!.
term_message(Term) -->
prolog:error_message(Term),
!.
term_message(Term) -->
iso_message(Term).
term_message(Term) -->
swi_message(Term).
term_message(Term) -->
[ 'Unknown error term: ~p'-[Term] ].
iso_message(resource_error(c_stack)) -->
out_of_c_stack.
iso_message(resource_error(Missing)) -->
[ 'Not enough resources: ~w'-[Missing] ].
iso_message(type_error(evaluable, Actual)) -->
{ callable(Actual) },
[ 'Arithmetic: `~p'' is not a function'-[Actual] ].
iso_message(type_error(free_of_attvar, Actual)) -->
[ 'Type error: `~W'' contains attributed variables'-
[Actual,[portray(true), attributes(portray)]] ].
iso_message(type_error(Expected, Actual)) -->
[ 'Type error: `~w'' expected, found `~p'''-[Expected, Actual] ],
type_error_comment(Expected, Actual).
iso_message(domain_error(Domain, Actual)) -->
[ 'Domain error: '-[] ], domain(Domain),
[ ' expected, found `~p'''-[Actual] ].
iso_message(instantiation_error) -->
[ 'Arguments are not sufficiently instantiated' ].
iso_message(uninstantiation_error(Var)) -->
[ 'Uninstantiated argument expected, found ~p'-[Var] ].
iso_message(representation_error(What)) -->
[ 'Cannot represent due to `~w'''-[What] ].
iso_message(permission_error(Action, Type, Object)) -->
permission_error(Action, Type, Object).
iso_message(evaluation_error(Which)) -->
[ 'Arithmetic: evaluation error: `~p'''-[Which] ].
iso_message(existence_error(procedure, Proc)) -->
[ 'Unknown procedure: ~q'-[Proc] ],
unknown_proc_msg(Proc).
iso_message(existence_error(answer_variable, Var)) -->
[ '$~w was not bound by a previous query'-[Var] ].
iso_message(existence_error(matching_rule, Goal)) -->
[ 'No rule matches ~p'-[Goal] ].
iso_message(existence_error(Type, Object)) -->
[ '~w `~p'' does not exist'-[Type, Object] ].
iso_message(existence_error(export, PI, module(M))) --> % not ISO
[ 'Module ', ansi(code, '~q', [M]), ' does not export ',
ansi(code, '~q', [PI]) ].
iso_message(existence_error(Type, Object, In)) --> % not ISO
[ '~w `~p'' does not exist in ~p'-[Type, Object, In] ].
iso_message(busy(Type, Object)) -->
[ '~w `~p'' is busy'-[Type, Object] ].
iso_message(syntax_error(swi_backslash_newline)) -->
[ 'Deprecated ... \\<newline><white>*. Use \\c' ].
iso_message(syntax_error(Id)) -->
[ 'Syntax error: ' ],
syntax_error(Id).
iso_message(occurs_check(Var, In)) -->
[ 'Cannot unify ~p with ~p: would create an infinite tree'-[Var, In] ].
%! permission_error(Action, Type, Object)//
%
% Translate permission errors. Most follow te pattern "No
% permission to Action Type Object", but some are a bit different.
permission_error(Action, built_in_procedure, Pred) -->
{ user_predicate_indicator(Pred, PI)
},
[ 'No permission to ~w built-in predicate `~p'''-[Action, PI] ],
( {Action \== export}
-> [ nl,
'Use :- redefine_system_predicate(+Head) if redefinition is intended'
]
; []
).
permission_error(import_into(Dest), procedure, Pred) -->
[ 'No permission to import ~p into ~w'-[Pred, Dest] ].
permission_error(Action, static_procedure, Proc) -->
[ 'No permission to ~w static procedure `~p'''-[Action, Proc] ],
defined_definition('Defined', Proc).
permission_error(input, stream, Stream) -->
[ 'No permission to read from output stream `~p'''-[Stream] ].
permission_error(output, stream, Stream) -->
[ 'No permission to write to input stream `~p'''-[Stream] ].
permission_error(input, text_stream, Stream) -->
[ 'No permission to read bytes from TEXT stream `~p'''-[Stream] ].
permission_error(output, text_stream, Stream) -->
[ 'No permission to write bytes to TEXT stream `~p'''-[Stream] ].
permission_error(input, binary_stream, Stream) -->
[ 'No permission to read characters from binary stream `~p'''-[Stream] ].
permission_error(output, binary_stream, Stream) -->
[ 'No permission to write characters to binary stream `~p'''-[Stream] ].
permission_error(open, source_sink, alias(Alias)) -->
[ 'No permission to reuse alias "~p": already taken'-[Alias] ].
permission_error(tnot, non_tabled_procedure, Pred) -->
[ 'The argument of tnot/1 is not tabled: ~p'-[Pred] ].
permission_error(assert, procedure, Pred) -->
{ '$pi_head'(Pred, Head),
predicate_property(Head, ssu)
},
[ '~p: an SSU (Head => Body) predicate cannot have normal Prolog clauses'-
[Pred] ].
permission_error(Action, Type, Object) -->
[ 'No permission to ~w ~w `~p'''-[Action, Type, Object] ].
unknown_proc_msg(_:(^)/2) -->
!,
unknown_proc_msg((^)/2).
unknown_proc_msg((^)/2) -->
!,
[nl, ' ^/2 can only appear as the 2nd argument of setof/3 and bagof/3'].
unknown_proc_msg((:-)/2) -->
!,
[nl, ' Rules must be loaded from a file'],
faq('ToplevelMode').
unknown_proc_msg((=>)/2) -->
!,
[nl, ' Rules must be loaded from a file'],
faq('ToplevelMode').
unknown_proc_msg((:-)/1) -->
!,
[nl, ' Directives must be loaded from a file'],
faq('ToplevelMode').
unknown_proc_msg((?-)/1) -->
!,
[nl, ' ?- is the Prolog prompt'],
faq('ToplevelMode').
unknown_proc_msg(Proc) -->
{ dwim_predicates(Proc, Dwims) },
( {Dwims \== []}
-> [nl, ' However, there are definitions for:', nl],
dwim_message(Dwims)
; []
).
dependency_error(shared(Shared), private(Private)) -->
[ 'Shared table for ~p may not depend on private ~p'-[Shared, Private] ].
dependency_error(Dep, monotonic(On)) -->
{ '$pi_head'(PI, Dep),
'$pi_head'(MPI, On)
},
[ 'Dependent ~p on monotonic predicate ~p is not monotonic or incremental'-
[PI, MPI]
].
faq(Page) -->
[nl, ' See FAQ at https://www.swi-prolog.org/FAQ/', Page, '.html' ].
type_error_comment(_Expected, Actual) -->
{ type_of(Actual, Type),
( sub_atom(Type, 0, 1, _, First),
memberchk(First, [a,e,i,o,u])
-> Article = an
; Article = a
)
},
[ ' (~w ~w)'-[Article, Type] ].
type_of(Term, Type) :-
( attvar(Term) -> Type = attvar
; var(Term) -> Type = var
; atom(Term) -> Type = atom
; integer(Term) -> Type = integer
; string(Term) -> Type = string
; Term == [] -> Type = empty_list
; blob(Term, BlobT) -> blob_type(BlobT, Type)
; rational(Term) -> Type = rational
; float(Term) -> Type = float
; is_stream(Term) -> Type = stream
; is_dict(Term) -> Type = dict
; is_list(Term) -> Type = list
; cyclic_term(Term) -> Type = cyclic
; compound(Term) -> Type = compound
; Type = unknown
).
blob_type(BlobT, Type) :-
atom_concat(BlobT, '_reference', Type).
syntax_error(end_of_clause) -->
[ 'Unexpected end of clause' ].
syntax_error(end_of_clause_expected) -->
[ 'End of clause expected' ].
syntax_error(end_of_file) -->
[ 'Unexpected end of file' ].
syntax_error(end_of_file_in_block_comment) -->
[ 'End of file in /* ... */ comment' ].
syntax_error(end_of_file_in_quoted(Quote)) -->
[ 'End of file in quoted ' ],
quoted_type(Quote).
syntax_error(illegal_number) -->
[ 'Illegal number' ].
syntax_error(long_atom) -->
[ 'Atom too long (see style_check/1)' ].
syntax_error(long_string) -->
[ 'String too long (see style_check/1)' ].
syntax_error(operator_clash) -->
[ 'Operator priority clash' ].
syntax_error(operator_expected) -->
[ 'Operator expected' ].
syntax_error(operator_balance) -->
[ 'Unbalanced operator' ].
syntax_error(quoted_punctuation) -->
[ 'Operand expected, unquoted comma or bar found' ].
syntax_error(list_rest) -->
[ 'Unexpected comma or bar in rest of list' ].
syntax_error(cannot_start_term) -->
[ 'Illegal start of term' ].
syntax_error(punct(Punct, End)) -->
[ 'Unexpected `~w\' before `~w\''-[Punct, End] ].
syntax_error(undefined_char_escape(C)) -->
[ 'Unknown character escape in quoted atom or string: `\\~w\''-[C] ].
syntax_error(void_not_allowed) -->
[ 'Empty argument list "()"' ].
syntax_error(Term) -->
{ compound(Term),
compound_name_arguments(Term, Syntax, [Text])
}, !,
[ '~w expected, found '-[Syntax], ansi(code, '"~w"', [Text]) ].
syntax_error(Message) -->
[ '~w'-[Message] ].
quoted_type('\'') --> [atom].
quoted_type('\"') --> { current_prolog_flag(double_quotes, Type) }, [Type-[]].
quoted_type('\`') --> { current_prolog_flag(back_quotes, Type) }, [Type-[]].
domain(range(Low,High)) -->
!,
['[~q..~q]'-[Low,High] ].
domain(Domain) -->
['`~w\''-[Domain] ].
%! tabling_existence_error(+Ball, +Context)//
%
% Called on invalid shift/1 calls. Track those that result from
% tabling errors.
tabling_existence_error(Ball, Context) -->
{ table_shift_ball(Ball) },
[ 'Tabling dependency error' ],
swi_extra(Context).
table_shift_ball(dependency(_Head)).
table_shift_ball(dependency(_Skeleton, _Trie, _Mono)).
table_shift_ball(call_info(_Skeleton, _Status)).
table_shift_ball(call_info(_GenSkeleton, _Skeleton, _Status)).
%! dwim_predicates(+PI, -Dwims)
%
% Find related predicate indicators.
dwim_predicates(Module:Name/_Arity, Dwims) :-
!,
findall(Dwim, dwim_predicate(Module:Name, Dwim), Dwims).
dwim_predicates(Name/_Arity, Dwims) :-
findall(Dwim, dwim_predicate(user:Name, Dwim), Dwims).
dwim_message([]) --> [].
dwim_message([M:Head|T]) -->
{ hidden_module(M),
!,
functor(Head, Name, Arity)
},
[ ' ~q'-[Name/Arity], nl ],
dwim_message(T).
dwim_message([Module:Head|T]) -->
!,
{ functor(Head, Name, Arity)
},
[ ' ~q'-[Module:Name/Arity], nl],
dwim_message(T).
dwim_message([Head|T]) -->
{functor(Head, Name, Arity)},
[ ' ~q'-[Name/Arity], nl],
dwim_message(T).
swi_message(io_error(Op, Stream)) -->
[ 'I/O error in ~w on stream ~p'-[Op, Stream] ].
swi_message(thread_error(TID, false)) -->
[ 'Thread ~p died due to failure:'-[TID] ].
swi_message(thread_error(TID, exception(Error))) -->
[ 'Thread ~p died abnormally:'-[TID], nl ],
translate_message(Error).
swi_message(dependency_error(Tabled, DependsOn)) -->
dependency_error(Tabled, DependsOn).
swi_message(shell(execute, Cmd)) -->
[ 'Could not execute `~w'''-[Cmd] ].
swi_message(shell(signal(Sig), Cmd)) -->
[ 'Caught signal ~d on `~w'''-[Sig, Cmd] ].
swi_message(format(Fmt, Args)) -->
[ Fmt-Args ].
swi_message(signal(Name, Num)) -->
[ 'Caught signal ~d (~w)'-[Num, Name] ].
swi_message(limit_exceeded(Limit, MaxVal)) -->
[ 'Exceeded ~w limit (~w)'-[Limit, MaxVal] ].
swi_message(goal_failed(Goal)) -->
[ 'goal unexpectedly failed: ~p'-[Goal] ].
swi_message(shared_object(_Action, Message)) --> % Message = dlerror()
[ '~w'-[Message] ].
swi_message(system_error(Error)) -->
[ 'error in system call: ~w'-[Error]
].
swi_message(system_error) -->
[ 'error in system call'
].
swi_message(failure_error(Goal)) -->
[ 'Goal failed: ~p'-[Goal] ].
swi_message(timeout_error(Op, Stream)) -->
[ 'Timeout in ~w from ~p'-[Op, Stream] ].
swi_message(not_implemented(Type, What)) -->
[ '~w `~p\' is not implemented in this version'-[Type, What] ].
swi_message(context_error(nodirective, Goal)) -->
{ goal_to_predicate_indicator(Goal, PI) },
[ 'Wrong context: ~p can only be used in a directive'-[PI] ].
swi_message(context_error(edit, no_default_file)) -->
( { current_prolog_flag(windows, true) }
-> [ 'Edit/0 can only be used after opening a \c
Prolog file by double-clicking it' ]
; [ 'Edit/0 can only be used with the "-s file" commandline option'
]
),
[ nl, 'Use "?- edit(Topic)." or "?- emacs."' ].
swi_message(context_error(function, meta_arg(S))) -->
[ 'Functions are not (yet) supported for meta-arguments of type ~q'-[S] ].
swi_message(format_argument_type(Fmt, Arg)) -->
[ 'Illegal argument to format sequence ~~~w: ~p'-[Fmt, Arg] ].
swi_message(format(Msg)) -->
[ 'Format error: ~w'-[Msg] ].
swi_message(conditional_compilation_error(unterminated, File:Line)) -->
[ 'Unterminated conditional compilation from '-[], url(File:Line) ].
swi_message(conditional_compilation_error(no_if, What)) -->
[ ':- ~w without :- if'-[What] ].
swi_message(duplicate_key(Key)) -->
[ 'Duplicate key: ~p'-[Key] ].
swi_message(initialization_error(failed, Goal, File:Line)) -->
!,
[ url(File:Line), ': ~p: false'-[Goal] ].
swi_message(initialization_error(Error, Goal, File:Line)) -->
[ url(File:Line), ': ~p '-[Goal] ],
translate_message(Error).
swi_message(determinism_error(PI, det, Found, property)) -->
( { '$pi_head'(user:PI, Head),
predicate_property(Head, det)
}
-> [ 'Deterministic procedure ~p'-[PI] ]
; [ 'Procedure ~p called from a deterministic procedure'-[PI] ]
),
det_error(Found).
swi_message(determinism_error(PI, det, fail, guard)) -->
[ 'Procedure ~p failed after $-guard'-[PI] ].
swi_message(determinism_error(PI, det, fail, guard_in_caller)) -->
[ 'Procedure ~p failed after $-guard in caller'-[PI] ].
swi_message(determinism_error(Goal, det, fail, goal)) -->
[ 'Goal ~p failed'-[Goal] ].
swi_message(determinism_error(Goal, det, nondet, goal)) -->
[ 'Goal ~p succeeded with a choice point'-[Goal] ].
swi_message(qlf_format_error(File, Message)) -->
[ '~w: Invalid QLF file: ~w'-[File, Message] ].
swi_message(goal_expansion_error(bound, Term)) -->
[ 'Goal expansion bound a variable to ~p'-[Term] ].
det_error(nondet) -->
[ ' succeeded with a choicepoint'- [] ].
det_error(fail) -->
[ ' failed'- [] ].
%! swi_location(+Term)// is det.
%
% Print location information for error(Formal, ImplDefined) from the
% ImplDefined term.
:- public swi_location//1.
swi_location(X) -->
{ var(X) },
!.
swi_location(Context) -->
{ message_lang(Lang) },
prolog:message_location(Lang, Context),
!.
swi_location(Context) -->
prolog:message_location(Context),
!.
swi_location(context(Caller, _Msg)) -->
{ ground(Caller) },
!,
caller(Caller).
swi_location(file(Path, Line, -1, _CharNo)) -->
!,
[ url(Path:Line), ': ' ].
swi_location(file(Path, Line, LinePos, _CharNo)) -->
[ url(Path:Line:LinePos), ': ' ].
swi_location(stream(Stream, Line, LinePos, CharNo)) -->
( { is_stream(Stream),
stream_property(Stream, file_name(File))
}
-> swi_location(file(File, Line, LinePos, CharNo))
; [ 'Stream ~w:~d:~d '-[Stream, Line, LinePos] ]
).
swi_location(autoload(File:Line)) -->
[ url(File:Line), ': ' ].
swi_location(_) -->
[].
caller(system:'$record_clause'/3) -->
!,
[].
caller(Module:Name/Arity) -->
!,
( { \+ hidden_module(Module) }
-> [ '~q:~q/~w: '-[Module, Name, Arity] ]
; [ '~q/~w: '-[Name, Arity] ]
).
caller(Name/Arity) -->
[ '~q/~w: '-[Name, Arity] ].
caller(Caller) -->
[ '~p: '-[Caller] ].
%! swi_extra(+Term)// is det.
%
% Extract information from the second argument of an error(Formal,
% ImplDefined) that is printed _after_ the core of the message.
%
% @see swi_location//1 uses the same term to insert context _before_
% the core of the message.
swi_extra(X) -->
{ var(X) },
!,
[].
swi_extra(Context) -->
{ message_lang(Lang) },
prolog:message_context(Lang, Context),
!.
swi_extra(Context) -->
prolog:message_context(Context).
swi_extra(context(_, Msg)) -->
{ nonvar(Msg),
Msg \== ''
},
!,
swi_comment(Msg).
swi_extra(string(String, CharPos)) -->
{ sub_string(String, 0, CharPos, _, Before),
sub_string(String, CharPos, _, 0, After)
},
[ nl, '~w'-[Before], nl, '** here **', nl, '~w'-[After] ].
swi_extra(_) -->
[].
swi_comment(already_from(Module)) -->
!,
[ ' (already imported from ~q)'-[Module] ].
swi_comment(directory(_Dir)) -->
!,
[ ' (is a directory)' ].
swi_comment(not_a_directory(_Dir)) -->
!,
[ ' (is not a directory)' ].
swi_comment(Msg) -->
[ ' (~w)'-[Msg] ].
thread_context -->
{ thread_self(Me), Me \== main, thread_property(Me, id(Id)) },
!,
['[Thread ~w] '-[Id]].
thread_context -->
[].
/*******************************
* UNWIND MESSAGES *
*******************************/
unwind_message(Var) -->
{ var(Var) }, !,
[ 'Unknown unwind message: ~p'-[Var] ].
unwind_message(abort) -->
[ 'Execution Aborted' ].
unwind_message(halt(_)) -->
[].
unwind_message(thread_exit(Term)) -->
[ 'Invalid thread_exit/1. Payload: ~p'-[Term] ].
unwind_message(Term) -->
[ 'Unknown "unwind" exception: ~p'-[Term] ].
/*******************************
* NORMAL MESSAGES *
*******************************/
prolog_message(welcome) -->
[ 'Welcome to SWI-Prolog (' ],
prolog_message(threads),
prolog_message(address_bits),
['version ' ],
prolog_message(version),
[ ')', nl ],
prolog_message(copyright),
[ nl ],
translate_message(user_versions),
[ nl ],
prolog_message(documentaton),
[ nl, nl ].
prolog_message(user_versions) -->
( { findall(Msg, prolog:version_msg(Msg), Msgs),
Msgs \== []
}
-> [nl],
user_version_messages(Msgs)
; []
).
prolog_message(deprecated(Term)) -->
{ nonvar(Term) },
( { message_lang(Lang) },
prolog:deprecated(Lang, Term)
-> []
; prolog:deprecated(Term)
-> []
; deprecated(Term)
).
prolog_message(unhandled_exception(E)) -->
{ nonvar(E) },
[ 'Unhandled exception: ' ],
( translate_message(E)
-> []
; [ '~p'-[E] ]
).
%! prolog_message(+Term)//
prolog_message(initialization_error(_, E, File:Line)) -->
!,
[ url(File:Line),
': Initialization goal raised exception:', nl
],
translate_message(E).
prolog_message(initialization_error(Goal, E, _)) -->
[ 'Initialization goal ~p raised exception:'-[Goal], nl ],
translate_message(E).
prolog_message(initialization_failure(_Goal, File:Line)) -->
!,
[ url(File:Line),
': Initialization goal failed'-[]
].
prolog_message(initialization_failure(Goal, _)) -->
[ 'Initialization goal failed: ~p'-[Goal]
].
prolog_message(initialization_exception(E)) -->
[ 'Prolog initialisation failed:', nl ],
translate_message(E).
prolog_message(init_goal_syntax(Error, Text)) -->
!,
[ '-g ~w: '-[Text] ],
translate_message(Error).
prolog_message(init_goal_failed(failed, @(Goal,File:Line))) -->
!,
[ url(File:Line), ': ~p: false'-[Goal] ].
prolog_message(init_goal_failed(Error, @(Goal,File:Line))) -->
!,
[ url(File:Line), ': ~p '-[Goal] ],
translate_message(Error).
prolog_message(init_goal_failed(failed, Text)) -->
!,
[ '-g ~w: false'-[Text] ].
prolog_message(init_goal_failed(Error, Text)) -->
!,
[ '-g ~w: '-[Text] ],
translate_message(Error).
prolog_message(goal_failed(Context, Goal)) -->
[ 'Goal (~w) failed: ~p'-[Context, Goal] ].
prolog_message(no_current_module(Module)) -->
[ '~w is not a current module (created)'-[Module] ].
prolog_message(commandline_arg_type(Flag, Arg)) -->
[ 'Bad argument to commandline option -~w: ~w'-[Flag, Arg] ].
prolog_message(missing_feature(Name)) -->
[ 'This version of SWI-Prolog does not support ~w'-[Name] ].
prolog_message(singletons(_Term, List)) -->
[ 'Singleton variables: ~w'-[List] ].
prolog_message(multitons(_Term, List)) -->
[ 'Singleton-marked variables appearing more than once: ~w'-[List] ].
prolog_message(profile_no_cpu_time) -->
[ 'No CPU-time info. Check the SWI-Prolog manual for details' ].
prolog_message(non_ascii(Text, Type)) -->
[ 'Unquoted ~w with non-portable characters: ~w'-[Type, Text] ].
prolog_message(io_warning(Stream, Message)) -->
{ stream_property(Stream, position(Position)),
!,
stream_position_data(line_count, Position, LineNo),
stream_position_data(line_position, Position, LinePos),
( stream_property(Stream, file_name(File))
-> Obj = File
; Obj = Stream
)
},
[ '~p:~d:~d: ~w'-[Obj, LineNo, LinePos, Message] ].
prolog_message(io_warning(Stream, Message)) -->
[ 'stream ~p: ~w'-[Stream, Message] ].
prolog_message(option_usage(pldoc)) -->
[ 'Usage: --pldoc[=port]' ].
prolog_message(interrupt(begin)) -->
[ 'Action (h for help) ? ', flush ].
prolog_message(interrupt(end)) -->
[ 'continue' ].
prolog_message(interrupt(trace)) -->
[ 'continue (trace mode)' ].
prolog_message(unknown_in_module_user) -->
[ 'Using a non-error value for unknown in the global module', nl,
'causes most of the development environment to stop working.', nl,
'Please use :- dynamic or limit usage of unknown to a module.', nl,
'See https://www.swi-prolog.org/howto/database.html'
].
prolog_message(untable(PI)) -->
[ 'Reconsult: removed tabling for ~p'-[PI] ].
prolog_message(unknown_option(Set, Opt)) -->
[ 'Unknown ~w option: ~p'-[Set, Opt] ].
/*******************************
* LOADING FILES *
*******************************/
prolog_message(modify_active_procedure(Who, What)) -->
[ '~p: modified active procedure ~p'-[Who, What] ].
prolog_message(load_file(failed(user:File))) -->
[ 'Failed to load ~p'-[File] ].
prolog_message(load_file(failed(Module:File))) -->
[ 'Failed to load ~p into module ~p'-[File, Module] ].
prolog_message(load_file(failed(File))) -->
[ 'Failed to load ~p'-[File] ].
prolog_message(mixed_directive(Goal)) -->
[ 'Cannot pre-compile mixed load/call directive: ~p'-[Goal] ].
prolog_message(cannot_redefine_comma) -->
[ 'Full stop in clause-body? Cannot redefine ,/2' ].
prolog_message(illegal_autoload_index(Dir, Term)) -->
[ 'Illegal term in INDEX file of directory ~w: ~w'-[Dir, Term] ].
prolog_message(redefined_procedure(Type, Proc)) -->
[ 'Redefined ~w procedure ~p'-[Type, Proc] ],
defined_definition('Previously defined', Proc).
prolog_message(declare_module(Module, abolish(Predicates))) -->
[ 'Loading module ~w abolished: ~p'-[Module, Predicates] ].
prolog_message(import_private(Module, Private)) -->
[ 'import/1: ~p is not exported (still imported into ~q)'-
[Private, Module]
].
prolog_message(ignored_weak_import(Into, From:PI)) -->
[ 'Local definition of ~p overrides weak import from ~q'-
[Into:PI, From]
].
prolog_message(undefined_export(Module, PI)) -->
[ 'Exported procedure ~q:~q is not defined'-[Module, PI] ].
prolog_message(no_exported_op(Module, Op)) -->
[ 'Operator ~q:~q is not exported (still defined)'-[Module, Op] ].
prolog_message(discontiguous((-)/2,_)) -->
prolog_message(minus_in_identifier).
prolog_message(discontiguous(Proc,Current)) -->
[ 'Clauses of ', ansi(code, '~p', [Proc]),
' are not together in the source-file', nl ],
current_definition(Proc, 'Earlier definition at '),
[ 'Current predicate: ', ansi(code, '~p', [Current]), nl,
'Use ', ansi(code, ':- discontiguous ~p.', [Proc]),
' to suppress this message'
].
prolog_message(decl_no_effect(Goal)) -->
[ 'Deprecated declaration has no effect: ~p'-[Goal] ].
prolog_message(load_file(start(Level, File))) -->
[ '~|~t~*+Loading '-[Level] ],
load_file(File),
[ ' ...' ].
prolog_message(include_file(start(Level, File))) -->
[ '~|~t~*+include '-[Level] ],
load_file(File),
[ ' ...' ].
prolog_message(include_file(done(Level, File))) -->
[ '~|~t~*+included '-[Level] ],
load_file(File).
prolog_message(load_file(done(Level, File, Action, Module, Time, Clauses))) -->
[ '~|~t~*+'-[Level] ],
load_file(File),
[ ' ~w'-[Action] ],
load_module(Module),
[ ' ~2f sec, ~D clauses'-[Time, Clauses] ].
prolog_message(dwim_undefined(Goal, Alternatives)) -->
{ goal_to_predicate_indicator(Goal, Pred)
},
[ 'Unknown procedure: ~q'-[Pred], nl,
' However, there are definitions for:', nl
],
dwim_message(Alternatives).
prolog_message(dwim_correct(Into)) -->
[ 'Correct to: ~q? '-[Into], flush ].
prolog_message(error(loop_error(Spec), file_search(Used))) -->
[ 'File search: too many levels of indirections on: ~p'-[Spec], nl,
' Used alias expansions:', nl
],
used_search(Used).
prolog_message(minus_in_identifier) -->
[ 'The "-" character should not be used to separate words in an', nl,
'identifier. Check the SWI-Prolog FAQ for details.'
].
prolog_message(qlf(removed_after_error(File))) -->
[ 'Removed incomplete QLF file ~w'-[File] ].
prolog_message(qlf(recompile(Spec,_Pl,_Qlf,Reason))) -->
[ '~p: recompiling QLF file'-[Spec] ],
qlf_recompile_reason(Reason).
prolog_message(qlf(can_not_recompile(Spec,QlfFile,_Reason))) -->
[ '~p: can not recompile "~w" (access denied)'-[Spec, QlfFile], nl,
'\tLoading from source'-[]
].
prolog_message(qlf(system_lib_out_of_date(Spec,QlfFile))) -->
[ '~p: can not recompile "~w" (access denied)'-[Spec, QlfFile], nl,
'\tLoading QlfFile'-[]
].
prolog_message(redefine_module(Module, OldFile, File)) -->
[ 'Module "~q" already loaded from ~w.'-[Module, OldFile], nl,
'Wipe and reload from ~w? '-[File], flush
].
prolog_message(redefine_module_reply) -->
[ 'Please answer y(es), n(o) or a(bort)' ].
prolog_message(reloaded_in_module(Absolute, OldContext, LM)) -->
[ '~w was previously loaded in module ~w'-[Absolute, OldContext], nl,
'\tnow it is reloaded into module ~w'-[LM] ].
prolog_message(expected_layout(Expected, Pos)) -->
[ 'Layout data: expected ~w, found: ~p'-[Expected, Pos] ].
defined_definition(Message, Spec) -->
{ strip_module(user:Spec, M, Name/Arity),
functor(Head, Name, Arity),
predicate_property(M:Head, file(File)),
predicate_property(M:Head, line_count(Line))
},
!,
[ nl, '~w at '-[Message], url(File:Line) ].
defined_definition(_, _) --> [].
used_search([]) -->
[].
used_search([Alias=Expanded|T]) -->
[ ' file_search_path(~p, ~p)'-[Alias, Expanded], nl ],
used_search(T).
load_file(file(Spec, _Path)) -->
( {atomic(Spec)}
-> [ '~w'-[Spec] ]
; [ '~p'-[Spec] ]
).
%load_file(file(_, Path)) -->
% [ '~w'-[Path] ].
load_module(user) --> !.
load_module(system) --> !.
load_module(Module) -->
[ ' into ~w'-[Module] ].
goal_to_predicate_indicator(Goal, PI) :-
strip_module(Goal, Module, Head),
callable_name_arity(Head, Name, Arity),
user_predicate_indicator(Module:Name/Arity, PI).
callable_name_arity(Goal, Name, Arity) :-
compound(Goal),
!,
compound_name_arity(Goal, Name, Arity).
callable_name_arity(Goal, Goal, 0) :-
atom(Goal).
user_predicate_indicator(Module:PI, PI) :-
hidden_module(Module),
!.
user_predicate_indicator(PI, PI).
hidden_module(user) :- !.
hidden_module(system) :- !.
hidden_module(M) :-
sub_atom(M, 0, _, _, $).
current_definition(Proc, Prefix) -->
{ pi_uhead(Proc, Head),
predicate_property(Head, file(File)),
predicate_property(Head, line_count(Line))
},
[ '~w'-[Prefix], url(File:Line), nl ].
current_definition(_, _) --> [].
pi_uhead(Module:Name/Arity, Module:Head) :-
!,
atom(Module), atom(Name), integer(Arity),
functor(Head, Name, Arity).
pi_uhead(Name/Arity, user:Head) :-
atom(Name), integer(Arity),
functor(Head, Name, Arity).
qlf_recompile_reason(old) -->
!,
[ ' (out of date)'-[] ].
qlf_recompile_reason(_) -->
[ ' (incompatible with current Prolog version)'-[] ].
prolog_message(file_search(cache(Spec, _Cond), Path)) -->
[ 'File search: ~p --> ~p (cache)'-[Spec, Path] ].
prolog_message(file_search(found(Spec, Cond), Path)) -->
[ 'File search: ~p --> ~p OK ~p'-[Spec, Path, Cond] ].
prolog_message(file_search(tried(Spec, Cond), Path)) -->
[ 'File search: ~p --> ~p NO ~p'-[Spec, Path, Cond] ].
/*******************************
* GC *
*******************************/
prolog_message(agc(start)) -->
thread_context,
[ 'AGC: ', flush ].
prolog_message(agc(done(Collected, Remaining, Time))) -->
[ at_same_line,
'reclaimed ~D atoms in ~3f sec. (remaining: ~D)'-
[Collected, Time, Remaining]
].
prolog_message(cgc(start)) -->
thread_context,
[ 'CGC: ', flush ].
prolog_message(cgc(done(CollectedClauses, _CollectedBytes,
RemainingBytes, Time))) -->
[ at_same_line,
'reclaimed ~D clauses in ~3f sec. (pending: ~D bytes)'-
[CollectedClauses, Time, RemainingBytes]
].