src/Pure/Isar/spec_rules.ML
changeset 71214 5727bcc3c47c
parent 71210 66fa99c85095
child 71216 e64c249d3d98
equal deleted inserted replaced
71213:39ccdbbed539 71214:5727bcc3c47c
    36   val get: Proof.context -> spec_rule list
    36   val get: Proof.context -> spec_rule list
    37   val get_global: theory -> spec_rule list
    37   val get_global: theory -> spec_rule list
    38   val dest_theory: theory -> spec_rule list
    38   val dest_theory: theory -> spec_rule list
    39   val retrieve: Proof.context -> term -> spec_rule list
    39   val retrieve: Proof.context -> term -> spec_rule list
    40   val retrieve_global: theory -> term -> spec_rule list
    40   val retrieve_global: theory -> term -> spec_rule list
    41   val add: string -> rough_classification -> term list -> thm list -> local_theory -> local_theory
    41   val add: binding -> rough_classification -> term list -> thm list -> local_theory -> local_theory
    42   val add_global: string -> rough_classification -> term list -> thm list -> theory -> theory
    42   val add_global: binding -> rough_classification -> term list -> thm list -> theory -> theory
    43 end;
    43 end;
    44 
    44 
    45 structure Spec_Rules: SPEC_RULES =
    45 structure Spec_Rules: SPEC_RULES =
    46 struct
    46 struct
    47 
    47 
   156 val retrieve_global = retrieve_generic o Context.Theory;
   156 val retrieve_global = retrieve_generic o Context.Theory;
   157 
   157 
   158 
   158 
   159 (* add *)
   159 (* add *)
   160 
   160 
   161 fun add name rough_classification terms rules lthy =
   161 fun add b rough_classification terms rules lthy =
   162   let
   162   let
   163     val pos = Position.thread_data ();
   163     val pos = Position.thread_data ();
   164     val thms0 = map Thm.trim_context (map (Drule.mk_term o Thm.cterm_of lthy) terms @ rules);
   164     val thms0 = map Thm.trim_context (map (Drule.mk_term o Thm.cterm_of lthy) terms @ rules);
   165   in
   165   in
   166     lthy |> Local_Theory.declaration {syntax = false, pervasive = true}
   166     lthy |> Local_Theory.declaration {syntax = false, pervasive = true}
   167       (fn phi => fn context =>
   167       (fn phi => fn context =>
   168         let
   168         let
       
   169           val name = Name_Space.full_name (Name_Space.naming_of context) (Morphism.binding phi b);
   169           val (terms', rules') =
   170           val (terms', rules') =
   170             map (Thm.transfer (Context.theory_of context)) thms0
   171             map (Thm.transfer (Context.theory_of context)) thms0
   171             |> Morphism.fact phi
   172             |> Morphism.fact phi
   172             |> chop (length terms)
   173             |> chop (length terms)
   173             |>> map (Thm.term_of o Drule.dest_term)
   174             |>> map (Thm.term_of o Drule.dest_term)
   177             {pos = pos, name = name, rough_classification = rough_classification,
   178             {pos = pos, name = name, rough_classification = rough_classification,
   178               terms = terms', rules = rules'}
   179               terms = terms', rules = rules'}
   179         end)
   180         end)
   180   end;
   181   end;
   181 
   182 
   182 fun add_global name rough_classification terms rules =
   183 fun add_global b rough_classification terms rules thy =
   183   (Context.theory_map o Rules.map o Item_Net.update)
   184   thy |> (Context.theory_map o Rules.map o Item_Net.update)
   184     {pos = Position.thread_data (), name = name, rough_classification = rough_classification,
   185    {pos = Position.thread_data (),
   185       terms = terms, rules = map Thm.trim_context rules};
   186     name = Sign.full_name thy b,
       
   187     rough_classification = rough_classification,
       
   188     terms = terms,
       
   189     rules = map Thm.trim_context rules};
   186 
   190 
   187 end;
   191 end;