src/Pure/Isar/generic_target.ML
changeset 60340 69394731c419
parent 60337 c7ca6bb006b0
child 60341 fcbd7f0c52c3
equal deleted inserted replaced
60339:0e6742f89c03 60340:69394731c419
     5 Common target infrastructure.
     5 Common target infrastructure.
     6 *)
     6 *)
     7 
     7 
     8 signature GENERIC_TARGET =
     8 signature GENERIC_TARGET =
     9 sig
     9 sig
    10   (*consts*)
    10   (*background primitives*)
    11   val standard_const: (int * int -> bool) -> Syntax.mode -> (binding * mixfix) * term ->
       
    12     local_theory -> local_theory
       
    13 
       
    14   (*background operations*)
       
    15   val background_foundation: ((binding * typ) * mixfix) * (binding * term) ->
    11   val background_foundation: ((binding * typ) * mixfix) * (binding * term) ->
    16     term list * term list -> local_theory -> (term * thm) * local_theory
    12     term list * term list -> local_theory -> (term * thm) * local_theory
    17   val background_declaration: declaration -> local_theory -> local_theory
    13   val background_declaration: declaration -> local_theory -> local_theory
    18   val background_abbrev: binding * term -> term list -> local_theory -> (term * term) * local_theory
    14   val background_abbrev: binding * term -> term list -> local_theory -> (term * term) * local_theory
    19 
    15 
    20   (*lifting primitives to local theory operations*)
    16   (*nested local theories primitives*)
       
    17   val standard_const: (int * int -> bool) -> Syntax.mode -> (binding * mixfix) * term ->
       
    18     local_theory -> local_theory
       
    19 
       
    20   (*lifting target primitives to local theory operations*)
    21   val define: (((binding * typ) * mixfix) * (binding * term) ->
    21   val define: (((binding * typ) * mixfix) * (binding * term) ->
    22       term list * term list -> local_theory -> (term * thm) * local_theory) ->
    22       term list * term list -> local_theory -> (term * thm) * local_theory) ->
    23     bool -> (binding * mixfix) * (Attrib.binding * term) -> local_theory ->
    23     bool -> (binding * mixfix) * (Attrib.binding * term) -> local_theory ->
    24     (term * (string * thm)) * local_theory
    24     (term * (string * thm)) * local_theory
    25   val notes:
    25   val notes:
    60     local_theory -> local_theory
    60     local_theory -> local_theory
    61 end
    61 end
    62 
    62 
    63 structure Generic_Target: GENERIC_TARGET =
    63 structure Generic_Target: GENERIC_TARGET =
    64 struct
    64 struct
    65 
       
    66 (** notes **)
       
    67 
       
    68 fun standard_facts lthy ctxt =
       
    69   Attrib.transform_facts (Local_Theory.standard_morphism lthy ctxt);
       
    70 
       
    71 fun standard_notes pred kind facts lthy =
       
    72   Local_Theory.map_contexts (fn level => fn ctxt =>
       
    73     if pred (Local_Theory.level lthy, level)
       
    74     then Attrib.local_notes kind (standard_facts lthy ctxt facts) ctxt |> snd
       
    75     else ctxt) lthy;
       
    76 
       
    77 
       
    78 
       
    79 (** declarations **)
       
    80 
       
    81 fun standard_declaration pred decl lthy =
       
    82   Local_Theory.map_contexts (fn level => fn ctxt =>
       
    83     if pred (Local_Theory.level lthy, level)
       
    84     then Context.proof_map (Local_Theory.standard_form lthy ctxt decl) ctxt
       
    85     else ctxt) lthy;
       
    86 
       
    87 
       
    88 
    65 
    89 (** consts **)
    66 (** consts **)
    90 
    67 
    91 fun check_mixfix ctxt (b, extra_tfrees) mx =
    68 fun check_mixfix ctxt (b, extra_tfrees) mx =
    92   if null extra_tfrees then mx
    69   if null extra_tfrees then mx
   137                 (Proof_Context.generic_revert_abbrev (#1 prmode) c #>
   114                 (Proof_Context.generic_revert_abbrev (#1 prmode) c #>
   138                  Morphism.form (Proof_Context.generic_notation true prmode [(const, mx)]))))
   115                  Morphism.form (Proof_Context.generic_notation true prmode [(const, mx)]))))
   139     end
   116     end
   140   else context;
   117   else context;
   141 
   118 
   142 fun standard_const pred prmode ((b, mx), rhs) =
       
   143   standard_declaration pred (const_decl (K true) prmode ((b, mx), rhs));
       
   144 
       
   145 
   119 
   146 
   120 
   147 (** background primitives **)
   121 (** background primitives **)
   148 
   122 
   149 fun background_foundation (((b, U), mx), (b_def, rhs)) (type_params, term_params) lthy =
   123 fun background_foundation (((b, U), mx), (b_def, rhs)) (type_params, term_params) lthy =
   172   Local_Theory.background_theory_result (Sign.add_abbrev Print_Mode.internal (b, global_rhs))
   146   Local_Theory.background_theory_result (Sign.add_abbrev Print_Mode.internal (b, global_rhs))
   173   #>> apply2 (fn t => Term.list_comb (Logic.unvarify_global t, params))
   147   #>> apply2 (fn t => Term.list_comb (Logic.unvarify_global t, params))
   174 
   148 
   175 
   149 
   176 
   150 
   177 (** lifting primitive to local theory operations **)
   151 (** nested local theories primitives **)
       
   152 
       
   153 fun standard_facts lthy ctxt =
       
   154   Attrib.transform_facts (Local_Theory.standard_morphism lthy ctxt);
       
   155 
       
   156 fun standard_notes pred kind facts lthy =
       
   157   Local_Theory.map_contexts (fn level => fn ctxt =>
       
   158     if pred (Local_Theory.level lthy, level)
       
   159     then Attrib.local_notes kind (standard_facts lthy ctxt facts) ctxt |> snd
       
   160     else ctxt) lthy;
       
   161 
       
   162 fun standard_declaration pred decl lthy =
       
   163   Local_Theory.map_contexts (fn level => fn ctxt =>
       
   164     if pred (Local_Theory.level lthy, level)
       
   165     then Context.proof_map (Local_Theory.standard_form lthy ctxt decl) ctxt
       
   166     else ctxt) lthy;
       
   167 
       
   168 fun standard_const pred prmode ((b, mx), rhs) =
       
   169   standard_declaration pred (const_decl (K true) prmode ((b, mx), rhs));
       
   170 
       
   171 
       
   172 (** lifting target primitives to local theory operations **)
   178 
   173 
   179 (* define *)
   174 (* define *)
   180 
   175 
   181 fun define foundation internal ((b, mx), ((b_def, atts), rhs)) lthy =
   176 fun define foundation internal ((b, mx), ((b_def, atts), rhs)) lthy =
   182   let
   177   let