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
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. *)
52 module StringMap = Map.Make (String)
57 type options = option_value StringMap.t
58 let no_options = StringMap.empty
61 aliases: DisambiguateTypes.environment; (** disambiguation aliases *)
62 proof_status: proof_status;
64 objects: (UriManager.uri * string) list;
65 (** in-scope objects, with their paths *)
68 let dump_status status =
69 MatitaLog.message "status.aliases:\n";
71 (CicTextualParser2.EnvironmentP3.to_string status.aliases ^ "\n");
72 MatitaLog.message "status.proof_status:";
74 (match status.proof_status with
75 | No_proof -> "no proof\n"
76 | Incomplete_proof _ -> "incomplete proof\n"
77 | Proof _ -> "proof\n"
78 | Intermediate _ -> "Intermediate\n");
79 MatitaLog.message "status.options\n";
80 StringMap.iter (fun k v ->
84 | Int i -> string_of_int i
86 MatitaLog.message (k ^ "::=" ^ v)) status.options;
87 MatitaLog.message "status.coercions\n";
88 MatitaLog.message "status.objects:\n";
91 MatitaLog.message (UriManager.string_of_uri u)) status.objects
94 let get_option status name =
96 StringMap.find name status.options
97 with Not_found -> raise (Option_error (name, "not found"))
99 let get_string_option status name =
100 match get_option status name with
102 | _ -> raise (Option_error (name, "not a string value"))
104 let set_option status name value =
106 let s = Str.global_replace (Str.regexp "//+") "/" s in
107 let s = Str.global_replace (Str.regexp "/$") "" s in
111 [ "baseuri", (`String, mangle_dir);
112 "basedir", (`String, mangle_dir);
117 List.assoc name types
118 with Not_found -> command_error (sprintf "Unknown option \"%s\"" name)
121 match ty_and_mangler with
122 | `String, f -> String (f value)
125 Int (int_of_string (f value))
127 command_error (sprintf "Not an integer value \"%s\"" value))
129 if StringMap.mem name status.options && name = "baseuri" then
130 command_error "Redefinition of 'baseuri' is forbidden."
132 { status with options = StringMap.add name value status.options }
134 (* subset of MatitaConsole.console methods needed by MatitaInterpreter *)
137 method clear : unit -> unit
138 method echo_error : string -> unit
139 method echo_message : string -> unit
140 method wrap_exn : 'a. (unit -> 'a) -> 'a option
141 method choose_uri : string list -> string
142 method show : ?msg:string -> unit -> unit
151 type mathViewer_entry =
152 [ `About of abouts (* current proof *)
153 | `Check of string (* term *)
154 | `Cic of Cic.term * Cic.metasenv
155 | `Dir of string (* "directory" in cic uris namespace *)
156 | `Uri of UriManager.uri (* cic object uri *)
157 | `Whelp of string * UriManager.uri list (* query and results *)
160 let string_of_entry = function
161 | `About `Blank -> "about:blank"
162 | `About `Current_proof -> "about:proof"
163 | `About `Us -> "about:us"
164 | `Check _ -> "check:"
165 | `Cic (_, _) -> "term:"
167 | `Uri uri -> UriManager.string_of_uri uri
168 | `Whelp (query, _) -> query
170 let entry_of_string = function
171 | "about:blank" -> `About `Blank
172 | "about:proof" -> `About `Current_proof
173 | "about:us" -> `About `Us
174 | _ -> (* only about entries supported ATM *)
175 raise (Invalid_argument "entry_of_string")
177 class type mathViewer =
179 (** @param reuse if set reused last opened cic browser otherwise
180 * opens a new one. default is false
182 method show_entry: ?reuse:bool -> mathViewer_entry -> unit
183 method show_uri_list:
184 ?reuse:bool -> entry:mathViewer_entry -> UriManager.uri list -> unit