]> matita.cs.unibo.it Git - helm.git/blob - helm/gTopLevel/hbugs.ml
- the mathql interpreter is not helm-dependent any more
[helm.git] / helm / gTopLevel / hbugs.ml
1 (*
2  * Copyright (C) 2003:
3  *    Stefano Zacchiroli <zack@cs.unibo.it>
4  *    for the HELM Team http://helm.cs.unibo.it/
5  *
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.
9  *
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.
14  *
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.
19  *
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,
23  *  MA  02111-1307, USA.
24  *
25  *  For details, see the HELM World-Wide-Web page,
26  *  http://helm.cs.unibo.it/
27  *)
28
29 open Hbugs_types;;
30 open Printf;;
31
32 let debug_print = 
33   let debug = true in
34   fun s -> prerr_endline (sprintf "DEBUG: %s" s)
35 ;;
36
37 exception NoProofInProgress;;
38
39 let hbugs_client = ref None
40 let use_hint_callback = ref ignore
41
42 let quit () =
43         match !hbugs_client with
44         | Some c -> c#unregisterFromBroker ()
45         | None -> ()
46
47 let hbugs_enabled = ref false
48
49 let get_hbugs_client () =
50         match !hbugs_client with
51         | Some c -> c
52         | None -> assert false
53
54 let disable () =
55         match !hbugs_client with None -> () | Some c -> c#hide ()
56
57         (** send current proof assistant state to hbugs broker *)
58 let notify () =
59         try
60                 if !hbugs_enabled then begin
61                         let client = get_hbugs_client () in
62                         let goal =
63                                 match !ProofEngine.goal with
64                                 | Some g -> g
65                                 | None -> raise NoProofInProgress
66                         in
67                         let (type_string, body_string) =
68                                 let (type_xml, body_xml) = ProofEngine.get_current_status_as_xml () in
69                                 (Xml.pp_to_string type_xml, Xml.pp_to_string body_xml)
70                         in
71                         let new_state =
72                                 (Misc.strip_xml_headings type_string,
73                                  Misc.strip_xml_headings body_string,
74                                  goal)
75                         in
76                         client#stateChange (Some new_state)
77                 end
78         with NoProofInProgress -> ()
79
80 let clear () =
81  if !hbugs_enabled then
82   begin
83          let client = get_hbugs_client () in
84           client#stateChange None
85   end
86
87 let rec enable () =
88         (match !hbugs_client with
89         | None -> (* create an hbugs client and show its window *)
90                         hbugs_client :=
91                                 (try
92                                         Some (new Hbugs_client.hbugsClient
93             ~use_hint_callback:!use_hint_callback ())
94                                 with e ->
95                                         prerr_endline (sprintf "Can't start HBugs client: %s"
96                                                 (Printexc.to_string e));
97                                         None);
98                         (match !hbugs_client with
99                         |Some client ->
100                                         client#show ();
101                                         client#subscribeAll ()
102                         | None -> ())
103         | Some c -> (* show hbugs client window *)
104                         c#show ())
105
106 let toggle state =
107         if state <> !hbugs_enabled then (* status has been changed *)
108                 (if state then enable () else disable ());
109         hbugs_enabled := state
110
111 module type Unit = sig end
112
113 module Initialize (Tactics: InvokeTactics.Tactics) : Unit =
114   struct
115     let use_hint = function
116       | Use_ring_Luke -> Tactics.ring ()
117       | Use_fourier_Luke -> Tactics.fourier ()
118       | Use_reflexivity_Luke -> Tactics.reflexivity ()
119       | Use_symmetry_Luke -> Tactics.symmetry ()
120       | Use_assumption_Luke -> Tactics.assumption ()
121       | Use_contradiction_Luke -> Tactics.contradiction ()
122       | Use_exists_Luke -> Tactics.exists ()
123       | Use_split_Luke -> Tactics.split ()
124       | Use_left_Luke -> Tactics.left ()
125       | Use_right_Luke -> Tactics.right ()
126       | Use_apply_Luke term ->
127          (* we remove the "cic:" prefix *)
128          let term' = String.sub term 4 (String.length term - 4) in
129           Tactics.apply ~term:term' ()
130       | Hints _ -> assert false
131
132     let _ = use_hint_callback := use_hint
133   end