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.
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.
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.
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,
22 * For details, see the HELM World-Wide-Web page,
23 * http://helm.cs.unibo.it/
28 exception BaseUriNotSetYet
31 (NotationPt.term, NotationPt.term,
32 NotationPt.term GrafiteAst.reduction, string)
36 (Cic.term, Cic.lazy_term, Cic.lazy_term GrafiteAst.reduction, string)
39 let singleton msg = function
43 Printf.sprintf "GrafiteDisambiguate.singleton (%s): %u interpretations"
46 prerr_endline debug; assert false
48 let __Implicit = "__Implicit__"
49 let __Closed_Implicit = "__Closed_Implicit__"
51 let ncic_mk_choice = function
52 | LexiconAst.Symbol_alias (name, _, dsc) ->
53 if name = __Implicit then
54 dsc, `Sym_interp (fun _ -> NCic.Implicit `Term)
55 else if name = __Closed_Implicit then
56 dsc, `Sym_interp (fun _ -> NCic.Implicit `Closed)
58 DisambiguateChoices.lookup_symbol_by_dsc
59 ~mk_implicit:(function
60 | true -> NCic.Implicit `Closed
61 | false -> NCic.Implicit `Term)
63 (NCic.Appl l)::tl -> NCic.Appl (l@tl) | l -> NCic.Appl l)
64 ~term_of_uri:(fun _ -> assert false)
65 ~term_of_nref:(fun nref -> NCic.Const nref)
67 | LexiconAst.Number_alias (_, dsc) ->
68 let desc,f = DisambiguateChoices.nlookup_num_by_dsc dsc in
70 (fun num -> match f with `Num_interp f -> f num | _ -> assert false)
71 | LexiconAst.Ident_alias (name, uri) ->
73 (fun l->assert(l = []);
74 let nref = NReference.reference_of_string uri in
82 LexiconAst.Symbol_alias (__Implicit,-1,"Fake Implicit")
84 LexiconAst.Symbol_alias (__Closed_Implicit,-1,"Fake Closed Implicit")
87 let nlookup_in_library
88 interactive_user_uri_choice input_or_locate_uri item
91 | DisambiguateTypes.Id id ->
93 let references = NCicLibrary.resolve id in
95 (fun u -> LexiconAst.Ident_alias (id,NReference.string_of_reference u)
98 NCicEnvironment.ObjectNotFound _ -> [])
102 let fix_instance item l =
104 DisambiguateTypes.Symbol (_,n) ->
107 LexiconAst.Symbol_alias (s,_,d) -> LexiconAst.Symbol_alias (s,n,d)
110 | DisambiguateTypes.Num n ->
113 LexiconAst.Number_alias (_,d) -> LexiconAst.Number_alias (n,d)
116 | DisambiguateTypes.Id _ -> l
120 let disambiguate_nterm expty estatus context metasenv subst thing
122 let diff, metasenv, subst, cic =
124 (NCicDisambiguate.disambiguate_term
126 ~aliases:estatus#lstatus.LexiconEngine.aliases
128 ~universe:(Some estatus#lstatus.LexiconEngine.multi_aliases)
129 ~lookup_in_library:nlookup_in_library
130 ~mk_choice:ncic_mk_choice
131 ~mk_implicit ~fix_instance
132 ~description_of_alias:LexiconAst.description_of_alias
133 ~context ~metasenv ~subst thing)
135 let estatus = LexiconEngine.set_proof_aliases estatus diff in
136 metasenv, subst, estatus, cic
141 NotationPt.term Disambiguate.disambiguator_input option *
142 (string * NCic.term) list * NCic.term option
144 let disambiguate_npattern (text, prefix_len, (wanted, hyp_paths, goal_path)) =
145 let interp path = NCicDisambiguate.disambiguate_path path in
146 let goal_path = HExtlib.map_option interp goal_path in
147 let hyp_paths = List.map (fun (name, path) -> name, interp path) hyp_paths in
149 match wanted with None -> None | Some x -> Some (text,prefix_len,x)
151 (wanted, hyp_paths, goal_path)
154 let disambiguate_reduction_kind text prefix_len lexicon_status_ref = function
155 | `Unfold (Some t) -> assert false (* MATITA 1.0 *)
159 | `Whd as kind -> kind
162 let disambiguate_auto_params
163 disambiguate_term metasenv context (oterms, params)
166 | None -> metasenv, (None, params)
168 let metasenv, terms =
170 (fun t (metasenv, terms) ->
171 let metasenv,t = disambiguate_term context metasenv t in
172 metasenv,t::terms) terms (metasenv, [])
174 metasenv, (Some terms, params)
177 let disambiguate_just disambiguate_term context metasenv =
180 let metasenv,t = disambiguate_term context metasenv t in
183 let metasenv,params = disambiguate_auto_params disambiguate_term metasenv
186 metasenv, `Auto params
189 let disambiguate_nobj estatus ?baseuri (text,prefix_len,obj) =
192 match baseuri with Some x -> x | None -> raise BaseUriNotSetYet
196 | NotationPt.Inductive (_,(name,_,_,_)::_)
197 | NotationPt.Record (_,name,_,_) -> name ^ ".ind"
198 | NotationPt.Theorem (_,name,_,_,_) -> name ^ ".con"
199 | NotationPt.Inductive _ -> assert false
201 NUri.uri_of_string (baseuri ^ "/" ^ name)
203 let diff, _, _, cic =
205 (NCicDisambiguate.disambiguate_obj
206 ~lookup_in_library:nlookup_in_library
207 ~description_of_alias:LexiconAst.description_of_alias
208 ~mk_choice:ncic_mk_choice
209 ~mk_implicit ~fix_instance
212 ~aliases:estatus#lstatus.LexiconEngine.aliases
213 ~universe:(Some estatus#lstatus.LexiconEngine.multi_aliases)
214 (text,prefix_len,obj)) in
215 let estatus = LexiconEngine.set_proof_aliases estatus diff in
218 let disambiguate_command estatus ?baseuri (text,prefix_len,cmd)=
220 | GrafiteAst.Index(loc,key,uri) -> (* MATITA 1.0 *) assert false
221 | GrafiteAst.Select (loc,uri) ->
222 estatus, GrafiteAst.Select(loc,uri)
223 | GrafiteAst.PreferCoercion (loc,t) -> (* MATITA 1.0 *) assert false
224 | GrafiteAst.Coercion (loc,t,b,a,s) -> (* MATITA 1.0 *) assert false
225 | GrafiteAst.Inverter (loc,n,indty,params) -> (* MATITA 1.0 *) assert false
226 | GrafiteAst.Default _
228 | GrafiteAst.Include _
231 | GrafiteAst.Set _ as cmd ->
233 | GrafiteAst.Obj (loc,obj) -> (* MATITA 1.0 *) assert false
234 | GrafiteAst.Relation (loc,id,a,aeq,refl,sym,trans) -> (* MATITA 1.0 *) assert false