1 (* Title: doc-src/more_antiquote.ML
2 Author: Florian Haftmann, TU Muenchen
7 signature MORE_ANTIQUOTE =
9 val setup: theory -> theory
12 structure More_Antiquote : MORE_ANTIQUOTE =
15 (* code theorem antiquotation *)
19 fun pretty_term ctxt t = Syntax.pretty_term (Variable.auto_fixes t ctxt) t;
21 fun pretty_thm ctxt = pretty_term ctxt o Thm.full_prop_of;
23 fun no_vars ctxt thm =
25 val ctxt' = Variable.set_body false ctxt;
26 val ((_, [thm]), _) = Variable.import true [thm] ctxt';
29 fun pretty_code_thm src ctxt raw_const =
31 val thy = Proof_Context.theory_of ctxt;
32 val const = Code.check_const thy raw_const;
33 val (_, eqngr) = Code_Preproc.obtain true thy [const] [];
34 fun holize thm = @{thm meta_eq_to_obj_eq} OF [thm];
35 val thms = Code_Preproc.cert eqngr const
36 |> Code.equations_of_cert thy
38 |> map_filter (fn (_, (some_thm, proper)) => if proper then some_thm else NONE)
39 |> map (holize o no_vars ctxt o AxClass.overload thy);
40 in Thy_Output.output ctxt (Thy_Output.maybe_pretty_source pretty_thm ctxt src thms) end;
45 Thy_Output.antiquotation @{binding code_thms} Args.term
46 (fn {source, context, ...} => pretty_code_thm source context);