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
32 (NotationPt.term, NotationPt.term,
33 NotationPt.term GrafiteAst.reduction, string)
36 let singleton msg = function
40 Printf.sprintf "GrafiteDisambiguate.singleton (%s): %u interpretations"
43 prerr_endline debug; assert false
45 let __Implicit = "__Implicit__"
46 let __Closed_Implicit = "__Closed_Implicit__"
48 let ncic_mk_choice = function
49 | LexiconAst.Symbol_alias (name, _, dsc) ->
50 if name = __Implicit then
51 dsc, `Sym_interp (fun _ -> NCic.Implicit `Term)
52 else if name = __Closed_Implicit then
53 dsc, `Sym_interp (fun _ -> NCic.Implicit `Closed)
55 DisambiguateChoices.lookup_symbol_by_dsc
56 ~mk_implicit:(function
57 | true -> NCic.Implicit `Closed
58 | false -> NCic.Implicit `Term)
60 (NCic.Appl l)::tl -> NCic.Appl (l@tl) | l -> NCic.Appl l)
61 ~term_of_uri:(fun _ -> assert false)
62 ~term_of_nref:(fun nref -> NCic.Const nref)
64 | LexiconAst.Number_alias (_, dsc) ->
65 let desc,f = DisambiguateChoices.nlookup_num_by_dsc dsc in
67 (fun num -> match f with `Num_interp f -> f num | _ -> assert false)
68 | LexiconAst.Ident_alias (name, uri) ->
70 (fun l->assert(l = []);
71 let nref = NReference.reference_of_string uri in
79 LexiconAst.Symbol_alias (__Implicit,-1,"Fake Implicit")
81 LexiconAst.Symbol_alias (__Closed_Implicit,-1,"Fake Closed Implicit")
84 let nlookup_in_library
85 interactive_user_uri_choice input_or_locate_uri item
88 | DisambiguateTypes.Id id ->
90 let references = NCicLibrary.resolve id in
92 (fun u -> LexiconAst.Ident_alias (id,NReference.string_of_reference u)
95 NCicEnvironment.ObjectNotFound _ -> [])
99 let fix_instance item l =
101 DisambiguateTypes.Symbol (_,n) ->
104 LexiconAst.Symbol_alias (s,_,d) -> LexiconAst.Symbol_alias (s,n,d)
107 | DisambiguateTypes.Num n ->
110 LexiconAst.Number_alias (_,d) -> LexiconAst.Number_alias (n,d)
113 | DisambiguateTypes.Id _ -> l
117 let disambiguate_nterm expty estatus context metasenv subst thing
119 let diff, metasenv, subst, cic =
121 (NCicDisambiguate.disambiguate_term
123 ~aliases:estatus#lstatus.LexiconEngine.aliases
125 ~universe:(Some estatus#lstatus.LexiconEngine.multi_aliases)
126 ~lookup_in_library:nlookup_in_library
127 ~mk_choice:ncic_mk_choice
128 ~mk_implicit ~fix_instance
129 ~description_of_alias:LexiconAst.description_of_alias
130 ~context ~metasenv ~subst thing)
132 let estatus = LexiconEngine.set_proof_aliases estatus diff in
133 metasenv, subst, estatus, cic
138 NotationPt.term Disambiguate.disambiguator_input option *
139 (string * NCic.term) list * NCic.term option
141 let disambiguate_npattern (text, prefix_len, (wanted, hyp_paths, goal_path)) =
142 let interp path = NCicDisambiguate.disambiguate_path path in
143 let goal_path = HExtlib.map_option interp goal_path in
144 let hyp_paths = List.map (fun (name, path) -> name, interp path) hyp_paths in
146 match wanted with None -> None | Some x -> Some (text,prefix_len,x)
148 (wanted, hyp_paths, goal_path)
151 let disambiguate_reduction_kind text prefix_len lexicon_status_ref = function
152 | `Unfold (Some t) -> assert false (* MATITA 1.0 *)
156 | `Whd as kind -> kind
159 let disambiguate_auto_params
160 disambiguate_term metasenv context (oterms, params)
163 | None -> metasenv, (None, params)
165 let metasenv, terms =
167 (fun t (metasenv, terms) ->
168 let metasenv,t = disambiguate_term context metasenv t in
169 metasenv,t::terms) terms (metasenv, [])
171 metasenv, (Some terms, params)
174 let disambiguate_just disambiguate_term context metasenv =
177 let metasenv,t = disambiguate_term context metasenv t in
180 let metasenv,params = disambiguate_auto_params disambiguate_term metasenv
183 metasenv, `Auto params
186 let disambiguate_nobj estatus ?baseuri (text,prefix_len,obj) =
189 match baseuri with Some x -> x | None -> raise BaseUriNotSetYet
193 | NotationPt.Inductive (_,(name,_,_,_)::_)
194 | NotationPt.Record (_,name,_,_) -> name ^ ".ind"
195 | NotationPt.Theorem (_,name,_,_,_) -> name ^ ".con"
196 | NotationPt.Inductive _ -> assert false
198 NUri.uri_of_string (baseuri ^ "/" ^ name)
200 let diff, _, _, cic =
202 (NCicDisambiguate.disambiguate_obj
203 ~lookup_in_library:nlookup_in_library
204 ~description_of_alias:LexiconAst.description_of_alias
205 ~mk_choice:ncic_mk_choice
206 ~mk_implicit ~fix_instance
209 ~aliases:estatus#lstatus.LexiconEngine.aliases
210 ~universe:(Some estatus#lstatus.LexiconEngine.multi_aliases)
211 (text,prefix_len,obj)) in
212 let estatus = LexiconEngine.set_proof_aliases estatus diff in
216 let disambiguate_command estatus ?baseuri (text,prefix_len,cmd)=
218 | GrafiteAst.Include _
220 | GrafiteAst.Set _ as cmd ->