List.find (has_description dsc) !num_choices
with Not_found -> raise (Choice_not_found (lazy ("Num with dsc " ^ dsc)))
-let mk_choice (dsc, args, appl_pattern) =
+let mk_choice ~mk_appl ~mk_implicit ~term_of_uri (dsc, args, appl_pattern)=
dsc,
(fun env _ cic_args ->
let env',rest =
"The notation " ^ dsc ^ " expects more arguments")))
in
let combined =
- TermAcicContent.instantiate_appl_pattern env' appl_pattern
+ TermAcicContent.instantiate_appl_pattern
+ ~mk_appl ~mk_implicit ~term_of_uri env' appl_pattern
in
match rest with
[] -> combined
- | _::_ -> Cic.Appl (combined::rest))
+ | _::_ -> mk_appl (combined::rest))
-let lookup_symbol_by_dsc symbol dsc =
+let lookup_symbol_by_dsc ~mk_appl ~mk_implicit ~term_of_uri symbol dsc =
try
- mk_choice
+ mk_choice~mk_appl ~mk_implicit ~term_of_uri
(List.find
(fun (dsc', _, _) -> dsc = dsc')
(TermAcicContent.lookup_interpretations symbol))
with TermAcicContent.Interpretation_not_found | Not_found ->
raise (Choice_not_found (lazy (sprintf "Symbol %s, dsc %s" symbol dsc)))
+let cic_lookup_symbol_by_dsc = lookup_symbol_by_dsc
+ ~mk_implicit:(function
+ | true -> Cic.Implicit (Some `Type)
+ | false -> Cic.Implicit None)
+ ~mk_appl:(function (Cic.Appl l)::tl -> Cic.Appl (l@tl) | l -> Cic.Appl l)
+ ~term_of_uri:CicUtil.term_of_uri
+;;
in
HLog.debug debug; assert false
+let cic_codomain_of_uri uri =
+ (UriManager.string_of_uri uri,
+ let term =
+ try
+ CicUtil.term_of_uri uri
+ with exn ->
+ assert false
+ in
+ fun _ _ _ -> term)
+;;
+
+let cic_num_choices = DisambiguateChoices.lookup_num_choices;;
+
+let cic_mk_choice =
+ DisambiguateChoices.mk_choice
+ ~mk_implicit:(function
+ | true -> Cic.Implicit (Some `Type)
+ | false -> Cic.Implicit None)
+ ~mk_appl:(function (Cic.Appl l)::tl -> Cic.Appl (l@tl) | l -> Cic.Appl l)
+ ~term_of_uri:CicUtil.term_of_uri
+;;
+
+let ncic_codomain_of_uri uri =
+ (UriManager.string_of_uri uri,
+ let term =
+ try
+ fst (OCic2NCic.convert_term uri (CicUtil.term_of_uri uri))
+ with exn ->
+ assert false
+ in
+ fun _ _ _ -> term)
+;;
+
+let ncic_num_choices _ = assert false;;
-let lookup_in_library interactive_user_uri_choice input_or_locate_uri item =
+let ncic_mk_choice =
+ DisambiguateChoices.mk_choice
+ ~mk_implicit:(function
+ | true -> NCic.Implicit `Closed
+ | false -> NCic.Implicit `Term)
+ ~mk_appl:(function (NCic.Appl l)::tl -> NCic.Appl (l@tl) | l -> NCic.Appl l)
+ ~term_of_uri:(fun uri ->
+ fst (OCic2NCic.convert_term uri (CicUtil.term_of_uri uri)))
+;;
+
+let lookup_in_library
+ codomain_of_uri mk_choice num_choices
+ interactive_user_uri_choice input_or_locate_uri item
+=
let dbd = LibraryDb.instance () in
let choices_of_id id =
let uris = Whelp.locate ~dbd id in
- let uris =
match uris with
| [] ->
(match
"\". Please, choose one or more interpretations:")
~id
uris
- in
- List.map
- (fun uri ->
- (UriManager.string_of_uri uri,
- let term =
- try
- CicUtil.term_of_uri uri
- with exn ->
- assert false
- in
- fun _ _ _ -> term))
- uris
in
match item with
- | DisambiguateTypes.Id id -> choices_of_id id
+ | DisambiguateTypes.Id id ->
+ let uris = choices_of_id id in
+ List.map codomain_of_uri uris
| DisambiguateTypes.Symbol (symb, _) ->
(try
- List.map DisambiguateChoices.mk_choice
- (TermAcicContent.lookup_interpretations symb)
+ List.map mk_choice (TermAcicContent.lookup_interpretations symb)
with
TermAcicContent.Interpretation_not_found -> [])
- | DisambiguateTypes.Num instance ->
- DisambiguateChoices.lookup_num_choices ()
+ | DisambiguateTypes.Num instance -> num_choices ()
;;
(** @param term not meaningful when context is given *)
(CicDisambiguate.disambiguate_term
~aliases:lexicon_status.LexiconEngine.aliases
?goal ~universe:(Some lexicon_status.LexiconEngine.multi_aliases)
- ~lookup_in_library
+ ~lookup_in_library:(lookup_in_library cic_codomain_of_uri cic_mk_choice
+ cic_num_choices)
~context ~metasenv ~subst:[] (text,prefix_len,term))
in
let lexicon_status = LexiconEngine.set_proof_aliases lexicon_status diff in
let lexicon_status = !lexicon_status_ref in
let (diff, metasenv, _, cic, ugraph) =
singleton "second"
- (CicDisambiguate.disambiguate_term ~lookup_in_library
+ (CicDisambiguate.disambiguate_term
+ ~lookup_in_library:(lookup_in_library cic_codomain_of_uri
+ cic_mk_choice cic_num_choices)
~initial_ugraph:ugraph ~aliases:lexicon_status.LexiconEngine.aliases
~universe:(Some lexicon_status.LexiconEngine.multi_aliases)
~context ~metasenv ~subst:[] ?goal
| `Proof as t -> metasenv,t in
metasenv,GrafiteAst.RewritingStep (loc, cic, cic', cic'', cont)
-
let disambiguate_obj lexicon_status ?baseuri metasenv (text,prefix_len,obj) =
let uri =
match obj with
| None -> raise BaseUriNotSetYet)
| CicNotationPt.Inductive _ -> assert false
| CicNotationPt.Theorem _ -> None in
- (*
+(*
(match obj with
CicNotationPt.Theorem (_,_,ty,_) ->
(try
- let [_,_,_,ty],_ =
- NMultiPassDisambiguator.disambiguate_term
+ (match
+ NCicDisambiguate.disambiguate_term
+ ~lookup_in_library:(lookup_in_library ncic_codomain_of_uri
+ ncic_mk_choice ncic_num_choices)
~context:[] ~metasenv:[] ~subst:[]
~aliases:DisambiguateTypes.Environment.empty
~universe:(Some DisambiguateTypes.Environment.empty)
("",0,ty)
- in
+ with
+ | [_,metasenv,subst,ty],_ ->
prerr_endline ("NUOVA DISAMBIGUAZIONE OK!!!!!!!!! " ^
- NCicPp.ppterm ~metasenv:[] ~subst:[] ~context:[] ty)
- with NMultiPassDisambiguator.DisambiguationError _ ->
- prerr_endline "ERRORE NUOVA DISAMBIGUAZIONE";
- assert false
- | exn -> ())
+ NCicPp.ppterm ~metasenv ~subst ~context:[] ty)
+ | _ ->
+ prerr_endline ("NUOVA DISAMBIGUAZIONE AMBIGUO!!!!!!!!! "))
+ with
+ | MultiPassDisambiguator.DisambiguationError (_,s) ->
+ prerr_endline ("ERRORE NUOVA DISAMBIGUAZIONE:\n" ^
+ String.concat "\n"
+ (List.map (fun _,_,x,_ -> snd (Lazy.force x)) (List.flatten s)))
+(* | exn -> prerr_endline (Printexc.to_string exn) *)
+ )
| _ -> ()
- ); *)
+ );
+*)
let (diff, metasenv, _, cic, _) =
singleton "third"
- (CicDisambiguate.disambiguate_obj ~lookup_in_library
+ (CicDisambiguate.disambiguate_obj
+ ~lookup_in_library:(lookup_in_library cic_codomain_of_uri cic_mk_choice
+ cic_num_choices)
~aliases:lexicon_status.LexiconEngine.aliases
~universe:(Some lexicon_status.LexiconEngine.multi_aliases) ~uri
(text,prefix_len,obj)) in