]> matita.cs.unibo.it Git - helm.git/blob - helm/matita/matitaTypes.ml
added choose_uri method to console, used by the interpreter to implement the
[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 open Printf
27
28 exception Not_implemented of string
29 let not_implemented feature = raise (Not_implemented feature)
30
31 exception Failure of string
32 let error s = raise (Failure s)
33 let warning s = prerr_endline ("MATITA WARNING:\t" ^ s)
34 let debug_print s =
35   if BuildTimeConf.debug then prerr_endline ("MATITA DEBUG:\t" ^ s)
36
37 let explain = function
38   | StatefulProofEngine.Tactic_failure exn ->
39       sprintf "Tactic failed: %s"(Printexc.to_string exn)
40   | StatefulProofEngine.Observer_failures exns ->
41       String.concat "\n"
42         (List.map (fun (_, exn) -> Printexc.to_string exn) exns)
43   | CicTextualParser2.Parse_error (floc, msg) ->
44       let (x, y) = CicAst.loc_of_floc floc in
45       sprintf "parse error at character %d-%d: %s" x y msg
46   | CicEnvironment.Object_not_found uri ->
47       sprintf "object not found: %s" (UriManager.string_of_uri uri)
48   | exn -> sprintf "Uncaught exception: %s" (Printexc.to_string exn)
49
50 exception No_proof
51
52 exception Cancel
53 exception Unbound_identifier of string
54
55 (*
56 let untitled_con_uri = UriManager.uri_of_string "cic:/untitled.con"
57 let untitled_def_uri = UriManager.uri_of_string "cic:/untitled.ind"
58
59 let unopt_uri ?(kind = `Con) = function
60   | Some uri -> uri
61   | None ->
62       (match kind with `Con -> untitled_con_uri | `Def -> untitled_def_uri)
63 *)
64 let unopt_uri = function Some uri -> uri | None -> assert false
65
66 class type parserr =  (* "parser" is a keyword :-( *)
67   object
68     method parseTerm:     char Stream.t -> DisambiguateTypes.term
69     method parseTactical: char Stream.t -> DisambiguateTypes.tactical
70   end
71
72 class type console =
73   object
74     method echo_message   : string -> unit
75     method echo_error     : string -> unit
76     method clear          : unit -> unit
77     method wrap_exn       : 'a. (unit -> 'a) -> 'a option
78     method choose_uri     : string list -> string
79     method show : ?msg:string -> unit -> unit
80   end
81
82 type choose_uris_callback =
83   selection_mode:[`MULTIPLE|`SINGLE] ->
84   ?title:string -> ?msg:string -> ?nonvars_button:bool ->
85   string list ->
86     string list
87 type choose_interp_callback = (string * string) list list -> int list
88
89 class type disambiguator =
90   object
91     method env: DisambiguateTypes.environment
92     method setEnv: DisambiguateTypes.environment -> unit
93
94     method chooseUris: choose_uris_callback
95     method setChooseUris: choose_uris_callback -> unit
96
97     method chooseInterp: choose_interp_callback
98     method setChooseInterp: choose_interp_callback -> unit
99
100     method parserr: parserr
101
102     method disambiguateTerm:
103       ?context:Cic.context -> ?metasenv:Cic.metasenv ->
104       ?env:DisambiguateTypes.environment ->
105         char Stream.t ->
106           (DisambiguateTypes.environment * Cic.metasenv * Cic.term *
107            CicUniv.universe_graph)
108     method disambiguateTermAst:
109       ?context:Cic.context -> ?metasenv:Cic.metasenv ->
110       ?env:DisambiguateTypes.environment ->
111         DisambiguateTypes.term ->
112           (DisambiguateTypes.environment * Cic.metasenv * Cic.term *
113            CicUniv.universe_graph) 
114
115     method disambiguateTermAsts:
116       ?metasenv:Cic.metasenv ->
117       ?env:DisambiguateTypes.environment ->
118       DisambiguateTypes.term list ->
119           (DisambiguateTypes.environment * Cic.metasenv * Cic.term list *
120           CicUniv.universe_graph)
121   end
122
123 class type proof =
124   object
125     inherit [unit] StatefulProofEngine.status
126
127     method toXml: Xml.token Stream.t * Xml.token Stream.t
128     method toString: string
129   end
130
131 class type currentProof =
132   object
133     method onGoing: unit -> bool
134     method proof: proof
135     method start: proof -> unit
136     method abort: unit -> unit
137     method quit: unit -> unit
138   end
139
140 type command_outcome = bool * bool
141
142 type script_item =
143   [ `Tactic
144   | `Theorem
145   | `Qed of UriManager.uri
146   | `Def of UriManager.uri
147   | `Inductive of UriManager.uri
148   ]
149
150 class type interpreter =
151   object
152     method evalAst : DisambiguateTypes.tactical -> command_outcome
153     method evalPhrase : string -> command_outcome
154 (*     method evalStream: char Stream.t -> command_outcome *)
155     method endOffset : int
156     method lastItem: script_item option
157     method setState: [`Proof | `Command] -> unit
158     method setEvalAstCallback: (DisambiguateTypes.tactical -> unit) -> unit
159   end
160
161 type term_source =
162   [ `Ast of DisambiguateTypes.term
163   | `Cic of Cic.term
164   | `String of string
165   ]
166
167 class type mathViewer =
168   object
169     method checkTerm: term_source -> unit
170   end
171
172 class type cicBrowser =
173   object
174     method loadUri: string -> unit
175     method loadTerm: term_source -> unit
176   end
177
178 type mml_of_cic_sequent =
179   Cic.metasenv -> Cic.conjecture ->
180     Gdome.document *
181     ((Cic.id, Cic.term) Hashtbl.t *
182     (Cic.id, Cic.id option) Hashtbl.t *
183     (string, Cic.hypothesis) Hashtbl.t)
184
185 type mml_of_cic_object =
186   explode_all:bool -> UriManager.uri -> Cic.annobj ->
187   (string, string) Hashtbl.t -> (string, Cic2acic.anntypes) Hashtbl.t ->
188     Gdome.document
189
190 type namer = ProofEngineTypes.mk_fresh_name_type
191
192 let mono_uris_callback ~selection_mode ?title ?msg ?nonvars_button _ =
193   raise (Failure "ambiguous input")
194 let mono_interp_callback _ = raise (Failure "ambiguous input")
195