1 (* Copyright (C) 2004-2005, HELM Team.
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.
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.
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.
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,
22 * For details, see the HELM World-Wide-Web page,
23 * http://helm.cs.unibo.it/
28 (** user hit the cancel button *)
31 (** statement invoked in the wrong context (e.g. tactic with no ongoing proof)
33 exception Statement_error of string
34 let statement_error msg = raise (Statement_error msg)
36 exception Command_error of string
37 let command_error msg = raise (Command_error msg)
39 (** parameters are: option name, error message *)
40 exception Option_error of string * string
42 exception Unbound_identifier of string
44 type incomplete_proof = {
45 proof: ProofEngineTypes.proof;
46 stack: Continuationals.Stack.t;
51 | Incomplete_proof of incomplete_proof
52 | Proof of ProofEngineTypes.proof
53 | Intermediate of Cic.metasenv
54 (* Status in which the proof could be while it is being processed by the
55 * engine. No status entering/exiting the engine could be in it. *)
57 module StringMap = Map.Make (String)
62 type options = option_value StringMap.t
63 let no_options = StringMap.empty
65 type ast_command = (CicNotationPt.term, GrafiteAst.obj) GrafiteAst.command
66 type moo = ast_command list * GrafiteAst.metadata list
69 aliases: DisambiguateTypes.environment;
70 multi_aliases: DisambiguateTypes.multiple_environment;
72 proof_status: proof_status;
74 objects: (UriManager.uri * string) list;
75 notation_ids: CicNotation.notation_id list;
78 let set_metasenv metasenv status =
80 match status.proof_status with
81 | No_proof -> Intermediate metasenv
82 | Incomplete_proof ({ proof = (uri, _, proof, ty) } as incomplete_proof) ->
84 { incomplete_proof with proof = (uri, metasenv, proof, ty) }
85 | Intermediate _ -> Intermediate metasenv
86 | Proof _ -> assert false
88 { status with proof_status = proof_status }
90 let dump_status status =
91 MatitaLog.message "status.aliases:\n";
93 (DisambiguatePp.pp_environment status.aliases ^ "\n");
94 MatitaLog.message "status.proof_status:";
96 (match status.proof_status with
97 | No_proof -> "no proof\n"
98 | Incomplete_proof _ -> "incomplete proof\n"
99 | Proof _ -> "proof\n"
100 | Intermediate _ -> "Intermediate\n");
101 MatitaLog.message "status.options\n";
102 StringMap.iter (fun k v ->
106 | Int i -> string_of_int i
108 MatitaLog.message (k ^ "::=" ^ v)) status.options;
109 MatitaLog.message "status.coercions\n";
110 MatitaLog.message "status.objects:\n";
113 MatitaLog.message (UriManager.string_of_uri u)) status.objects
115 let get_option status name =
117 StringMap.find name status.options
118 with Not_found -> raise (Option_error (name, "not found"))
120 let get_string_option status name =
121 match get_option status name with
123 | _ -> raise (Option_error (name, "not a string value"))
125 let set_option status name value =
127 let s = Str.global_replace (Str.regexp "//+") "/" s in
128 let s = Str.global_replace (Str.regexp "/$") "" s in
132 [ "baseuri", (`String, mangle_dir);
133 "basedir", (`String, mangle_dir);
138 List.assoc name types
139 with Not_found -> command_error (sprintf "Unknown option \"%s\"" name)
142 match ty_and_mangler with
143 | `String, f -> String (f value)
146 Int (int_of_string (f value))
148 command_error (sprintf "Not an integer value \"%s\"" value))
150 if StringMap.mem name status.options && name = "baseuri" then
151 command_error "Redefinition of 'baseuri' is forbidden."
153 { status with options = StringMap.add name value status.options }
155 let add_moo_content cmds status =
156 let content, metadata = status.moo_content_rev in
160 (* prerr_endline ("adding to moo command: " ^ GrafiteAstPp.pp_command cmd); *)
162 | GrafiteAst.Interpretation _
163 | GrafiteAst.Default _ ->
164 if List.mem cmd content then acc
166 | GrafiteAst.Alias _ -> (* move Alias as the last inserted one *)
167 cmd :: (List.filter ((<>) cmd) acc)
171 (* prerr_endline ("new moo content: " ^ String.concat " " (List.map
172 GrafiteAstPp.pp_command content')); *)
173 { status with moo_content_rev = content', metadata }
175 let add_moo_metadata new_metadata status =
176 let content, metadata = status.moo_content_rev in
181 | GrafiteAst.Dependency buri ->
182 let is_self = (* self dependency *)
184 get_string_option status "baseuri" = buri
185 with Option_error _ -> false (* baseuri not yet set *)
188 || List.exists (GrafiteAst.eq_metadata m) metadata (* duplicate *)
192 metadata new_metadata
194 { status with moo_content_rev = content, metadata' }
196 (* subset of MatitaConsole.console methods needed by MatitaInterpreter *)
199 method clear : unit -> unit
200 method echo_error : string -> unit
201 method echo_message : string -> unit
202 method wrap_exn : 'a. (unit -> 'a) -> 'a option
203 method choose_uri : string list -> string
204 method show : ?msg:string -> unit -> unit
213 type mathViewer_entry =
214 [ `About of abouts (* current proof *)
215 | `Check of string (* term *)
216 | `Cic of Cic.term * Cic.metasenv
217 | `Dir of string (* "directory" in cic uris namespace *)
218 | `Uri of UriManager.uri (* cic object uri *)
219 | `Whelp of string * UriManager.uri list (* query and results *)
222 let string_of_entry = function
223 | `About `Blank -> "about:blank"
224 | `About `Current_proof -> "about:proof"
225 | `About `Us -> "about:us"
226 | `Check _ -> "check:"
227 | `Cic (_, _) -> "term:"
229 | `Uri uri -> UriManager.string_of_uri uri
230 | `Whelp (query, _) -> query
232 let entry_of_string = function
233 | "about:blank" -> `About `Blank
234 | "about:proof" -> `About `Current_proof
235 | "about:us" -> `About `Us
236 | _ -> (* only about entries supported ATM *)
237 raise (Invalid_argument "entry_of_string")
239 class type mathViewer =
241 (** @param reuse if set reused last opened cic browser otherwise
242 * opens a new one. default is false
244 method show_entry: ?reuse:bool -> mathViewer_entry -> unit
245 method show_uri_list:
246 ?reuse:bool -> entry:mathViewer_entry -> UriManager.uri list -> unit