3 * Stefano Zacchiroli <zack@cs.unibo.it>
4 * for the HELM Team http://helm.cs.unibo.it/
6 * This file is part of HELM, an Hypertextual, Electronic
7 * Library of Mathematics, developed at the Computer Science
8 * Department, University of Bologna, Italy.
10 * HELM 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 * HELM 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 General Public License
21 * along with HELM; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25 * For details, see the HELM World-Wide-Web page,
26 * http://helm.cs.unibo.it/
34 fun s -> prerr_endline (sprintf "DEBUG: %s" s)
37 exception NoProofInProgress;;
39 module type HbugsActions =
41 val enable: unit -> unit
42 val disable: unit -> unit
43 val toggle: bool -> unit
45 val quit: unit -> unit
47 val notify: unit -> unit
50 module Make (Tactics: InvokeTactics.Tactics) : HbugsActions =
52 let hbugs_client = ref None
55 match !hbugs_client with
56 | Some c -> c#unregisterFromBroker ()
59 let hbugs_enabled = ref false
61 let get_hbugs_client () =
62 match !hbugs_client with
64 | None -> assert false
67 match !hbugs_client with None -> () | Some c -> c#hide ()
69 (** send current proof assistant state to hbugs broker *)
72 if !hbugs_enabled then begin
73 let client = get_hbugs_client () in
75 match !ProofEngine.goal with
77 | None -> raise NoProofInProgress
79 let (type_string, body_string) =
80 let (type_xml, body_xml) = ProofEngine.get_current_status_as_xml () in
81 (Xml.pp_to_string type_xml, Xml.pp_to_string body_xml)
84 (Misc.strip_xml_headings type_string,
85 Misc.strip_xml_headings body_string,
88 client#stateChange new_state
90 with NoProofInProgress -> ()
92 let use_hint = function
93 | Use_ring_Luke -> Tactics.ring ()
94 | Use_fourier_Luke -> Tactics.fourier ()
95 | Use_reflexivity_Luke -> Tactics.reflexivity ()
96 | Use_symmetry_Luke -> Tactics.symmetry ()
97 | Use_assumption_Luke -> Tactics.assumption ()
98 | Use_contradiction_Luke -> Tactics.contradiction ()
99 | Use_exists_Luke -> Tactics.exists ()
100 | Use_split_Luke -> Tactics.split ()
101 | Use_left_Luke -> Tactics.left ()
102 | Use_right_Luke -> Tactics.right ()
103 | Use_apply_Luke term -> Tactics.apply ~term ()
104 | Hints _ -> assert false
107 (match !hbugs_client with
108 | None -> (* create an hbugs client and show its window *)
112 (new Hbugs_client.hbugsClient
113 ~on_use_hint: use_hint
114 ~on_exit: ignore (* TODO disable hbugs on 'on_exit' callback *)
117 prerr_endline (sprintf "Can't start HBugs client: %s"
118 (Printexc.to_string e));
120 (match !hbugs_client with
123 client#subscribeAll ()
125 | Some c -> (* show hbugs client window *)
129 if state <> !hbugs_enabled then (* status has been changed *)
130 (if state then enable () else disable ());
131 hbugs_enabled := state