]> matita.cs.unibo.it Git - helm.git/blob - helm/matita/matitaTypes.ml
92fc79b7c288fb979f65d136eb510c148c04fee4
[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 let untitled_con_uri = UriManager.uri_of_string "cic:/untitled.con"
39 let untitled_def_uri = UriManager.uri_of_string "cic:/untitled.ind"
40
41 class type observer =
42   (* "observer" pattern *)
43   object
44     method update: unit -> unit
45   end
46
47 class subject =
48   (* "observer" pattern *)
49   object
50     val mutable observers = []
51     method attach (o: observer) = observers <- o :: observers
52     method detach (o: observer) =
53       observers <- List.filter (fun o' -> o' != o) observers
54     method notify () = List.iter (fun o -> o#update ()) observers
55   end
56
57 class type command =
58   (* "command" pattern *)
59   object
60     method execute: unit -> unit
61     method undo: unit -> unit
62   end
63
64 class type parserr =  (* "parser" is a keyword :-( *)
65   object
66     method parseTerm:     char Stream.t -> DisambiguateTypes.term
67     method parseTactic:   char Stream.t -> DisambiguateTypes.tactic
68     method parseTactical: char Stream.t -> DisambiguateTypes.tactical
69     method parseCommand:  char Stream.t -> DisambiguateTypes.command
70     method parseScript:   char Stream.t -> DisambiguateTypes.script
71   end
72
73 class type disambiguator =
74   object
75     method parserr: parserr
76     method setParserr: parserr -> unit
77
78     method env: DisambiguateTypes.environment
79     method setEnv: DisambiguateTypes.environment -> unit
80
81       (* TODO Zack: as long as matita doesn't support MDI inteface,
82       * disambiguateTerm will return a single term *)
83       (** @param env disambiguation environment. If this parameter is given the
84       * disambiguator act statelessly, that is internal disambiguation status
85       * want be changed but only returned. If this parameter is not given the
86       * internal one will be used and updated with the disambiguation status
87       * resulting from the disambiguation *)
88     method disambiguateTerm:
89       ?context:Cic.context -> ?metasenv:Cic.metasenv ->
90       ?env:DisambiguateTypes.environment ->
91         char Stream.t ->
92           (DisambiguateTypes.environment * Cic.metasenv * Cic.term)
93       (** @param env @see disambiguateTerm above *)
94     method disambiguateTermAst:
95       ?context:Cic.context -> ?metasenv:Cic.metasenv ->
96       ?env:DisambiguateTypes.environment ->
97         DisambiguateTypes.term ->
98           (DisambiguateTypes.environment * Cic.metasenv * Cic.term)
99   end
100
101 class type proofStatus =
102   object
103     inherit subject
104
105       (** {3 properties} *)
106
107     method proof: ProofEngineTypes.proof
108     method setProof: ProofEngineTypes.proof -> unit
109
110     method goal: ProofEngineTypes.goal option
111     method setGoal: ProofEngineTypes.goal option -> unit
112
113       (** @raise MatitaTypes.No_proof *)
114     method status: ProofEngineTypes.status (* proof, goal *)
115     method setStatus: ProofEngineTypes.status -> unit
116
117       (** {3 actions} *)
118
119     (** return a pair of "xml" (as defined in Xml module) representing the *
120      * current proof type and body, respectively *)
121     method toXml: Xml.token Stream.t * Xml.token Stream.t
122     method toString: string
123   end
124
125 class type proof =
126   object
127       (** {3 status} *)
128     method status: proofStatus
129     method setStatus: proofStatus -> unit
130   end
131
132 type proof_handler =
133   { get_proof: unit -> proof; (* return current proof or fail *)
134     set_proof: proof option -> unit;  (* set a proof option as current proof *)
135     has_proof: unit -> bool;  (* check if a current proof is available or not *)
136     new_proof: proof -> unit; (* as a set_proof but takes care also to register
137                               observers *)
138     quit: unit -> unit
139   }
140
141   (** interpreter for toplevel phrases given via console *)
142 class type interpreter =
143   object
144     method evalPhrase: string -> unit
145   end
146
147 (** {2 shorthands} *)
148
149 type namer = ProofEngineTypes.mk_fresh_name_type
150
151 type choose_uris_callback =
152   selection_mode:[`MULTIPLE|`SINGLE] ->
153   ?title:string -> ?msg:string -> ?nonvars_button:bool ->
154   string list ->
155     string list
156
157 type choose_interp_callback = (string * string) list list -> int list
158