]> matita.cs.unibo.it Git - helm.git/blob - matitaB/components/disambiguation/disambiguateTypes.ml
Update online helper entries
[helm.git] / matitaB / components / disambiguation / disambiguateTypes.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 (* $Id$ *)
27
28 (*
29 type domain_item =
30  | Id of (string * string option)              (* literal, opt. uri *)
31  | Symbol of string * (string option * string) option (* literal, opt. (uri,interp.) *)
32  | Num of (string option * string) option             (* opt. uri, interpretation *)
33 *)
34
35 type domain_item =
36  | Id of string     (* literal *)
37  | Symbol of string (* literal *)
38  | Num 
39
40 exception Invalid_choice of (Stdpp.location * string) Lazy.t
41
42 module OrderedDomain =
43   struct
44     type t = domain_item
45     (*
46     let compare a b = 
47       match a,b with
48       | Id (x,None), Id (y,_)
49       | Id (x,_), Id (y,None) when x = y -> 0
50       | Symbol (x,None), Symbol (y,_)
51       | Symbol (x,_), Symbol (y,None) when x = y -> 0
52       | _ -> Pervasives.compare a b *)
53     let compare = Pervasives.compare
54   end
55
56 (* module Domain = Set.Make (OrderedDomain) *)
57 module Environment =
58 struct
59   module Environment' = Map.Make (OrderedDomain)
60
61   include Environment'
62
63   let find k env =
64     try find k env 
65     with Not_found ->
66            (* 
67       match k with
68        | Symbol (sym,_) -> find (Symbol (sym,None)) env
69        | Num _ -> find (Num None) env
70        | Id (id,_) -> find (Id (id,None)) env 
71        *) raise Not_found
72
73   let cons desc_of_alias k v env =
74     let default_dom_item x = x in
75     let env' =
76       try
77         let current = Environment'.find k env in
78         let dsc = desc_of_alias v in
79         add k (v :: (List.filter (fun x -> desc_of_alias x <> dsc) current)) env
80       with Not_found ->
81         add k [v] env
82     in
83     (* we also add default aliases *)
84     let k' = default_dom_item k in
85     try
86       let current = find k' env' in
87       let dsc = desc_of_alias v in
88       add k' (v :: (List.filter (fun x -> desc_of_alias x <> dsc) current)) env'
89     with Not_found ->
90       add k' [v] env'
91
92 end
93
94 module InterprOD =
95   struct
96     type t = Stdpp.location
97     let compare = Pervasives.compare
98   end
99
100 module InterprEnv = Map.Make (InterprOD)
101
102 type 'term codomain_item =
103   string *  (* description *)
104    [`Num_interp of string -> 'term
105    |`Sym_interp of 'term list -> 'term]
106
107 type interactive_user_uri_choice_type =
108   selection_mode:[`SINGLE | `MULTIPLE] ->
109   ?ok:string ->
110   ?enable_button_for_non_vars:bool ->
111   title:string -> msg:string -> id:string -> NReference.reference list ->
112    NReference.reference list
113
114 type interactive_interpretation_choice_type = string -> int ->
115   (Stdpp.location list * string * string) list list -> int list
116
117 type interactive_ast_choice_type = string list -> int
118
119 type input_or_locate_uri_type = 
120   title:string -> ?id:string -> unit -> NReference.reference option
121
122 (*
123 let string_of_domain_item item =
124   let f_opt f x default =
125     match x with
126     | None -> default
127     | Some y -> f y
128   in
129   match item with
130   | Id (s,huri) -> 
131      Printf.sprintf "ID(%s,%s)" s (f_opt (fun x -> x) huri "_")
132   | Symbol (s,None) -> Printf.sprintf "SYMBOL(%s)" s
133   | Symbol (s,Some (_,dsc)) -> Printf.sprintf "SYMBOL(%s,%s)" s dsc
134   | Num _ -> "NUM"
135 ;;
136 *)
137 let string_of_domain_item item =
138   let f_opt f x default =
139     match x with
140     | None -> default
141     | Some y -> f y
142   in
143   match item with
144   | Id s -> 
145      Printf.sprintf "ID(%s)" s
146   | Symbol s -> Printf.sprintf "SYMBOL(%s)" s
147   | Num -> "NUM"
148 ;;