(* implement module's API *)
-let disambiguate_thing ~aliases
- ~(f:?fresh_instances:bool -> aliases:Disambiguate.aliases -> 'a -> 'b)
+let disambiguate_thing ~aliases ~universe
+ ~(f:?fresh_instances:bool ->
+ aliases:DisambiguateTypes.environment ->
+ universe:DisambiguateTypes.multiple_environment option ->
+ 'a -> 'b)
~(set_aliases: DisambiguateTypes.environment -> 'b -> 'b)
(thing: 'a)
=
- let library = true, DisambiguateTypes.empty_environment in
- let multi_aliases = true, aliases in
- let mono_aliases = false, aliases in
+ assert (universe <> None);
+ let library = false, DisambiguateTypes.Environment.empty, None in
+ let multi_aliases=false, DisambiguateTypes.Environment.empty, universe in
+ let mono_aliases = true, aliases, None in
let passes = (* <fresh_instances?, aliases, coercions?> *)
[ (false, mono_aliases, false);
(false, multi_aliases, false);
(true, library, true);
]
in
- let try_pass (fresh_instances, aliases, use_coercions) =
+ let try_pass (fresh_instances, (_, aliases, universe), use_coercions) =
CoercDb.use_coercions := use_coercions;
- f ~fresh_instances ~aliases thing
+ f ~fresh_instances ~aliases ~universe thing
in
- let set_aliases (instances,(use_multi_aliases,_),_) (_, user_asked as res) =
- if not use_multi_aliases && not instances then
+ let set_aliases (instances,(use_mono_aliases,_,_),_) (_, user_asked as res) =
+ if use_mono_aliases && not instances then
res
else if user_asked then
res (* one shot aliases *)
(List.map (fun (_, a, b, c) -> aliases, a, b, c) choices),
user_asked
-let disambiguate_term ~dbd ~context ~metasenv ?initial_ugraph ~aliases term =
+let disambiguate_term ?fresh_instances ~dbd ~context ~metasenv ?initial_ugraph
+ ~aliases ~universe term
+ =
+ assert (fresh_instances = None);
let f =
Disambiguator.disambiguate_term ~dbd ~context ~metasenv ?initial_ugraph
in
- disambiguate_thing ~aliases ~f ~set_aliases term
+ disambiguate_thing ~aliases ~universe ~f ~set_aliases term
-let disambiguate_obj ~dbd ~aliases ~uri obj =
+let disambiguate_obj ?fresh_instances ~dbd ~aliases ~universe ~uri obj =
+ assert (fresh_instances = None);
let f = Disambiguator.disambiguate_obj ~dbd ~uri in
- disambiguate_thing ~aliases ~f ~set_aliases obj
+ disambiguate_thing ~aliases ~universe ~f ~set_aliases obj
(** for GUI callbacks see MatitaGui.interactive_{interp,user_uri}_choice *)
-val disambiguate_term :
- dbd:Mysql.dbd ->
- context:Cic.context ->
- metasenv:Cic.metasenv ->
- ?initial_ugraph:CicUniv.universe_graph ->
- aliases:DisambiguateTypes.environment -> (* previous interpretation status *)
- DisambiguateTypes.term ->
- (DisambiguateTypes.environment * (* new interpretation status *)
- Cic.metasenv * (* new metasenv *)
- Cic.term *
- CicUniv.universe_graph) list * (* disambiguated term *)
- bool (* has interactive_interpretation_choice been invoked? *)
-
-(** @param fresh_instances as per disambiguate_term *)
-val disambiguate_obj :
- dbd:Mysql.dbd ->
- aliases:DisambiguateTypes.environment -> (* previous interpretation status *)
- uri:UriManager.uri option -> (* required only for inductive types *)
- GrafiteAst.obj ->
- (DisambiguateTypes.environment * (* new interpretation status *)
- Cic.metasenv * (* new metasenv *)
- Cic.obj *
- CicUniv.universe_graph) list * (* disambiguated obj *)
- bool (* has interactive_interpretation_choice been invoked? *)
-
+include Disambiguate.Disambiguator
let (aliases, metasenv, cic, _) =
singleton
(MatitaDisambiguator.disambiguate_term ~dbd:(MatitaDb.instance ())
- ~aliases:(status.aliases) ~context:(MatitaMisc.get_proof_context status)
+ ~aliases:status.aliases ~universe:(Some status.multi_aliases)
+ ~context:(MatitaMisc.get_proof_context status)
~metasenv:(MatitaMisc.get_proof_metasenv status) term)
in
let status = MatitaTypes.set_metasenv metasenv status in
let (aliases, metasenv, cic, ugraph) =
singleton
(MatitaDisambiguator.disambiguate_term ~dbd:(MatitaDb.instance ())
- ~initial_ugraph:ugraph ~aliases:status.aliases ~context ~metasenv
- term)
+ ~initial_ugraph:ugraph ~aliases:status.aliases
+ ~universe:(Some status.multi_aliases) ~context ~metasenv term)
in
let status = MatitaTypes.set_metasenv metasenv status in
let status = MatitaSync.set_proof_aliases status aliases in
let (aliases, metasenv, cic, _) =
singleton
(MatitaDisambiguator.disambiguate_obj ~dbd:(MatitaDb.instance ())
- ~aliases:(status.aliases) ~uri obj)
+ ~aliases:status.aliases ~universe:(Some status.multi_aliases) ~uri obj)
in
let proof_status =
match status.proof_status with
code in DisambiguatePp *)
match spec with
| GrafiteAst.Ident_alias (id,uri) ->
- DisambiguateTypes.Environment.cons
+ DisambiguateTypes.Environment.add
(DisambiguateTypes.Id id)
(uri,(fun _ _ _-> CicUtil.term_of_uri (UriManager.uri_of_string uri)))
status.aliases
| GrafiteAst.Symbol_alias (symb, instance, desc) ->
- DisambiguateTypes.Environment.cons
+ DisambiguateTypes.Environment.add
(DisambiguateTypes.Symbol (symb,instance))
(DisambiguateChoices.lookup_symbol_by_dsc symb desc)
status.aliases
| GrafiteAst.Number_alias (instance,desc) ->
- DisambiguateTypes.Environment.cons
+ DisambiguateTypes.Environment.add
(DisambiguateTypes.Num instance)
(DisambiguateChoices.lookup_num_by_dsc desc) status.aliases
in
| GrafiteAst.Interpretation (_, dsc, (symbol, _), _) as stm ->
let status' = add_moo_content [stm] status in
let aliases' =
- DisambiguateTypes.Environment.cons
+ DisambiguateTypes.Environment.add
(DisambiguateTypes.Symbol (symbol, 0))
(DisambiguateChoices.lookup_symbol_by_dsc symbol dsc)
status.aliases
let initial_status =
lazy {
- aliases = DisambiguateTypes.empty_environment;
+ aliases = DisambiguateTypes.Environment.empty;
+ multi_aliases = DisambiguateTypes.Environment.empty;
moo_content_rev = [];
proof_status = No_proof;
options = default_options ();
conclusion
| _ -> statement_error "no ongoing proof"
-let get_proof_aliases status = status.aliases
-
let qualify status name = get_string_option status "baseuri" ^ "/" ^ name
let unopt = function None -> failwith "unopt: None" | Some v -> v
val get_proof_metasenv: MatitaTypes.status -> Cic.metasenv
val get_proof_context: MatitaTypes.status -> Cic.context
val get_proof_conclusion: MatitaTypes.status -> Cic.term
-val get_proof_aliases: MatitaTypes.status -> DisambiguateTypes.environment
(** given the base name of an image, returns its full path *)
val image_path: string -> string
let initial_space,status,new_status_and_text_list_rev =
let module DTE = DisambiguateTypes.Environment in
let module UM = UriManager in
- DTE.fold_flatten (
+ DTE.fold (
fun k ((v,_) as value) (initial_space,status,acc) ->
let b =
try
let initial_space =
if initial_space = "" then "\n" else initial_space in
initial_space ^
- DisambiguatePp.pp_environment(DTE.cons k value DTE.empty) in
+ DisambiguatePp.pp_environment(DTE.add k value DTE.empty) in
let new_status =
- {status with aliases = DTE.cons k value status.aliases}
+ MatitaSync.set_proof_aliases status (DTE.add k value status.aliases)
in
"\n",new_status,((new_status, new_text)::acc)
) new_aliases (initial_space,status,[]) in
let dbd = MatitaDb.instance () in
let metasenv = MatitaMisc.get_proof_metasenv status in
let context = MatitaMisc.get_proof_context status in
- let aliases = MatitaMisc.get_proof_aliases status in
- let interps = MD.disambiguate_term dbd context metasenv aliases term in
+ let interps =
+ MD.disambiguate_term ~dbd ~context ~metasenv ~aliases:status.aliases
+ ~universe:(Some status.multi_aliases) term in
match interps with
| [_,_,x,_], _ -> x
| _ -> assert false
| TA.Check (_,term) ->
let metasenv = MatitaMisc.get_proof_metasenv status in
let context = MatitaMisc.get_proof_context status in
- let aliases = MatitaMisc.get_proof_aliases status in
let interps =
- MatitaDisambiguator.disambiguate_term
- dbd context metasenv aliases term
+ MatitaDisambiguator.disambiguate_term ~dbd ~context ~metasenv
+ ~aliases:status.aliases ~universe:(Some status.multi_aliases) term
in
let _, metasenv , term, ugraph =
match interps with
let alias_diff ~from status =
let module Map = DisambiguateTypes.Environment in
- Map.fold_flatten
+ Map.fold
(fun domain_item codomain_item acc ->
if not (Map.mem domain_item from.aliases) then
- Map.cons domain_item codomain_item acc
+ Map.add domain_item codomain_item acc
else
begin
try
- let codomain1 = Map.find domain_item from.aliases in
- let codomain2 = Map.find domain_item status.aliases in
- List.fold_right
- (fun item env ->
- let dsc = fst item in
- if not (List.exists (fun (dsc', _) -> dsc'=dsc) codomain1) then
- Map.cons domain_item codomain_item env
- else
- env)
- codomain2 acc
+ let description1 = fst(Map.find domain_item from.aliases) in
+ let description2 = fst(Map.find domain_item status.aliases) in
+ if description1 <> description2 then
+ Map.add domain_item codomain_item acc
+ else
+ acc
with Not_found -> acc
end)
status.aliases Map.empty
let set_proof_aliases status aliases =
let new_status = { status with aliases = aliases } in
let diff = alias_diff ~from:status new_status in
+ let multi_aliases =
+ DisambiguateTypes.Environment.fold DisambiguateTypes.Environment.cons
+ diff status.multi_aliases in
+ let new_status = { new_status with multi_aliases = multi_aliases } in
if DisambiguateTypes.Environment.is_empty diff then
new_status
else
type status = {
aliases: DisambiguateTypes.environment;
+ multi_aliases: DisambiguateTypes.multiple_environment;
moo_content_rev: ast_command list;
proof_status: proof_status;
options: options;
type status = {
aliases: DisambiguateTypes.environment; (** disambiguation aliases *)
+ multi_aliases: DisambiguateTypes.multiple_environment;
moo_content_rev: ast_command list;
proof_status: proof_status;
options: options;