]> matita.cs.unibo.it Git - helm.git/blob - helm/matita/matitaTypes.ml
added set_metasenv on proof_status
[helm.git] / helm / matita / matitaTypes.ml
1 (* Copyright (C) 2004-2005, HELM Team.
2  * 
3  * This file is part of HELM, an Hypertextual, Electronic
4  * Library of Mathematics, developed at the Computer Science
5  * Department, University of Bologna, Italy.
6  * 
7  * HELM is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  * 
12  * HELM is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with HELM; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://helm.cs.unibo.it/
24  *)
25
26 open Printf
27
28   (** user hit the cancel button *)
29 exception Cancel
30
31   (** statement invoked in the wrong context (e.g. tactic with no ongoing proof)
32    *)
33 exception Statement_error of string
34 let statement_error msg = raise (Statement_error msg)
35
36 exception Command_error of string
37 let command_error msg = raise (Command_error msg)
38
39   (** parameters are: option name, error message *)
40 exception Option_error of string * string
41
42 exception Unbound_identifier of string
43
44 type proof_status =
45   | No_proof
46   | Incomplete_proof of ProofEngineTypes.status
47   | Proof of ProofEngineTypes.proof
48   | Intermediate of Cic.metasenv
49       (* Status in which the proof could be while it is being processed by the
50       * engine. No status entering/exiting the engine could be in it. *)
51
52 module StringMap = Map.Make (String)
53
54 type option_value =
55   | String of string
56   | Int of int
57 type options = option_value StringMap.t
58 let no_options = StringMap.empty
59
60 type status = {
61   aliases : DisambiguateTypes.environment;
62   moo_content_rev : string list;
63   proof_status : proof_status;
64   options : options;
65   objects : (UriManager.uri * string) list;
66   notation_ids: CicNotation.notation_id list;
67 }
68
69 let set_metasenv metasenv status =
70   let proof_status =
71     match status.proof_status with
72     | No_proof -> Intermediate metasenv
73     | Incomplete_proof ((uri, _, proof, ty), goal) ->
74         Incomplete_proof ((uri, metasenv, proof, ty), goal)
75     | Intermediate _ -> Intermediate metasenv 
76     | Proof _ -> assert false
77   in
78   { status with proof_status = proof_status }
79
80 let dump_status status = 
81   MatitaLog.message "status.aliases:\n";
82   MatitaLog.message
83   (DisambiguatePp.pp_environment status.aliases ^ "\n");
84   MatitaLog.message "status.proof_status:"; 
85   MatitaLog.message
86     (match status.proof_status with
87     | No_proof -> "no proof\n"
88     | Incomplete_proof _ -> "incomplete proof\n"
89     | Proof _ -> "proof\n"
90     | Intermediate _ -> "Intermediate\n");
91   MatitaLog.message "status.options\n";
92   StringMap.iter (fun k v -> 
93     let v = 
94       match v with
95       | String s -> s
96       | Int i -> string_of_int i
97     in
98     MatitaLog.message (k ^ "::=" ^ v)) status.options;
99   MatitaLog.message "status.coercions\n";
100   MatitaLog.message "status.objects:\n";
101   List.iter 
102     (fun (u,_) -> 
103       MatitaLog.message (UriManager.string_of_uri u)) status.objects 
104   
105
106 let get_option status name =
107   try
108     StringMap.find name status.options
109   with Not_found -> raise (Option_error (name, "not found"))
110
111 let get_string_option status name =
112   match get_option status name with
113   | String s -> s
114   | _ -> raise (Option_error (name, "not a string value"))
115
116 let set_option status name value =
117   let mangle_dir s =
118     let s = Str.global_replace (Str.regexp "//+") "/" s in
119     let s = Str.global_replace (Str.regexp "/$") "" s in
120     s
121   in
122   let types =
123     [ "baseuri", (`String, mangle_dir);
124       "basedir", (`String, mangle_dir);
125     ]
126   in
127   let ty_and_mangler =
128     try
129       List.assoc name types
130     with Not_found -> command_error (sprintf "Unknown option \"%s\"" name)
131   in
132   let value =
133     match ty_and_mangler with
134     | `String, f -> String (f value)
135     | `Int, f ->
136         (try
137           Int (int_of_string (f value))
138         with Failure _ ->
139           command_error (sprintf "Not an integer value \"%s\"" value))
140   in
141   if StringMap.mem name status.options && name = "baseuri" then
142     command_error "Redefinition of 'baseuri' is forbidden."
143   else
144     { status with options = StringMap.add name value status.options }
145
146   (* subset of MatitaConsole.console methods needed by MatitaInterpreter *)
147 class type console =
148   object
149     method clear : unit -> unit
150     method echo_error : string -> unit
151     method echo_message : string -> unit
152     method wrap_exn : 'a. (unit -> 'a) -> 'a option
153     method choose_uri : string list -> string
154     method show : ?msg:string -> unit -> unit
155   end
156
157 type abouts =
158   [ `Blank
159   | `Current_proof
160   | `Us
161   ]
162   
163 type mathViewer_entry =
164   [ `About of abouts  (* current proof *)
165   | `Check of string (* term *)
166   | `Cic of Cic.term * Cic.metasenv
167   | `Dir of string (* "directory" in cic uris namespace *)
168   | `Uri of UriManager.uri (* cic object uri *)
169   | `Whelp of string * UriManager.uri list (* query and results *)
170   ]
171
172 let string_of_entry = function
173   | `About `Blank -> "about:blank"
174   | `About `Current_proof -> "about:proof"
175   | `About `Us -> "about:us"
176   | `Check _ -> "check:"
177   | `Cic (_, _) -> "term:"
178   | `Dir uri -> uri
179   | `Uri uri -> UriManager.string_of_uri uri
180   | `Whelp (query, _) -> query
181
182 let entry_of_string = function
183   | "about:blank" -> `About `Blank
184   | "about:proof" -> `About `Current_proof
185   | "about:us"    -> `About `Us
186   | _ ->  (* only about entries supported ATM *)
187       raise (Invalid_argument "entry_of_string")
188
189 class type mathViewer =
190   object
191     (** @param reuse if set reused last opened cic browser otherwise 
192      *  opens a new one. default is false
193      *)
194     method show_entry: ?reuse:bool -> mathViewer_entry -> unit
195     method show_uri_list:
196       ?reuse:bool -> entry:mathViewer_entry -> UriManager.uri list -> unit
197   end
198