3 Part of CHR
(Constraint Handling Rules
)
5 Author
: Jan Wielemaker
and Tom Schrijvers
6 E
-mail
: Tom
.Schrijvers
@cs.kuleuven
.be
7 WWW
: http
://www
.swi
-prolog
.org
8 Copyright
(C
): 2003-2004, K
.U
. Leuven
10 This program is free software
; you can redistribute it
and/or
11 modify it under the terms of the GNU General Public License
12 as published by the Free Software Foundation
; either version
2
13 of the License
, or (at your option
) any later version
.
15 This program is distributed
in the hope that it will be useful
,
16 but WITHOUT ANY WARRANTY
; without even the implied warranty of
17 MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE
. See the
18 GNU General Public License
for more details
.
20 You should have received a copy of the GNU Lesser General Public
21 License along with this library
; if not, write to the Free Software
22 Foundation
, Inc
., 59 Temple Place
, Suite
330, Boston
, MA
02111-1307 USA
24 As a special exception
, if you
link this library with other files
,
25 compiled with a Free Software compiler
, to produce an executable
, this
26 library does
not by itself cause the resulting executable to be covered
27 by the GNU General Public License
. This exception does
not however
28 invalidate any other reasons why the executable file might be covered by
29 the GNU General Public License
.
32 :- module
(chr_messages
,
33 [ chr_message
/3 % +CHR Message
, Out
, Rest
35 :- use_module
(chr(chr_runtime
)).
42 chr_message
(compilation_failed
(From
)) -->
43 [ 'CHR Failed to compile ~w'-[From
] ].
47 chr_message
(prompt
) -->
48 [ at_same_line
, ' ? ', flush
].
49 chr_message
(command
(Command
)) -->
50 [ at_same_line
, '[~w]'-[Command
] ].
51 chr_message
(invalid_command
) -->
52 [ nl
, 'CHR: Not a valid debug option. Use ? for help.' ].
53 chr_message
(debug_options
) -->
55 bagof
(L
, 'chr debug command'(L
, Cmd
), Ls
),
58 [ 'CHR Debugger commands:', nl
, nl
],
59 debug_commands
(Lines
),
62 debug_commands
([]) -->
64 debug_commands
([Ls
-Cmd
|T
]) -->
65 [ '\t' ], chars
(Ls
), [ '~t~28|~w'-[Cmd
], nl
],
74 char
(' ') --> !, ['<space>'].
75 char
('\r') --> !, ['<cr>'].
76 char
(end_of_file
) --> !, ['EOF'].
80 chr_message
(ancestors
(History
, Depth
)) -->
81 [ 'CHR Ancestors:', nl
],
82 ancestors
(History
, Depth
).
86 ancestors
([Event
|Events
], Depth
) -->
87 [ '\t' ], event
(Event
, Depth
), [ nl
],
90 ancestors
(Events
, NDepth
).
95 chr_message
(event
(Port
, Depth
)) -->
98 [ flush
]. % do not emit a newline
100 event
(Port
, Depth
) -->
103 event
(apply
(H1
,H2
,G
,B
), Depth
) -->
107 event
(try
(H1
,H2
,G
,B
), Depth
) -->
111 event
(insert
(#(_,Susp)), Depth) -->
131 port
(remove
(Susp
)) -->
137 [ '~t(~D)~10| '-[Depth
] ].
140 { Susp
=.. [_
,ID
,_
,_
,_
,_
|GoalArgs
], Goal
=.. GoalArgs
142 [ '~w # <~w>'-[Goal
, ID
] ].
154 % Produce text
for the CHR rule
"H1 \ H2 [<=]=> G | B"
156 rule
(H1
, H2
, G
, B
) -->
160 rule_head
([], H2
) --> !,
163 rule_head
(H1
, []) --> !,
166 rule_head
(H1
, H2
) -->
167 heads
(H2
), [ ' \\ ' ], heads
(H1
), [' <=> '].
170 rule_body
(true
, B
) --> !,
173 [ '~w | ~w.'-[G
, B
] ].