34
35:- module(chr_messages,
36 [ chr_message/3 37 ]). 38:- use_module(chr(chr_runtime)). 39
40:- discontiguous
41 chr_message/3. 42
44
45chr_message(compilation_failed(From)) -->
46 [ 'CHR Failed to compile ~w'-[From] ].
47
49
50chr_message(prompt) -->
51 [ at_same_line, ' ? ', flush ].
52chr_message(command(Command)) -->
53 [ at_same_line, '[~w]'-[Command] ].
54chr_message(invalid_command) -->
55 [ nl, 'CHR: Not a valid debug option. Use ? for help.' ].
56chr_message(debug_options) -->
57 { bagof(Ls-Cmd,
58 bagof(L, 'chr debug command'(L, Cmd), Ls),
59 Lines)
60 },
61 [ 'CHR Debugger commands:', nl, nl ],
62 debug_commands(Lines),
63 [ nl ].
64
65debug_commands([]) -->
66 [].
67debug_commands([Ls-Cmd|T]) -->
68 [ '\t' ], chars(Ls), [ '~t~28|~w'-[Cmd], nl ],
69 debug_commands(T).
70
71chars([C]) --> !,
72 char(C).
73chars([C|T]) -->
74 char(C), [', '],
75 chars(T).
76
77char(' ') --> !, ['<space>'].
78char('\r') --> !, ['<cr>'].
79char(end_of_file) --> !, ['EOF'].
80char(C) --> [C].
81
82
83chr_message(ancestors(History, Depth)) -->
84 [ 'CHR Ancestors:', nl ],
85 ancestors(History, Depth).
86
87ancestors([], _) -->
88 [].
89ancestors([Event|Events], Depth) -->
90 [ '\t' ], event(Event, Depth), [ nl ],
91 { NDepth is Depth - 1
92 },
93 ancestors(Events, NDepth).
94
95
97
98chr_message(event(Port, Depth)) -->
99 [ 'CHR: ' ],
100 event(Port, Depth),
101 [ flush ]. 102
103event(Port, Depth) -->
104 depth(Depth),
105 port(Port).
106event(apply(H1,H2,G,B), Depth) -->
107 depth(Depth),
108 [ 'Apply: ' ],
109 rule(H1,H2,G,B).
110event(try(H1,H2,G,B), Depth) -->
111 depth(Depth),
112 [ 'Try: ' ],
113 rule(H1,H2,G,B).
114event(insert(#(_,Susp)), Depth) -->
115 depth(Depth),
116 [ 'Insert: ' ],
117 head(Susp).
118
119port(call(Susp)) -->
120 [ 'Call: ' ],
121 head(Susp).
122port(wake(Susp)) -->
123 [ 'Wake: ' ],
124 head(Susp).
125port(exit(Susp)) -->
126 [ 'Exit: ' ],
127 head(Susp).
128port(fail(Susp)) -->
129 [ 'Fail: ' ],
130 head(Susp).
131port(redo(Susp)) -->
132 [ 'Redo: ' ],
133 head(Susp).
134port(remove(Susp)) -->
135 [ 'Remove: ' ],
136 head(Susp).
137
138
139depth(Depth) -->
140 [ '~t(~D)~10| '-[Depth] ].
141
142head(Susp) -->
143 { Susp =.. [_,ID,_,_,_,_|GoalArgs], Goal =.. GoalArgs
144 },
145 [ '~w # <~w>'-[Goal, ID] ].
146
147heads([H]) --> !,
148 head(H).
149heads([H|T]) -->
150 head(H),
151 [ ', ' ],
152 heads(T).
153
154
158
159rule(H1, H2, G, B) -->
160 rule_head(H1, H2),
161 rule_body(G, B).
162
163rule_head([], H2) --> !,
164 heads(H2),
165 [ ' ==> ' ].
166rule_head(H1, []) --> !,
167 heads(H1),
168 [ ' <=> ' ].
169rule_head(H1, H2) -->
170 heads(H2), [ ' \\ ' ], heads(H1), [' <=> '].
171
172
173rule_body(true, B) --> !,
174 [ '~w.'-[B] ].
175rule_body(G, B) -->
176 [ '~w | ~w.'-[G, B] ]