| Symbol (s, _) -> s
| Num i -> string_of_int i
-type 'a test_result =
- | Ok of 'a * Cic.metasenv
+type ('a,'m) test_result =
+ | Ok of 'a * 'm
| Ko of Stdpp.location option * string Lazy.t
| Uncertain of Stdpp.location option * string Lazy.t
in
aux 1 context
-let interpretate_term ?(create_dummy_ids=false) ~(context: Cic.name list) ~env ~uri ~is_path ast
+let interpretate_term ?(create_dummy_ids=false) ~context ~env ~uri ~is_path ast
~localization_tbl
=
(* create_dummy_ids shouldbe used only for interpretating patterns *)
assert (uri = None);
- let rec aux ~localize loc (context: Cic.name list) = function
+ let rec aux ~localize loc context = function
| CicNotationPt.AttributedTerm (`Loc loc, term) ->
let res = aux ~localize loc context term in
if localize then Cic.CicHash.add localization_tbl res loc;
| CicNotationPt.Sort `Prop -> Cic.Sort Cic.Prop
| CicNotationPt.Sort `Set -> Cic.Sort Cic.Set
| CicNotationPt.Sort (`Type u) -> Cic.Sort (Cic.Type u)
- | CicNotationPt.Sort `CProp -> Cic.Sort Cic.CProp
+ | CicNotationPt.Sort (`CProp u) -> Cic.Sort (Cic.CProp u)
| CicNotationPt.Symbol (symbol, instance) ->
resolve env (Symbol (symbol, instance)) ()
| _ -> assert false (* god bless Bologna *)
- and aux_option ~localize loc (context: Cic.name list) annotation = function
+ and aux_option ~localize loc context annotation = function
| None -> Cic.Implicit annotation
| Some term -> aux ~localize loc context term
in
| Some bo,_ ->
let bo' = Some (interpretate_term [] env None false bo) in
Cic.Constant (name,bo',ty',[],attrs))
+;;
+
+let interpretate_term ?(create_dummy_ids=false) ~context ~env ~uri ~is_path ast
+ ~localization_tbl
+=
+ let context = List.map (function None -> Cic.Anonymous | Some (n,_) -> n) context in
+interpretate_term ~create_dummy_ids ~context ~env ~uri ~is_path ast
+~localization_tbl
+;;
+
let rec domain_of_term ?(loc = HExtlib.dummy_floc) ~context = function
| Ast.AttributedTerm (`Loc loc, term) ->
uniq_domain (domain_of_term ~context term)
let domain_of_obj ~context ast =
+ let context = List.map (function None -> Cic.Anonymous | Some (n,_) -> n) context in
assert (context = []);
match ast with
| Ast.Theorem (_,_,ty,bo) ->
let domain_of_obj ~context obj =
uniq_domain (domain_of_obj ~context obj)
+let domain_of_ast_term = domain_of_term;;
+
+let domain_of_term ~context term =
+ let context =
+ List.map (function None -> Cic.Anonymous | Some (n,_) -> n) context
+ in
+ domain_of_term ~context term
+
(* dom1 \ dom2 *)
let domain_diff dom1 dom2 =
(* let domain_diff = Domain.diff *)
module type Disambiguator =
sig
+ val disambiguate_thing:
+ dbd:HSql.dbd ->
+ context:'context ->
+ metasenv:'metasenv ->
+ initial_ugraph:'ugraph ->
+ hint: ('metasenv -> 'raw_thing -> 'raw_thing) *
+ (('refined_thing,'metasenv) test_result -> 'ugraph ->
+ ('refined_thing,'metasenv) test_result * 'ugraph) ->
+ aliases:DisambiguateTypes.codomain_item DisambiguateTypes.Environment.t ->
+ universe:DisambiguateTypes.codomain_item list
+ DisambiguateTypes.Environment.t option ->
+ uri:'uri ->
+ pp_thing:('ast_thing -> string) ->
+ domain_of_thing:(context:'context -> 'ast_thing -> domain) ->
+ interpretate_thing:(context:'context ->
+ env:DisambiguateTypes.codomain_item
+ DisambiguateTypes.Environment.t ->
+ uri:'uri ->
+ is_path:bool -> 'ast_thing -> localization_tbl:'cichash -> 'raw_thing) ->
+ refine_thing:('metasenv ->
+ 'context ->
+ 'uri ->
+ 'raw_thing ->
+ 'ugraph -> localization_tbl:'cichash -> ('refined_thing,
+ 'metasenv) test_result * 'ugraph) ->
+ localization_tbl:'cichash ->
+ string * int * 'ast_thing ->
+ ((DisambiguateTypes.Environment.key * DisambiguateTypes.codomain_item)
+ list * 'metasenv * 'refined_thing * 'ugraph)
+ list * bool
+
val disambiguate_term :
?fresh_instances:bool ->
dbd:HSql.dbd ->
context:Cic.context ->
- metasenv:Cic.metasenv ->
+ metasenv:Cic.metasenv -> ?goal:int ->
?initial_ugraph:CicUniv.universe_graph ->
aliases:DisambiguateTypes.environment ->(* previous interpretation status *)
universe:DisambiguateTypes.multiple_environment option ->
let refine_profiler = HExtlib.profile "disambiguate_thing.refine_thing"
let disambiguate_thing ~dbd ~context ~metasenv
- ?(initial_ugraph = CicUniv.oblivion_ugraph) ~aliases ~universe
+ ~initial_ugraph ~hint
+ ~aliases ~universe
~uri ~pp_thing ~domain_of_thing ~interpretate_thing ~refine_thing
+ ~localization_tbl
(thing_txt,thing_txt_prefix_len,thing)
=
debug_print (lazy "DISAMBIGUATE INPUT");
- let disambiguate_context = (* cic context -> disambiguate context *)
- List.map
- (function None -> Cic.Anonymous | Some (name, _) -> name)
- context
- in
debug_print (lazy ("TERM IS: " ^ (pp_thing thing)));
- let thing_dom = domain_of_thing ~context:disambiguate_context thing in
+ let thing_dom = domain_of_thing ~context thing in
debug_print
(lazy (sprintf "DISAMBIGUATION DOMAIN: %s"(string_of_domain thing_dom)));
(*
aux (aux env l) tl in
let filled_env = aux aliases todo_dom in
try
- let localization_tbl = Cic.CicHash.create 503 in
let cic_thing =
- interpretate_thing ~context:disambiguate_context ~env:filled_env
+ interpretate_thing ~context ~env:filled_env
~uri ~is_path:false thing ~localization_tbl
in
+ let cic_thing = (fst hint) metasenv cic_thing in
let foo () =
let k,ugraph1 =
refine_thing metasenv context uri cic_thing ugraph ~localization_tbl
in
+ let k, ugraph1 = (snd hint) k ugraph1 in
(k , ugraph1 )
in refine_profiler.HExtlib.profile foo ()
with
CicEnvironment.CircularDependency s ->
failwith "Disambiguate: circular dependency"
- let disambiguate_term ?(fresh_instances=false) ~dbd ~context ~metasenv
+ let disambiguate_term ?(fresh_instances=false) ~dbd ~context ~metasenv
+ ?goal
?(initial_ugraph = CicUniv.oblivion_ugraph) ~aliases ~universe
(text,prefix_len,term)
=
let term =
if fresh_instances then CicNotationUtil.freshen_term term else term
in
+ let hint = match goal with
+ | None -> (fun _ x -> x), fun k u -> k, u
+ | Some i ->
+ (fun metasenv t ->
+ let _,c,ty = CicUtil.lookup_meta i metasenv in
+ assert(c=context);
+ Cic.Cast(t,ty)),
+ function
+ | Ok (t,m) -> fun ug ->
+ (match t with
+ | Cic.Cast(t,_) -> Ok (t,m), ug
+ | _ -> assert false)
+ | k -> fun ug -> k, ug
+ in
+ let localization_tbl = Cic.CicHash.create 503 in
disambiguate_thing ~dbd ~context ~metasenv ~initial_ugraph ~aliases
~universe ~uri:None ~pp_thing:CicNotationPp.pp_term
~domain_of_thing:domain_of_term
~interpretate_thing:(interpretate_term (?create_dummy_ids:None))
~refine_thing:refine_term (text,prefix_len,term)
+ ~localization_tbl
+ ~hint
let disambiguate_obj ?(fresh_instances=false) ~dbd ~aliases ~universe ~uri
(text,prefix_len,obj)
let obj =
if fresh_instances then CicNotationUtil.freshen_obj obj else obj
in
- disambiguate_thing ~dbd ~context:[] ~metasenv:[] ~aliases ~universe ~uri
+ let hint =
+ (fun _ x -> x),
+ fun k u -> k, u
+ in
+ let localization_tbl = Cic.CicHash.create 503 in
+ disambiguate_thing ~dbd ~context:[] ~metasenv:[]
+ ~aliases ~universe ~uri
~pp_thing:(CicNotationPp.pp_obj CicNotationPp.pp_term) ~domain_of_thing:domain_of_obj
+ ~initial_ugraph:CicUniv.empty_ugraph
~interpretate_thing:interpretate_obj ~refine_thing:refine_obj
+ ~localization_tbl
+ ~hint
(text,prefix_len,obj)
+
end
+