(* $Id$ *)
-exception Drop
(* mo file name, ma file name *)
exception NMacro of GrafiteAst.loc * GrafiteAst.nmacro
let eval_unification_hint status t n =
let metasenv,subst,status,t =
- GrafiteDisambiguate.disambiguate_nterm None status [] [] [] ("",0,t) in
+ GrafiteDisambiguate.disambiguate_nterm status None [] [] [] ("",0,t) in
assert (metasenv=[]);
let t = NCicUntrusted.apply_subst subst [] t in
let status = basic_eval_unification_hint (t,n) status in
let dump = inject_unification_hint (t,n)::status#dump in
let status = status#set_dump dump in
- status,[]
+ status
;;
let basic_index_obj l status =
status#auto_cache l)
;;
+let basic_eval_interpretation (dsc, (symbol, args), cic_appl_pattern) status =
+ let status =
+ Interpretations.add_interpretation status dsc (symbol, args) cic_appl_pattern
+ in
+ let mode = GrafiteAst.WithPreferences (*assert false*) in (* MATITA 1.0 VEDI SOTTO *)
+ let diff =
+ [DisambiguateTypes.Symbol (symbol, 0), GrafiteAst.Symbol_alias (symbol,0,dsc)]
+ in
+ GrafiteDisambiguate.set_proof_aliases status ~implicit_aliases:false mode diff
+;;
+
+let inject_interpretation =
+ let basic_eval_interpretation (dsc, (symbol, args), cic_appl_pattern)
+ ~refresh_uri_in_universe ~refresh_uri_in_term
+ =
+ let rec refresh =
+ function
+ NotationPt.NRefPattern (NReference.Ref (uri,spec)) ->
+ NotationPt.NRefPattern
+ (NReference.reference_of_spec (NCicLibrary.refresh_uri uri) spec)
+ | NotationPt.VarPattern _
+ | NotationPt.ImplicitPattern as x -> x
+ | NotationPt.ApplPattern l -> NotationPt.ApplPattern (List.map refresh l)
+ in
+ let cic_appl_pattern = refresh cic_appl_pattern in
+ basic_eval_interpretation (dsc, (symbol, args), cic_appl_pattern)
+ in
+ GrafiteTypes.Serializer.register#run "interpretation"
+ basic_eval_interpretation
+;;
+
+let eval_interpretation status data=
+ let status = basic_eval_interpretation data status in
+ let dump = inject_interpretation data::status#dump in
+ status#set_dump dump
+;;
+
+let basic_eval_alias (mode,diff) status =
+ GrafiteDisambiguate.set_proof_aliases status ~implicit_aliases:false mode diff
+;;
+
+let inject_alias =
+ let basic_eval_alias (mode,diff) ~refresh_uri_in_universe ~refresh_uri_in_term=
+ basic_eval_alias (mode,diff)
+ in
+ GrafiteTypes.Serializer.register#run "alias" basic_eval_alias
+;;
+
+let eval_alias status data=
+ let status = basic_eval_alias data status in
+ let dump = inject_alias data::status#dump in
+ status#set_dump dump
+;;
+
+let basic_eval_input_notation (l1,l2) status =
+ GrafiteParser.extend status l1
+ (fun env loc ->
+ NotationPt.AttributedTerm
+ (`Loc loc,TermContentPres.instantiate_level2 env l2))
+;;
+
+let inject_input_notation =
+ let basic_eval_input_notation (l1,l2)
+ ~refresh_uri_in_universe ~refresh_uri_in_term
+ =
+ let l1 = CicNotationParser.refresh_uri_in_checked_l1_pattern l1 in
+ let l2 = NotationUtil.refresh_uri_in_term l2 in
+ basic_eval_input_notation (l1,l2)
+ in
+ GrafiteTypes.Serializer.register#run "input_notation"
+ basic_eval_input_notation
+;;
+
+let eval_input_notation status data=
+ let status = basic_eval_input_notation data status in
+ let dump = inject_input_notation data::status#dump in
+ status#set_dump dump
+;;
+
+let basic_eval_output_notation (l1,l2) status =
+ TermContentPres.add_pretty_printer status l2 l1
+;;
+
+let inject_output_notation =
+ let basic_eval_output_notation (l1,l2)
+ ~refresh_uri_in_universe ~refresh_uri_in_term
+ =
+ let l1 = CicNotationParser.refresh_uri_in_checked_l1_pattern l1 in
+ let l2 = NotationUtil.refresh_uri_in_term l2 in
+ basic_eval_output_notation (l1,l2)
+ in
+ GrafiteTypes.Serializer.register#run "output_notation"
+ basic_eval_output_notation
+;;
+
+let eval_output_notation status data=
+ let status = basic_eval_output_notation data status in
+ let dump = inject_output_notation data::status#dump in
+ status#set_dump dump
+;;
+
let record_index_obj =
let aux l
~refresh_uri_in_universe
let status = basic_eval_add_constraint (u1,u2) status in
let dump = inject_constraint (u1,u2)::status#dump in
let status = status#set_dump dump in
- status,[]
+ status
;;
let eval_ng_tac tac =
;;
-let rec eval_ncommand opts status (text,prefix_len,cmd) =
+let rec eval_ncommand ~include_paths opts status (text,prefix_len,cmd) =
match cmd with
+ | GrafiteAst.Include (loc, mode, fname) ->
+ let _root, baseuri, _fullpath, _rrelpath =
+ Librarian.baseuri_of_script ~include_paths fname in
+ let status,obj =
+ GrafiteTypes.Serializer.require ~baseuri:(NUri.uri_of_string baseuri)
+ status in
+ let status = status#set_dump (obj::status#dump) in
+ (*assert false;*) (* MATITA 1.0mode must be passed to GrafiteTypes.Serializer.require
+ somehow *)
+ status
| GrafiteAst.UnificationHint (loc, t, n) -> eval_unification_hint status t n
| GrafiteAst.NCoercion (loc, name, t, ty, source, target) ->
+ let status, composites =
NCicCoercDeclaration.eval_ncoercion status name t ty source target
+ in
+ GrafiteDisambiguate.add_aliases_for_objs status composites
| GrafiteAst.NQed loc ->
if status#ng_mode <> `ProofMode then
raise (GrafiteTypes.Command_error "Not in proof mode")
let uris = uri::List.rev uris_rev in
*)
let status = status#set_ng_mode `CommandMode in
- let status = LexiconSync.add_aliases_for_objs status [uri] in
- let status,uris =
+ let status = GrafiteDisambiguate.add_aliases_for_objs status [uri] in
+ let status =
List.fold_left
- (fun (status,uris) boxml ->
+ (fun status boxml ->
try
- let nstatus,nuris =
- eval_ncommand opts status
+ let nstatus =
+ eval_ncommand ~include_paths opts status
("",0,GrafiteAst.NObj (HExtlib.dummy_floc,boxml))
in
if nstatus#ng_mode <> `CommandMode then
begin
(*HLog.warn "error in generating projection/eliminator";*)
assert(status#ng_mode = `CommandMode);
- status, uris
+ status
end
else
- nstatus, uris@nuris
+ nstatus
with
| MultiPassDisambiguator.DisambiguationError _
| NCicTypeChecker.TypeCheckerFailure _ ->
(*HLog.warn "error in generating projection/eliminator";*)
- status,uris
- ) (status,[] (* uris *)) boxml in
+ status
+ ) status boxml in
let _,_,_,_,nobj = obj in
let status = match nobj with
NCic.Inductive (is_ind,leftno,[it],_) ->
(snd (NCicElim.ast_of_sort outsort)))
is_ind it leftno outsort status status#baseuri in
let _,_,menv,_,_ = invobj in
- fst (match menv with
- [] -> eval_ncommand opts status ("",0,GrafiteAst.NQed Stdpp.dummy_loc)
- | _ -> status,[]))
+ (match menv with
+ [] -> eval_ncommand ~include_paths opts status
+ ("",0,GrafiteAst.NQed Stdpp.dummy_loc)
+ | _ -> status))
(* XXX *)
with _ -> (*HLog.warn "error in generating inversion principle"; *)
let status = status#set_ng_mode `CommandMode in status)
(fun (name,is_coercion,arity) ->
if is_coercion then Some(name,leftno,arity) else None) fields
| _ -> [] in
- let status,uris =
+ let status =
List.fold_left
- (fun (status,uris) (name,cpos,arity) ->
+ (fun status (name,cpos,arity) ->
try
let metasenv,subst,status,t =
- GrafiteDisambiguate.disambiguate_nterm None status [] [] []
+ GrafiteDisambiguate.disambiguate_nterm status None [] [] []
("",0,NotationPt.Ident (name,None)) in
assert (metasenv = [] && subst = []);
let status, nuris =
basic_eval_and_record_ncoercion_from_t_cpos_arity
status (name,t,cpos,arity)
in
- let uris = nuris@uris in
- status, uris
+ GrafiteDisambiguate.add_aliases_for_objs status nuris
with MultiPassDisambiguator.DisambiguationError _->
HLog.warn ("error in generating coercion: "^name);
- status, uris)
- (status,uris) coercions
+ status)
+ status coercions
in
- status,uris
+ status
with
exn ->
NCicLibrary.time_travel old_status;
let status = status#set_stack ninitial_stack in
let status = subst_metasenv_and_fix_names status in
let status = status#set_ng_mode `ProofMode in
- eval_ncommand opts status ("",0,GrafiteAst.NQed Stdpp.dummy_loc)
+ eval_ncommand ~include_paths opts status ("",0,GrafiteAst.NQed Stdpp.dummy_loc)
| GrafiteAst.NObj (loc,obj) ->
if status#ng_mode <> `CommandMode then
raise (GrafiteTypes.Command_error "Not in command mode")
let status = status#set_ng_mode `ProofMode in
(match nmenv with
[] ->
- eval_ncommand opts status ("",0,GrafiteAst.NQed Stdpp.dummy_loc)
- | _ -> status,[])
+ eval_ncommand ~include_paths opts status ("",0,GrafiteAst.NQed Stdpp.dummy_loc)
+ | _ -> status)
| GrafiteAst.NDiscriminator (_,_) -> assert false (*(loc, indty) ->
if status#ng_mode <> `CommandMode then
raise (GrafiteTypes.Command_error "Not in command mode")
let status,obj = NDestructTac.mk_discriminator it status in
let _,_,menv,_,_ = obj in
(match menv with
- [] -> eval_ncommand opts status ("",0,GrafiteAst.NQed Stdpp.dummy_loc)
+ [] -> eval_ncommand ~include_paths opts status ("",0,GrafiteAst.NQed Stdpp.dummy_loc)
| _ -> prerr_endline ("Discriminator: non empty metasenv");
status, []) *)
| GrafiteAst.NInverter (loc, name, indty, selection, sort) ->
else
let metasenv,subst,status,sort = match sort with
| None -> [],[],status,NCic.Sort NCic.Prop
- | Some s -> GrafiteDisambiguate.disambiguate_nterm None status [] [] []
- (text,prefix_len,s)
+ | Some s ->
+ GrafiteDisambiguate.disambiguate_nterm status None [] [] []
+ (text,prefix_len,s)
in
assert (metasenv = []);
let sort = NCicReduction.whd ~subst [] sort in
- let sort = match sort with
+ let sort =
+ match sort with
NCic.Sort s -> s
- | _ -> raise (Invalid_argument (Printf.sprintf "ninverter: found target %s, which is not a sort"
- (NCicPp.ppterm ~metasenv ~subst ~context:[] sort)))
- in
+ | _ ->
+ raise (Invalid_argument (Printf.sprintf
+ "ninverter: found target %s, which is not a sort"
+ (NCicPp.ppterm ~metasenv ~subst ~context:[] sort))) in
let status = status#set_ng_mode `ProofMode in
let metasenv,subst,status,indty =
- GrafiteDisambiguate.disambiguate_nterm None status [] [] subst (text,prefix_len,indty) in
- let indtyno,(_,leftno,tys,_,_) = match indty with
- NCic.Const ((NReference.Ref (_,NReference.Ind (_,indtyno,_))) as r) ->
- indtyno, NCicEnvironment.get_checked_indtys r
- | _ -> prerr_endline ("engine: indty =" ^ NCicPp.ppterm ~metasenv:[] ~subst:[] ~context:[] indty) ; assert false in
+ GrafiteDisambiguate.disambiguate_nterm status None [] [] subst
+ (text,prefix_len,indty) in
+ let indtyno,(_,leftno,tys,_,_) =
+ match indty with
+ NCic.Const ((NReference.Ref (_,NReference.Ind (_,indtyno,_))) as r) ->
+ indtyno, NCicEnvironment.get_checked_indtys r
+ | _ ->
+ prerr_endline ("engine: indty =" ^ NCicPp.ppterm ~metasenv:[]
+ ~subst:[] ~context:[] indty);
+ assert false in
let it = List.nth tys indtyno in
- let status,obj = NInversion.mk_inverter name true it leftno ?selection sort
- status status#baseuri in
- let _,_,menv,_,_ = obj in
- (match menv with
- [] ->
- eval_ncommand opts status ("",0,GrafiteAst.NQed Stdpp.dummy_loc)
- | _ -> assert false)
+ let status,obj =
+ NInversion.mk_inverter name true it leftno ?selection sort
+ status status#baseuri in
+ let _,_,menv,_,_ = obj in
+ (match menv with
+ [] ->
+ eval_ncommand ~include_paths opts status
+ ("",0,GrafiteAst.NQed Stdpp.dummy_loc)
+ | _ -> assert false)
| GrafiteAst.NUnivConstraint (loc,u1,u2) ->
eval_add_constraint status [`Type,u1] [`Type,u2]
+ (* ex lexicon commands *)
+ | GrafiteAst.Interpretation (loc, dsc, (symbol, args), cic_appl_pattern) ->
+ let cic_appl_pattern =
+ GrafiteDisambiguate.disambiguate_cic_appl_pattern status args
+ cic_appl_pattern
+ in
+ eval_interpretation status (dsc,(symbol, args),cic_appl_pattern)
+ | GrafiteAst.Notation (loc, dir, l1, associativity, precedence, l2) ->
+ let l1 =
+ CicNotationParser.check_l1_pattern
+ l1 (dir = Some `RightToLeft) precedence associativity
+ in
+ let status =
+ if dir <> Some `RightToLeft then eval_input_notation status (l1,l2)
+ else status
+ in
+ if dir <> Some `LeftToRight then eval_output_notation status (l1,l2)
+ else status
+ | GrafiteAst.Alias (loc, spec) ->
+ let diff =
+ (*CSC: Warning: this code should be factorized with the corresponding
+ code in DisambiguatePp *)
+ match spec with
+ | GrafiteAst.Ident_alias (id,uri) ->
+ [DisambiguateTypes.Id id,spec]
+ | GrafiteAst.Symbol_alias (symb, instance, desc) ->
+ [DisambiguateTypes.Symbol (symb,instance),spec]
+ | GrafiteAst.Number_alias (instance,desc) ->
+ [DisambiguateTypes.Num instance,spec]
+ in
+ let mode = GrafiteAst.WithPreferences in(*assert false in (* VEDI SOPRA *) MATITA 1.0*)
+ eval_alias status (mode,diff)
;;
-let eval_comment ~disambiguate_command opts status (text,prefix_len,c) =
- status, []
-
-let rec eval_command ~disambiguate_command opts status (text,prefix_len,cmd) =
- let status,cmd = disambiguate_command status (text,prefix_len,cmd) in
- let status,uris =
- match cmd with
- | GrafiteAst.Include (loc, baseuri) ->
- let status,obj =
- GrafiteTypes.Serializer.require ~baseuri:(NUri.uri_of_string baseuri)
- status in
- let status = status#set_dump (obj::status#dump) in
- status,[]
- | GrafiteAst.Print (_,_) -> status,[]
- | GrafiteAst.Set (loc, name, value) -> status, []
- in
- status,uris
+let eval_comment opts status (text,prefix_len,c) = status
-and eval_executable ~disambiguate_command opts status (text,prefix_len,ex) =
+let rec eval_executable ~include_paths opts status (text,prefix_len,ex) =
match ex with
| GrafiteAst.NTactic (_(*loc*), tacl) ->
if status#ng_mode <> `ProofMode then
subst_metasenv_and_fix_names status)
status tacl
in
- status,[]
- | GrafiteAst.Command (_, cmd) ->
- eval_command ~disambiguate_command opts status (text,prefix_len,cmd)
+ status
| GrafiteAst.NCommand (_, cmd) ->
- eval_ncommand opts status (text,prefix_len,cmd)
+ eval_ncommand ~include_paths opts status (text,prefix_len,cmd)
| GrafiteAst.NMacro (loc, macro) ->
raise (NMacro (loc,macro))
-and eval_ast ~disambiguate_command ?(do_heavy_checks=false) status
-(text,prefix_len,st)
+and eval_ast ~include_paths ?(do_heavy_checks=false) status (text,prefix_len,st)
=
let opts = { do_heavy_checks = do_heavy_checks ; } in
match st with
| GrafiteAst.Executable (_,ex) ->
- eval_executable ~disambiguate_command opts status (text,prefix_len,ex)
+ eval_executable ~include_paths opts status (text,prefix_len,ex)
| GrafiteAst.Comment (_,c) ->
- eval_comment ~disambiguate_command opts status (text,prefix_len,c)
+ eval_comment opts status (text,prefix_len,c)
;;