src/Pure/Isar/theory_target.ML
author wenzelm
Thu Oct 11 21:10:43 2007 +0200 (2007-10-11)
changeset 24987 50b07326da38
parent 24983 f2f4ba67cef1
child 24989 e656aeaa8b28
permissions -rw-r--r--
local_theory: incorporated consts into axioms;
LocalDefs.expand_cterm;
tuned;
wenzelm@20894
     1
(*  Title:      Pure/Isar/theory_target.ML
wenzelm@20894
     2
    ID:         $Id$
wenzelm@20894
     3
    Author:     Makarius
wenzelm@20894
     4
wenzelm@24935
     5
Common theory/locale/class targets.
wenzelm@20894
     6
*)
wenzelm@20894
     7
wenzelm@20894
     8
signature THEORY_TARGET =
wenzelm@20894
     9
sig
wenzelm@21006
    10
  val peek: local_theory -> string option
wenzelm@24935
    11
  val begin: string -> Proof.context -> local_theory
wenzelm@24935
    12
  val init: string option -> theory -> local_theory
wenzelm@24935
    13
  val init_cmd: xstring option -> theory -> local_theory
wenzelm@20894
    14
end;
wenzelm@20894
    15
wenzelm@20894
    16
structure TheoryTarget: THEORY_TARGET =
wenzelm@20894
    17
struct
wenzelm@20894
    18
wenzelm@24987
    19
wenzelm@20894
    20
(** locale targets **)
wenzelm@20894
    21
wenzelm@21006
    22
(* context data *)
wenzelm@21006
    23
wenzelm@21006
    24
structure Data = ProofDataFun
wenzelm@21006
    25
(
wenzelm@21006
    26
  type T = string option;
wenzelm@21006
    27
  fun init _ = NONE;
wenzelm@21006
    28
);
wenzelm@21006
    29
wenzelm@21006
    30
val peek = Data.get;
wenzelm@21006
    31
wenzelm@21006
    32
wenzelm@20894
    33
(* pretty *)
wenzelm@20894
    34
wenzelm@20894
    35
fun pretty loc ctxt =
wenzelm@20894
    36
  let
wenzelm@20894
    37
    val thy = ProofContext.theory_of ctxt;
wenzelm@24939
    38
    val loc_kind = if is_some (Class.class_of_locale thy loc) then "class" else "locale";
wenzelm@24939
    39
    val loc_name = Locale.extern thy loc;
wenzelm@24939
    40
