]> matita.cs.unibo.it Git - helm.git/blob - helm/matita/matitaTypes.ml
removed coercions from 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;   (** disambiguation aliases *)
62   proof_status: proof_status;
63   options: options;
64   objects: (UriManager.uri * string) list;
65     (** in-scope objects, with their paths *)
66 }
67
68 let dump_status status = 
69   MatitaLog.message "status.aliases:\n";
70   MatitaLog.message
71   (CicTextualParser2.EnvironmentP3.to_string status.aliases ^ "\n");
72   MatitaLog.message "status.proof_status:"; 
73   MatitaLog.message
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 -> 
81     let v = 
82       match v with
83       | String s -> s
84       | Int i -> string_of_int i
85     in
86     MatitaLog.message (k ^ "::=" ^ v)) status.options;
87   MatitaLog.message "status.coercions\n";
88   MatitaLog.message "status.objects:\n";
89   List.iter 
90     (fun (u,_) -> 
91       MatitaLog.message (UriManager.string_of_uri u)) status.objects 
92   
93
94 let get_option status name =
95   try
96     StringMap.find name status.options
97   with Not_found -> raise (Option_error (name, "not found"))
98
99 let get_string_option status name =
100   match get_option status name with
101   | String s -> s
102   | _ -> raise (Option_error (name, "not a string value"))
103
104 let set_option status name value =
105   let mangle_dir s =
106     let s = Str.global_replace (Str.regexp "//+") "/" s in
107     let s = Str.global_replace (Str.regexp "/$") "" s in
108     s
109   in
110   let types =
111     [ "baseuri", (`String, mangle_dir);
112       "basedir", (`String, mangle_dir);
113     ]
114   in
115   let ty_and_mangler =
116     try
117       List.assoc name types
118     with Not_found -> command_error (sprintf "Unknown option \"%s\"" name)
119   in
120   let value =
121     match ty_and_mangler with
122     | `String, f -> String (f value)
123     | `Int, f ->
124         (try
125           Int (int_of_string (f value))
126         with Failure _ ->
127           command_error (sprintf "Not an integer value \"%s\"" value))
128   in
129   { status with options = StringMap.add name value status.options }
130
131   (* subset of MatitaConsole.console methods needed by MatitaInterpreter *)
132 class type console =
133   object
134     method clear : unit -> unit
135     method echo_error : string -> unit
136     method echo_message : string -> unit
137     method wrap_exn : 'a. (unit -> 'a) -> 'a option
138     method choose_uri : string list -> string
139     method show : ?msg:string -> unit -> unit
140   end
141
142 type abouts =
143   [ `Blank
144   | `Current_proof
145   | `Us
146   ]
147   
148 type mathViewer_entry =
149   [ `About of abouts  (* current proof *)
150   | `Check of string (* term *)
151   | `Cic of Cic.term * Cic.metasenv
152   | `Dir of string (* "directory" in cic uris namespace *)
153   | `Uri of string (* cic object uri *)
154   | `Whelp of string * string list (* query and results *)
155   ]
156
157 let string_of_entry = function
158   | `About `Blank -> "about:blank"
159   | `About `Current_proof -> "about:proof"
160   | `About `Us -> "about:us"
161   | `Check _ -> "check:"
162   | `Cic (_, _) -> "term:"
163   | `Dir uri | `Uri uri -> uri
164   | `Whelp (query, _) -> query
165
166 class type mathViewer =
167   object
168     (** @param reuse if set reused last opened cic browser otherwise 
169      *  opens a new one. default is false
170      *)
171     method show_entry: ?reuse:bool -> mathViewer_entry -> unit
172     method show_uri_list:
173       ?reuse:bool -> entry:mathViewer_entry -> string list -> unit
174   end
175