]> matita.cs.unibo.it Git - helm.git/blob - helm/matita/matitaTypes.ml
snapshot, notably:
[helm.git] / helm / matita / matitaTypes.ml
1 (* Copyright (C) 2004, 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 exception Not_implemented of string
27 let not_implemented feature = raise (Not_implemented feature)
28
29   (** exceptions whose content should be presented to the user *)
30 exception Failure of string
31 let error s = raise (Failure s)
32 let warning s = prerr_endline ("MATITA WARNING:\t" ^ s)
33 let debug_print s =
34   if BuildTimeConf.debug then prerr_endline ("MATITA DEBUG:\t" ^ s)
35
36 exception No_proof  (** no current proof is available *)
37
38 exception Cancel
39 exception Unbound_identifier of string
40
41 (*
42 let untitled_con_uri = UriManager.uri_of_string "cic:/untitled.con"
43 let untitled_def_uri = UriManager.uri_of_string "cic:/untitled.ind"
44
45 let unopt_uri ?(kind = `Con) = function
46   | Some uri -> uri
47   | None ->
48       (match kind with `Con -> untitled_con_uri | `Def -> untitled_def_uri)
49 *)
50 let unopt_uri = function Some uri -> uri | None -> assert false
51
52 class type parserr =  (* "parser" is a keyword :-( *)
53   object
54     method parseTerm:     char Stream.t -> DisambiguateTypes.term
55     method parseTactical: char Stream.t -> DisambiguateTypes.tactical
56   end
57
58   (* subset of MatitaConsole.console methods needed by MatitaInterpreter *)
59 class type console =
60   object
61     method echo_message   : string -> unit
62     method echo_error     : string -> unit
63     method clear          : unit -> unit
64     method wrap_exn       : (unit -> unit) -> bool
65   end
66
67 class type disambiguator =
68   object
69     method parserr: parserr
70     method setParserr: parserr -> unit
71
72     method env: DisambiguateTypes.environment
73     method setEnv: DisambiguateTypes.environment -> unit
74
75       (* TODO Zack: as long as matita doesn't support MDI inteface,
76       * disambiguateTerm will return a single term *)
77       (** @param env disambiguation environment. If this parameter is given the
78       * disambiguator act statelessly, that is internal disambiguation status
79       * want be changed but only returned. If this parameter is not given the
80       * internal one will be used and updated with the disambiguation status
81       * resulting from the disambiguation *)
82     method disambiguateTerm:
83       ?context:Cic.context -> ?metasenv:Cic.metasenv ->
84       ?env:DisambiguateTypes.environment ->
85         char Stream.t ->
86           (DisambiguateTypes.environment * Cic.metasenv * Cic.term * CicUniv.universe_graph)
87       (** @param env @see disambiguateTerm above *)
88     method disambiguateTermAst:
89       ?context:Cic.context -> ?metasenv:Cic.metasenv ->
90       ?env:DisambiguateTypes.environment ->
91         DisambiguateTypes.term ->
92           (DisambiguateTypes.environment * Cic.metasenv * Cic.term * CicUniv.universe_graph) 
93
94       (** as disambiguateTermAst, but disambiguate a list of ASTs at once. All
95       * AST should be closed hence no context param is permitted on this method
96       *)
97     method disambiguateTermAsts:
98       ?metasenv:Cic.metasenv ->
99       ?env:DisambiguateTypes.environment ->
100       DisambiguateTypes.term list ->
101           (DisambiguateTypes.environment * Cic.metasenv * Cic.term list *
102           CicUniv.universe_graph)
103   end
104
105 (*
106 type sequents_metadata =
107   (int *                                  (** sequent (meta) index *)
108     (Cic.annconjecture *                    (** annotated conjecture *)
109     (Cic.id, Cic.term) Hashtbl.t *          (** ids_to_terms *)
110     (Cic.id, Cic.id option) Hashtbl.t *     (** ids_to_father_ids *)
111     (Cic.id, string) Hashtbl.t *            (** ids_to_inner_sorts *)
112     (Cic.id, Cic.hypothesis) Hashtbl.t))    (** ids_to_hypotheses *)
113       list
114 type proof_metadata =
115   Cic.annobj *                             (** annotated object    *)
116   (Cic.id, Cic.term) Hashtbl.t *            (** ids_to_terms        *)
117   (Cic.id, Cic.id option) Hashtbl.t *       (** ids_to_father_ids   *)
118   (Cic.id, string) Hashtbl.t *              (** ids_to_inner_sorts  *)
119   (Cic.id, Cic2acic.anntypes) Hashtbl.t *   (** ids_to_inner_types  *)
120   (Cic.id, Cic.conjecture) Hashtbl.t *      (** ids_to_conjectures  *)
121   (Cic.id, Cic.hypothesis) Hashtbl.t        (** ids_to_hypotheses   *)
122 type hist_metadata = proof_metadata * sequents_metadata
123 *)
124
125 class type proof =
126   object
127     inherit [unit] StatefulProofEngine.status
128
129     (** return a pair of "xml" (as defined in Xml module) representing the *
130      * current proof type and body, respectively *)
131     method toXml: Xml.token Stream.t * Xml.token Stream.t
132     method toString: string
133   end
134
135 type proof_handler =
136   { get_proof: unit -> proof; (* return current proof or fail *)
137     set_proof: proof option -> unit;
138     abort_proof: unit -> unit;(* abort current proof, cleaning up garbage *)
139     has_proof: unit -> bool;  (* check if a current proof is available or not *)
140     new_proof: proof -> unit; (* as a set_proof but takes care also to register
141                               observers *)
142     quit: unit -> unit
143   }
144
145   (** interpreter for toplevel phrases given via console *)
146 class type interpreter =
147   object
148     method reset: unit  (** return the interpreter to the initial state *)
149
150       (** parse a single phrase contained in the input string. Additional
151       * garbage at the end of the phrase is ignored
152       * @return true if no exception has been raised by the evaluation, false
153       * otherwise
154       *)
155     method evalPhrase: string -> bool
156
157       (** as above, evaluating a command/tactics AST *)
158     method evalAst: DisambiguateTypes.tactical -> bool
159
160       (** offset from the starting of the last string parser by evalPhrase where
161       * parsing stop.
162       * @raise Failure when no offset has been recorded *)
163     method endOffset: int
164
165   end
166
167 (** {2 MathML widgets} *)
168
169 type mml_of_cic_sequent =
170   Cic.metasenv -> Cic.conjecture ->
171     Gdome.document *
172     ((Cic.id, Cic.term) Hashtbl.t *
173     (Cic.id, Cic.id option) Hashtbl.t *
174     (string, Cic.hypothesis) Hashtbl.t)
175
176 type mml_of_cic_object =
177   explode_all:bool -> UriManager.uri -> Cic.annobj ->
178   (string, string) Hashtbl.t -> (string, Cic2acic.anntypes) Hashtbl.t ->
179     Gdome.document
180
181 class type proof_viewer =
182   object
183     inherit GMathViewAux.single_selection_math_view
184
185     method load_proof: StatefulProofEngine.proof_status -> unit
186   end
187
188 class type sequent_viewer =
189   object
190     inherit GMathViewAux.multi_selection_math_view
191
192       (** @return the list of selected terms. Selections which are not terms are
193       * ignored *)
194     method get_selected_terms: Cic.term list
195
196       (** @return the list of selected hypothese. Selections which are not
197       * hypotheses are ignored *)
198     method get_selected_hypotheses: Cic.hypothesis list
199
200       (** load a sequent and render it into parent widget *)
201     method load_sequent: Cic.metasenv -> int -> unit
202   end
203
204 class type sequents_viewer =
205   object
206     method reset: unit
207     method load_sequents: Cic.metasenv -> unit
208     method goto_sequent: int -> unit  (* to be called _after_ load_sequents *)
209   end
210
211 (** {2 shorthands} *)
212
213 type namer = ProofEngineTypes.mk_fresh_name_type
214
215 type choose_uris_callback =
216   selection_mode:[`MULTIPLE|`SINGLE] ->
217   ?title:string -> ?msg:string -> ?nonvars_button:bool ->
218   string list ->
219     string list
220
221 type choose_interp_callback = (string * string) list list -> int list
222