wenzelm@20894
    41
    val fixes = map (fn (x, T) => (x, SOME T, NoSyn)) (#1 (ProofContext.inferred_fixes ctxt));
wenzelm@21585
    42
    val assumes = map (fn A => (("", []), [(A, [])])) (map Thm.term_of (Assumption.assms_of ctxt));
wenzelm@20894
    43
    val elems =
wenzelm@20894
    44
      (if null fixes then [] else [Element.Fixes fixes]) @
wenzelm@20894
    45
      (if null assumes then [] else [Element.Assumes assumes]);
wenzelm@20894
    46
  in
wenzelm@24939
    47
    Pretty.block [Pretty.str "theory", Pretty.brk 1, Pretty.str (Context.theory_name thy)] ::
wenzelm@24939
    48
     (if loc = "" then []
wenzelm@24939
    49
      else if null elems then [Pretty.str (loc_kind ^ " " ^ loc_name)]
wenzelm@24939
    50
      else [Pretty.big_list (loc_kind ^ " " ^ loc_name ^ " =")
wenzelm@24939
    51
        (map (Pretty.chunks o Element.pretty_ctxt ctxt) elems)])
wenzelm@20894
    52
  end;
wenzelm@20894
    53
wenzelm@20894
    54
haftmann@24838
    55
(* target declarations *)
haftmann@24838
    56
haftmann@24838
    57
fun target_decl add loc d lthy =
haftmann@24838
    58
  let
wenzelm@24935
    59
    val d' = Morphism.transform (LocalTheory.target_morphism lthy) d;
haftmann@24838
    60
    val d0 = Morphism.form d';
haftmann@24838
    61
  in
haftmann@24838
    62
    if loc = "" then
haftmann@24838
    63
      lthy
haftmann@24838
    64
      |> LocalTheory.theory (Context.theory_map d0)
haftmann@24838
    65
      |> LocalTheory.target (Context.proof_map d0)
haftmann@24838
    66
    else
haftmann@24838
    67
      lthy
haftmann@24838
    68
      |> LocalTheory.target (add loc d')
haftmann@24838
    69
  end;
haftmann@24838
    70
haftmann@24838
    71
val type_syntax = target_decl Locale.add_type_syntax;
haftmann@24838
    72
val term_syntax = target_decl Locale.add_term_syntax;
haftmann@24838
    73
val declaration = target_decl Locale.add_declaration;
haftmann@24838
    74
haftmann@24838
    75
fun target_naming loc lthy =
haftmann@24838
    76
  (if loc = "" then Sign.naming_of (ProofContext.theory_of lthy)
haftmann@24838
    77
   else ProofContext.naming_of (LocalTheory.target_of lthy))
haftmann@24838
    78
  |> NameSpace.qualified_names;
haftmann@24838
    79
haftmann@24838
    80
wenzelm@21611
    81
wenzelm@20894
    82
(* notes *)
wenzelm@20894
    83
wenzelm@21611
    84
fun import_export_proof ctxt (name, raw_th) =
wenzelm@21594
    85
  let
wenzelm@21611
    86
    val thy = ProofContext.theory_of ctxt;
wenzelm@21611
    87
    val thy_ctxt = ProofContext.init thy;
wenzelm@21611
    88
    val certT = Thm.ctyp_of thy;
wenzelm@21611
    89
    val cert = Thm.cterm_of thy;
wenzelm@21594
    90
wenzelm@21611
    91
    (*export assumes/defines*)
wenzelm@21611
    92
    val th = Goal.norm_result raw_th;
wenzelm@21611
    93
    val (defs, th') = LocalDefs.export ctxt thy_ctxt th;
wenzelm@21708
    94
    val concl_conv = MetaSimplifier.rewrite true defs (Thm.cprop_of th);
wenzelm@21708
    95
    val assms = map (MetaSimplifier.rewrite_rule defs o Thm.assume) (Assumption.assms_of ctxt);
wenzelm@21611
    96
    val nprems = Thm.nprems_of th' - Thm.nprems_of th;
wenzelm@21611
    97
wenzelm@21611
    98
    (*export fixes*)
wenzelm@22692
    99
    val tfrees = map TFree (Thm.fold_terms Term.add_tfrees th' []);
wenzelm@22692
   100
    val frees = map Free (Thm.fold_terms Term.add_frees th' []);
wenzelm@21611
   101
    val (th'' :: vs) = (th' :: map (Drule.mk_term o cert) (map Logic.mk_type tfrees @ frees))
wenzelm@21611
   102
      |> Variable.export ctxt thy_ctxt
wenzelm@21611
   103
      |> Drule.zero_var_indexes_list;
wenzelm@21611
   104
wenzelm@21611
   105
    (*thm definition*)
wenzelm@21644
   106
    val result = th''
wenzelm@21644
   107
      |> PureThy.name_thm true true ""
wenzelm@21644
   108
      |> Goal.close_result
wenzelm@24779
   109
      |> fold PureThy.tag_rule (ContextPosition.properties_of ctxt)
wenzelm@21644
   110
      |> PureThy.name_thm true true name;
wenzelm@21611
   111
wenzelm@21611
   112
    (*import fixes*)
wenzelm@21611
   113
    val (tvars, vars) =
wenzelm@21611
   114
      chop (length tfrees) (map (Thm.term_of o Drule.dest_term) vs)
wenzelm@21611
   115
      |>> map Logic.dest_type;
wenzelm@21611
   116
wenzelm@21611
   117
    val instT = map_filter (fn (TVar v, T) => SOME (v, T) | _ => NONE) (tvars ~~ tfrees);
wenzelm@21611
   118
    val inst = filter (is_Var o fst) (vars ~~ frees);
wenzelm@21611
   119
    val cinstT = map (pairself certT o apfst TVar) instT;
wenzelm@21611
   120
    val cinst = map (pairself (cert o Term.map_types (TermSubst.instantiateT instT))) inst;
wenzelm@21611
   121
    val result' = Thm.instantiate (cinstT, cinst) result;
wenzelm@21611
   122
wenzelm@21611
   123
    (*import assumes/defines*)
wenzelm@21594
   124
    val assm_tac = FIRST' (map (fn assm => Tactic.compose_tac (false, assm, 0)) assms);
wenzelm@21611
   125
    val result'' =
wenzelm@21611
   126
      (case SINGLE (Seq.INTERVAL assm_tac 1 nprems) result' of
wenzelm@21611
   127
        NONE => raise THM ("Failed to re-import result", 0, [result'])
wenzelm@21845
   128
      | SOME res => LocalDefs.trans_props ctxt [res, Thm.symmetric concl_conv])
wenzelm@21644
   129
      |> Goal.norm_result
wenzelm@21644
   130
      |> PureThy.name_thm false false name;
wenzelm@21611
   131
wenzelm@21611
   132
  in (result'', result) end;
wenzelm@21611
   133
wenzelm@24939
   134
fun local_notes loc kind facts lthy =
wenzelm@21585
   135
  let
wenzelm@21594
   136
    val is_loc = loc <> "";
wenzelm@21594
   137
    val thy = ProofContext.theory_of lthy;
wenzelm@21615
   138
    val full = LocalTheory.full_name lthy;
wenzelm@21585
   139
wenzelm@21594
   140
    val facts' = facts
wenzelm@21615
   141
      |> map (fn (a, bs) => (a, PureThy.burrow_fact (PureThy.name_multi (full (fst a))) bs))
wenzelm@21615
   142
      |> PureThy.map_facts (import_export_proof lthy);
wenzelm@21611
   143
    val local_facts = PureThy.map_facts #1 facts'
wenzelm@21611
   144
      |> Attrib.map_facts (Attrib.attribute_i thy);
wenzelm@21611
   145
    val target_facts = PureThy.map_facts #1 facts'
wenzelm@21611
   146
      |> is_loc ? Element.facts_map (Element.morph_ctxt (LocalTheory.target_morphism lthy));
wenzelm@21611
   147
    val global_facts = PureThy.map_facts #2 facts'
wenzelm@21594
   148
      |> Attrib.map_facts (if is_loc then K I else Attrib.attribute_i thy);
wenzelm@21594
   149
  in
wenzelm@21611
   150
    lthy |> LocalTheory.theory
wenzelm@21611
   151
      (Sign.qualified_names
wenzelm@21611
   152
        #> PureThy.note_thmss_i kind global_facts #> snd
wenzelm@21611
   153
        #> Sign.restore_naming thy)
wenzelm@21585
   154
wenzelm@21611
   155
    |> is_loc ? LocalTheory.target (Locale.add_thmss loc kind target_facts)
wenzelm@21594
   156
wenzelm@20894
   157
    |> ProofContext.qualified_names
wenzelm@21611
   158
    |> ProofContext.note_thmss_i kind local_facts
wenzelm@20894
   159
    ||> ProofContext.restore_naming lthy
wenzelm@20894
   160
  end;
wenzelm@20894
   161
wenzelm@20894
   162
wenzelm@24939
   163
(* consts *)
wenzelm@24939
   164
wenzelm@24939
   165
fun target_abbrev prmode ((c, mx), rhs) phi =
wenzelm@24939
   166
  let
wenzelm@24939
   167
    val c' = Morphism.name phi c;
wenzelm@24939
   168
    val rhs' = Morphism.term phi rhs;
wenzelm@24939
   169
    val arg' = (c', rhs');
wenzelm@24939
   170
    val eq_heads =
wenzelm@24939
   171
      (case pairself Term.head_of (rhs, rhs') of
wenzelm@24939
   172
        (Const (a, _), Const (a', _)) => a = a'
wenzelm@24939
   173
      | _ => false);
wenzelm@24939
   174
  in
wenzelm@24939
   175
    eq_heads ? (Context.mapping_result
wenzelm@24939
   176
      (Sign.add_abbrev Syntax.internalM [] arg') (ProofContext.add_abbrev Syntax.internalM [] arg')
wenzelm@24939
   177
    #-> (fn (lhs, _) =>
wenzelm@24983
   178
      Type.similar_types (rhs, rhs') ?
wenzelm@24949
   179
        Morphism.form (ProofContext.target_notation true prmode [(lhs, mx)])))
wenzelm@24939
   180
  end;
wenzelm@24939
   181
wenzelm@24939
   182
fun internal_abbrev loc prmode ((c, mx), t) lthy = lthy
wenzelm@24939
   183
  (* FIXME really permissive *)
wenzelm@24939
   184
  |> term_syntax loc (perhaps o try o target_abbrev prmode ((c, mx), t))
wenzelm@24939
   185
  |> ProofContext.add_abbrev Syntax.internalM (ContextPosition.properties_of lthy) (c, t)
wenzelm@24939
   186
  |> snd;
wenzelm@24939
   187
wenzelm@24939
   188
fun declare_consts loc depends decls lthy =
wenzelm@24939
   189
  let
wenzelm@24939
   190
    val thy = ProofContext.theory_of lthy;
wenzelm@24939
   191
    val is_loc = loc <> "";
wenzelm@24939
   192
    val some_class = Class.class_of_locale thy loc;
wenzelm@24939
   193
wenzelm@24939
   194
    val xs = filter depends (#1 (ProofContext.inferred_fixes (LocalTheory.target_of lthy)));
wenzelm@24939
   195
wenzelm@24939
   196
    fun const ((c, T), mx) thy =
wenzelm@24939
   197
      let
wenzelm@24939
   198
        val U = map #2 xs ---> T;
wenzelm@24939
   199
        val (mx1, mx2) = Class.fork_mixfix is_loc some_class mx;
wenzelm@24939
   200
        val mx3 = if is_loc then NoSyn else mx1;
wenzelm@24959
   201
        val (const, thy') = Sign.declare_const (ContextPosition.properties_of lthy) (c, U, mx3) thy;
wenzelm@24959
   202
        val t = Term.list_comb (const, map Free xs);
wenzelm@24939
   203
      in (((c, mx2), t), thy') end;
wenzelm@24939
   204
    fun const_class (SOME class) ((c, _), mx) (_, t) =
wenzelm@24939
   205
          LocalTheory.raw_theory_result (Class.add_const_in_class class ((c, t), mx))
wenzelm@24939
   206
          #-> Class.remove_constraint [class]
wenzelm@24939
   207
      | const_class NONE _ _ = I;
wenzelm@24939
   208
    fun hide_abbrev (SOME class) abbrs thy =
wenzelm@24939
   209
          let
wenzelm@24939
   210
            val raw_cs = map (fst o fst) abbrs;
wenzelm@24939
   211
            val prfx = (Logic.const_of_class o NameSpace.base) class;
wenzelm@24939
   212
            fun mk_name c =
wenzelm@24939
   213
              let
wenzelm@24939
   214
                val n1 = Sign.full_name thy c;
wenzelm@24939
   215
                val n2 = NameSpace.qualifier n1;
wenzelm@24939
   216
                val n3 = NameSpace.base n1;
wenzelm@24939
   217
              in NameSpace.implode [n2, prfx, prfx, n3] end;
wenzelm@24939
   218
            val cs = map mk_name raw_cs;
wenzelm@24939
   219
          in
wenzelm@24939
   220
            Sign.hide_consts_i true cs thy
wenzelm@24939
   221
          end
wenzelm@24939
   222
      | hide_abbrev NONE _ thy = thy;
wenzelm@24939
   223
wenzelm@24939
   224
    val (abbrs, lthy') = lthy
wenzelm@24939
   225
      |> LocalTheory.theory_result (fold_map const decls)
wenzelm@24939
   226
    val defs = map (apsnd (pair ("", []))) abbrs;
wenzelm@24939
   227
wenzelm@24939
   228
  in
wenzelm@24939
   229
    lthy'
wenzelm@24939
   230
    |> fold2 (const_class some_class) decls abbrs
wenzelm@24959
   231
    |> is_loc ? fold (internal_abbrev loc Syntax.mode_default) abbrs
wenzelm@24939
   232
    |> LocalTheory.raw_theory (hide_abbrev some_class abbrs)
wenzelm@24939
   233
        (*FIXME abbreviations should never occur*)
wenzelm@24939
   234
    |> LocalDefs.add_defs defs
wenzelm@24939
   235
    |>> map (apsnd snd)
wenzelm@24939
   236
  end;
wenzelm@24939
   237
wenzelm@24939
   238
wenzelm@24939
   239
(* abbrev *)
wenzelm@24939
   240
wenzelm@24939
   241
fun occ_params ctxt ts =
wenzelm@24939
   242
  #1 (ProofContext.inferred_fixes ctxt)
wenzelm@24939
   243
  |> filter (member (op =) (fold (Variable.add_fixed ctxt) ts []));
wenzelm@24939
   244
wenzelm@24939
   245
fun local_abbrev (x, rhs) =
wenzelm@24939
   246
  Variable.add_fixes [x] #-> (fn [x'] =>
wenzelm@24939
   247
    let
wenzelm@24939
   248
      val T = Term.fastype_of rhs;
wenzelm@24939
   249
      val lhs = Free (x', T);
wenzelm@24939
   250
    in
wenzelm@24939
   251
      Variable.declare_term lhs #>
wenzelm@24939
   252
      Variable.declare_term rhs #>
wenzelm@24939
   253
      Assumption.add_assms (K (K (I, Envir.expand_term_frees [((x', T), rhs)]))) [] #> snd #>
wenzelm@24939
   254
      pair (lhs, rhs)
wenzelm@24939
   255
    end);
wenzelm@24939
   256
wenzelm@24939
   257
fun abbrev loc prmode ((raw_c, mx), raw_t) lthy =
wenzelm@24939
   258
  let
wenzelm@24939
   259
    val thy = ProofContext.theory_of lthy;
wenzelm@24939
   260
    val is_loc = loc <> "";
wenzelm@24939
   261
    val some_class = Class.class_of_locale thy loc;
wenzelm@24939
   262
wenzelm@24939
   263
    val thy_ctxt = ProofContext.init thy;
wenzelm@24939
   264
    val target = LocalTheory.target_of lthy;
wenzelm@24939
   265
    val target_morphism = LocalTheory.target_morphism lthy;
wenzelm@24939
   266
wenzelm@24939
   267
    val c = Morphism.name target_morphism raw_c;
wenzelm@24939
   268
    val t = Morphism.term target_morphism raw_t;
wenzelm@24939
   269
    val xs = map Free (occ_params target [t]);
wenzelm@24939
   270
    val u = fold_rev Term.lambda xs t;
wenzelm@24939
   271
    val U = Term.fastype_of u;
wenzelm@24939
   272
    val u' = singleton (Variable.export_terms (Variable.declare_term u target) thy_ctxt) u;
wenzelm@24939
   273
    val (mx1, mx2) = Class.fork_mixfix is_loc some_class mx;
wenzelm@24939
   274
    val mx3 = if is_loc then NoSyn else mx1;
wenzelm@24939
   275
    fun add_abbrev_in_class (SOME class) abbr =
wenzelm@24939
   276
          LocalTheory.raw_theory_result (Class.add_abbrev_in_class class prmode abbr)
wenzelm@24939
   277
          #-> (fn c => Class.remove_constraint [class] c)
wenzelm@24939
   278
      | add_abbrev_in_class NONE _ = I;
wenzelm@24939
   279
  in
wenzelm@24939
   280
    lthy
wenzelm@24939
   281
    |> LocalTheory.theory_result
wenzelm@24939
   282
        (Sign.add_abbrev (#1 prmode) (ContextPosition.properties_of lthy) (c, u'))
wenzelm@24949
   283
    |-> (fn (lhs as Const (full_c, _), rhs) =>
wenzelm@24949
   284
          LocalTheory.theory (Sign.notation true prmode [(lhs, mx3)])
wenzelm@24949
   285
          #> is_loc ? internal_abbrev loc prmode ((c, mx2), Term.list_comb (Const (full_c, U), xs))
wenzelm@24949
   286
          #> add_abbrev_in_class some_class ((c, Term.list_comb (Const (full_c, U), xs)), mx1)
wenzelm@24949
   287
          #> local_abbrev (c, rhs))
wenzelm@24939
   288
  end;
wenzelm@24939
   289
wenzelm@24939
   290
wenzelm@24939
   291
(* defs *)
wenzelm@24939
   292
wenzelm@24987
   293
fun local_def loc kind ((c, mx), ((name, atts), rhs)) lthy =
wenzelm@24939
   294
  let
wenzelm@24987
   295
    val thy = ProofContext.theory_of lthy;
wenzelm@24939
   296
    val thy_ctxt = ProofContext.init thy;
wenzelm@24939
   297
wenzelm@24987
   298
    val (rhs', rhs_conv) =
wenzelm@24987
   299
      LocalDefs.export_cterm lthy thy_ctxt (Thm.cterm_of thy rhs) |>> Thm.term_of;
wenzelm@24987
   300
    val xs = Variable.add_fixed (LocalTheory.target_of lthy) rhs' [];
wenzelm@24939
   301
    val T = Term.fastype_of rhs;
wenzelm@24939
   302
wenzelm@24939
   303
    (*consts*)
wenzelm@24987
   304
    val ([(lhs, lhs_def)], lthy2) = lthy
wenzelm@24939
   305
      |> declare_consts loc (member (op =) xs) [((c, T), mx)];
wenzelm@24939
   306
    val (_, lhs') = Logic.dest_equals (Thm.prop_of lhs_def);
wenzelm@24939
   307
wenzelm@24939
   308
    (*def*)
wenzelm@24939
   309
    val name' = Thm.def_name_optional c name;
wenzelm@24939
   310
    val (def, lthy3) = lthy2
wenzelm@24983
   311
      |> LocalTheory.theory_result (Thm.add_def false (name', Logic.mk_equals (lhs', rhs')));
wenzelm@24939
   312
    val eq = LocalDefs.trans_terms lthy3
wenzelm@24939
   313
      [(*c == loc.c xs*) lhs_def,
wenzelm@24939
   314
       (*lhs' == rhs'*)  def,
wenzelm@24939
   315
       (*rhs' == rhs*)   Thm.symmetric rhs_conv];
wenzelm@24939
   316
wenzelm@24939
   317
    (*notes*)
wenzelm@24939
   318
    val ([(res_name, [res])], lthy4) = lthy3
wenzelm@24939
   319
      |> local_notes loc kind [((name', atts), [([eq], [])])];
wenzelm@24939
   320
  in ((lhs, (res_name, res)), lthy4) end;
wenzelm@24939
   321
wenzelm@24939
   322
wenzelm@24939
   323
(* axioms *)
wenzelm@24939
   324
wenzelm@24987
   325
fun local_axioms loc kind (vars, specs) lthy =
wenzelm@24939
   326
  let
wenzelm@24939
   327
    val hyps = map Thm.term_of (Assumption.assms_of lthy);
wenzelm@24939
   328
    fun axiom ((name, atts), props) thy = thy
wenzelm@24983
   329
      |> fold_map (Thm.add_axiom hyps) (PureThy.name_multi name props)
wenzelm@24939
   330
      |-> (fn ths => pair ((name, atts), [(ths, [])]));
wenzelm@24987
   331
wenzelm@24987
   332
    val spec_frees = member (op =) (fold (fold Term.add_frees o snd) specs []);
wenzelm@24987
   333
    val (consts, lthy') = declare_consts loc spec_frees vars lthy;
wenzelm@24987
   334
    val heads = map (Term.head_of o Thm.term_of o Thm.rhs_of o #2) consts;
wenzelm@24939
   335
  in
wenzelm@24987
   336
    lthy'
wenzelm@24987
   337
    |> LocalTheory.theory (Theory.add_finals_i false heads)
wenzelm@24939
   338
    |> fold (fold Variable.declare_term o snd) specs
wenzelm@24939
   339
    |> LocalTheory.theory_result (fold_map axiom specs)
wenzelm@24939
   340
    |-> local_notes loc kind
wenzelm@24987
   341
    |>> pair (map #1 consts)
wenzelm@24939
   342
  end;
wenzelm@24939
   343
wenzelm@24939
   344
wenzelm@20894
   345
(* init and exit *)
wenzelm@20894
   346
haftmann@22353
   347
fun begin loc ctxt =
haftmann@22353
   348
  let
haftmann@22353
   349
    val thy = ProofContext.theory_of ctxt;
haftmann@22353
   350
    val is_loc = loc <> "";
haftmann@22353
   351
  in
haftmann@22353
   352
    ctxt
haftmann@22353
   353
    |> Data.put (if is_loc then SOME loc else NONE)
wenzelm@24939
   354
    |> fold Class.init (the_list (Class.class_of_locale thy loc))
haftmann@24748
   355
    |> LocalTheory.init (NameSpace.base loc)
wenzelm@21747
   356
     {pretty = pretty loc,
wenzelm@24987
   357
      axioms = local_axioms loc,
wenzelm@24939
   358
      abbrev = abbrev loc,
wenzelm@24939
   359
      def = local_def loc,
wenzelm@24939
   360
      notes = local_notes loc,
wenzelm@21747
   361
      type_syntax = type_syntax loc,
wenzelm@21747
   362
      term_syntax = term_syntax loc,
wenzelm@21747
   363
      declaration = declaration loc,
wenzelm@22203
   364
      target_naming = target_naming loc,
wenzelm@21804
   365
      reinit = fn _ =>
haftmann@24657
   366
        (if is_loc then Locale.init loc else ProofContext.init)
haftmann@24657
   367
        #> begin loc,
wenzelm@24935
   368
      exit = LocalTheory.target_of}
wenzelm@21747
   369
  end;
wenzelm@20894
   370
wenzelm@24935
   371
fun init NONE thy = begin "" (ProofContext.init thy)
wenzelm@24935
   372
  | init (SOME loc) thy = begin loc (Locale.init loc thy);
wenzelm@20894
   373
wenzelm@24935
   374
fun init_cmd (SOME "-") thy = init NONE thy
wenzelm@24935
   375
  | init_cmd loc thy = init (Option.map (Locale.intern thy) loc) thy;
wenzelm@20894
   376
wenzelm@20894
   377
end;