]> matita.cs.unibo.it Git - helm.git/blob - helm/software/components/disambiguation/disambiguateTypes.ml
The aliases and multi_aliases in the lexicon status are now
[helm.git] / helm / software / 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 type domain_item =
29   | Id of string               (* literal *)
30   | Symbol of string * int     (* literal, instance num *)
31   | Num of int                 (* instance num *)
32
33 exception Invalid_choice of (Stdpp.location * string) Lazy.t
34
35 module OrderedDomain =
36   struct
37     type t = domain_item
38     let compare = Pervasives.compare
39   end
40
41 (* module Domain = Set.Make (OrderedDomain) *)
42 module Environment =
43 struct
44   module Environment' = Map.Make (OrderedDomain)
45
46   include Environment'
47
48   let find k env =
49    match k with
50       Symbol (sym,n) ->
51        (try find k env
52         with Not_found -> find (Symbol (sym,0)) env)
53     | Num n ->
54        (try find k env
55         with Not_found -> find (Num 0) env)
56     | _ -> find k env
57
58   let cons desc_of_alias k v env =
59     try
60       let current = find k env in
61       let dsc = desc_of_alias v in
62       add k (v :: (List.filter (fun x -> desc_of_alias x <> dsc) current)) env
63     with Not_found ->
64       add k [v] env
65
66   let hd list_env =
67     try
68       map List.hd list_env
69     with Failure _ -> assert false
70
71   let fold_flatten f env base =
72     fold
73       (fun k l acc -> List.fold_right (fun v acc -> f k v acc) l acc)
74       env base
75
76 end
77
78 type 'term codomain_item =
79   string *  (* description *)
80    [`Num_interp of string -> 'term
81    |`Sym_interp of 'term list -> 'term]
82
83 and 'term environment = 'term codomain_item Environment.t
84
85 type 'term multiple_environment =
86  'term codomain_item list Environment.t
87
88 type interactive_user_uri_choice_type =
89   selection_mode:[`SINGLE | `MULTIPLE] ->
90   ?ok:string ->
91   ?enable_button_for_non_vars:bool ->
92   title:string -> msg:string -> id:string -> UriManager.uri list ->
93    UriManager.uri list
94
95 type interactive_interpretation_choice_type = string -> int ->
96   (Stdpp.location list * string * string) list list -> int list
97
98 type input_or_locate_uri_type = 
99   title:string -> ?id:string -> unit -> UriManager.uri option
100
101 module type Callbacks =
102   sig
103     val interactive_user_uri_choice : interactive_user_uri_choice_type
104
105     val interactive_interpretation_choice : 
106        interactive_interpretation_choice_type
107
108     val input_or_locate_uri: input_or_locate_uri_type
109   end
110
111 let string_of_domain_item = function
112   | Id s -> Printf.sprintf "ID(%s)" s
113   | Symbol (s, i) -> Printf.sprintf "SYMBOL(%s,%d)" s i
114   | Num i -> Printf.sprintf "NUM(instance %d)" i
115
116 let string_of_domain dom =
117   String.concat "; " (List.map string_of_domain_item dom)