10 type 'term expr = (string * ((string * bool) * 'term map)) list; |
10 type 'term expr = (string * ((string * bool) * 'term map)) list; |
11 type expression_i = term expr * (Binding.T * typ option * mixfix) list; |
11 type expression_i = term expr * (Binding.T * typ option * mixfix) list; |
12 type expression = string expr * (Binding.T * string option * mixfix) list; |
12 type expression = string expr * (Binding.T * string option * mixfix) list; |
13 |
13 |
14 (* Processing of context statements *) |
14 (* Processing of context statements *) |
|
15 val cert_statement: Element.context_i list -> (term * term list) list list -> |
|
16 Proof.context -> (term * term list) list list * Proof.context; |
15 val read_statement: Element.context list -> (string * string list) list list -> |
17 val read_statement: Element.context list -> (string * string list) list list -> |
16 Proof.context -> (term * term list) list list * Proof.context; |
18 Proof.context -> (term * term list) list list * Proof.context; |
17 val cert_statement: Element.context_i list -> (term * term list) list list -> |
|
18 Proof.context -> (term * term list) list list * Proof.context; |
|
19 |
19 |
20 (* Declaring locales *) |
20 (* Declaring locales *) |
21 val add_locale: bstring -> bstring -> expression_i -> Element.context_i list -> |
21 val add_locale: bstring -> bstring -> expression_i -> Element.context_i list -> |
22 theory -> string * local_theory; |
22 theory -> string * local_theory; |
23 val add_locale_cmd: bstring -> bstring -> expression -> Element.context list -> |
23 val add_locale_cmd: bstring -> bstring -> expression -> Element.context list -> |
24 theory -> string * local_theory; |
24 theory -> string * local_theory; |
25 |
25 |
26 (* Interpretation *) |
26 (* Interpretation *) |
|
27 val cert_goal_expression: expression_i -> Proof.context -> |
|
28 (term list list * (string * morphism) list * morphism) * Proof.context; |
|
29 |
27 val sublocale: string -> expression_i -> theory -> Proof.state; |
30 val sublocale: string -> expression_i -> theory -> Proof.state; |
28 val sublocale_cmd: string -> expression -> theory -> Proof.state; |
31 val sublocale_cmd: string -> expression -> theory -> Proof.state; |
29 val interpretation: expression_i -> (Attrib.binding * term) list -> |
32 val interpretation: expression_i -> (Attrib.binding * term) list -> |
30 theory -> Proof.state; |
33 theory -> Proof.state; |
31 val interpretation_cmd: expression -> (Attrib.binding * string) list -> |
34 val interpretation_cmd: expression -> (Attrib.binding * string) list -> |
738 fst |> |
741 fst |> |
739 map (Element.morph_ctxt b_satisfy) |> |
742 map (Element.morph_ctxt b_satisfy) |> |
740 map_filter (fn Notes notes => SOME notes | _ => NONE); |
743 map_filter (fn Notes notes => SOME notes | _ => NONE); |
741 |
744 |
742 val deps' = map (fn (l, morph) => (l, morph $> b_satisfy)) deps; |
745 val deps' = map (fn (l, morph) => (l, morph $> b_satisfy)) deps; |
|
746 val axioms = map Element.conclude_witness b_axioms; |
743 |
747 |
744 val loc_ctxt = thy' |
748 val loc_ctxt = thy' |
745 |> Locale.register_locale bname (extraTs, params) |
749 |> Locale.register_locale bname (extraTs, params) |
746 (asm, rev defs) ([], []) |
750 (asm, rev defs) (a_intro, b_intro) axioms ([], []) |
747 (map (fn n => (n, stamp ())) notes |> rev) (map (fn d => (d, stamp ())) deps' |> rev) |
751 (map (fn n => (n, stamp ())) notes |> rev) (map (fn d => (d, stamp ())) deps' |> rev) |
748 |> TheoryTarget.init (SOME name) |
752 |> TheoryTarget.init (SOME name) |
749 |> fold (fn (kind, facts) => LocalTheory.notes kind facts #> snd) notes'; |
753 |> fold (fn (kind, facts) => LocalTheory.notes kind facts #> snd) notes'; |
750 |
754 |
751 in (name, loc_ctxt) end; |
755 in (name, loc_ctxt) end; |
814 expression equations thy = |
818 expression equations thy = |
815 let |
819 let |
816 val ctxt = ProofContext.init thy; |
820 val ctxt = ProofContext.init thy; |
817 |
821 |
818 val ((propss, regs, export), expr_ctxt) = prep_expr expression ctxt; |
822 val ((propss, regs, export), expr_ctxt) = prep_expr expression ctxt; |
819 |
823 |
820 val eqns = map (parse_prop expr_ctxt o snd) equations |> Syntax.check_terms expr_ctxt; |
824 val eqns = map (parse_prop expr_ctxt o snd) equations |> Syntax.check_terms expr_ctxt; |
821 val eq_attns = map ((apsnd o map) (prep_attr thy) o fst) equations; |
825 val eq_attns = map ((apsnd o map) (prep_attr thy) o fst) equations; |
822 val goal_ctxt = fold Variable.auto_fixes eqns expr_ctxt; |
826 val goal_ctxt = fold Variable.auto_fixes eqns expr_ctxt; |
823 val export' = Variable.export_morphism goal_ctxt expr_ctxt; |
827 val export' = Variable.export_morphism goal_ctxt expr_ctxt; |
|
828 |
|
829 (*** alternative code -- unclear why it does not work yet ***) |
|
830 fun store_reg ((name, morph), thms) thy = |
|
831 let |
|
832 val thms' = map (Element.morph_witness export') thms; |
|
833 val morph' = morph $> Element.satisfy_morphism thms'; |
|
834 in |
|
835 thy |
|
836 |> Locale.add_registration (name, (morph', export)) |
|
837 |> pair (name, morph') |
|
838 end; |
|
839 |
|
840 fun store_eqns_activate regs [] thy = |
|
841 thy |
|
842 |> fold (fn (name, morph) => |
|
843 Locale.activate_global_facts (name, morph $> export)) regs |
|
844 | store_eqns_activate regs thms thys = |
|
845 let |
|
846 val thms' = thms |> map (Element.conclude_witness #> |
|
847 Morphism.thm (export' $> export) #> |
|
848 LocalDefs.meta_rewrite_rule (ProofContext.init thy) #> |
|
849 Drule.abs_def); |
|
850 val eq_morph = |
|
851 Morphism.term_morphism (MetaSimplifier.rewrite_term thy thms' []) $> |
|
852 Morphism.thm_morphism (MetaSimplifier.rewrite_rule thms'); |
|
853 val eq_attns' = map ((apsnd o map) (Attrib.attribute_i thy)) eq_attns; |
|
854 in |
|
855 thy |
|
856 |> fold (fn (name, morph) => |
|
857 Locale.amend_registration eq_morph (name, morph) #> |
|
858 Locale.activate_global_facts (name, morph $> eq_morph $> export)) regs |
|
859 |> PureThy.note_thmss Thm.lemmaK (eq_attns' ~~ map (fn th => [([th], [])]) thms') |
|
860 |> snd |
|
861 end; |
|
862 |
|
863 fun after_qed results = |
|
864 let |
|
865 val (wits_reg, wits_eq) = split_last (prep_result (propss @ [eqns]) results); |
|
866 in ProofContext.theory (fold_map store_reg (regs ~~ wits_reg) |
|
867 #-> (fn regs => store_eqns_activate regs wits_eq)) |
|
868 end; |
|
869 (*** alternative code end ***) |
824 |
870 |
825 fun store (Reg (name, morph), thms) (regs, thy) = |
871 fun store (Reg (name, morph), thms) (regs, thy) = |
826 let |
872 let |
827 val thms' = map (Element.morph_witness export') thms; |
873 val thms' = map (Element.morph_witness export') thms; |
828 val morph' = morph $> Element.satisfy_morphism thms'; |
874 val morph' = morph $> Element.satisfy_morphism thms'; |