src/Pure/Isar/named_target.ML
changeset 66334 b210ae666a42
parent 66333 30c1639a343a
child 66335 a849ce33923d
equal deleted inserted replaced
66333:30c1639a343a 66334:b210ae666a42
     9 sig
     9 sig
    10   val is_theory: local_theory -> bool
    10   val is_theory: local_theory -> bool
    11   val locale_of: local_theory -> string option
    11   val locale_of: local_theory -> string option
    12   val bottom_locale_of: local_theory -> string option
    12   val bottom_locale_of: local_theory -> string option
    13   val class_of: local_theory -> string option
    13   val class_of: local_theory -> string option
    14   val init: (local_theory -> local_theory) option -> string -> theory -> local_theory
    14   val init: string -> theory -> local_theory
       
    15   val init': {setup: local_theory -> local_theory, conclude: local_theory -> local_theory} ->
       
    16     string -> theory -> local_theory
    15   val theory_init: theory -> local_theory
    17   val theory_init: theory -> local_theory
    16   val theory_map: (local_theory -> local_theory) -> theory -> theory
    18   val theory_map: (local_theory -> local_theory) -> theory -> theory
    17   val begin: xstring * Position.T -> theory -> local_theory
    19   val begin: xstring * Position.T -> theory -> local_theory
    18   val exit: local_theory -> theory
    20   val exit: local_theory -> theory
    19   val switch: (xstring * Position.T) option -> Context.generic ->
    21   val switch: (xstring * Position.T) option -> Context.generic ->
   121 
   123 
   122 fun init_context Theory = Proof_Context.init_global
   124 fun init_context Theory = Proof_Context.init_global
   123   | init_context (Locale locale) = Locale.init locale
   125   | init_context (Locale locale) = Locale.init locale
   124   | init_context (Class class) = Class.init class;
   126   | init_context (Class class) = Class.init class;
   125 
   127 
   126 fun init before_exit ident thy =
   128 fun init' {setup, conclude} ident thy =
   127   let
   129   let
   128     val target = make_target thy ident;
   130     val target = make_target thy ident;
   129     val background_naming =
   131     val background_naming =
   130       Sign.naming_of thy |> Name_Space.mandatory_path (Long_Name.base_name ident);
   132       Sign.naming_of thy |> Name_Space.mandatory_path (Long_Name.base_name ident);
   131   in
   133   in
   132     thy
   134     thy
   133     |> Sign.change_begin
   135     |> Sign.change_begin
   134     |> init_context target
   136     |> init_context target
   135     |> is_none before_exit ? Data.put (SOME target)
   137     |> setup
   136     |> Local_Theory.init background_naming
   138     |> Local_Theory.init background_naming
   137        {define = Generic_Target.define (foundation target),
   139        {define = Generic_Target.define (foundation target),
   138         notes = Generic_Target.notes (notes target),
   140         notes = Generic_Target.notes (notes target),
   139         abbrev = abbrev target,
   141         abbrev = abbrev target,
   140         declaration = declaration target,
   142         declaration = declaration target,
   141         theory_registration = theory_registration target,
   143         theory_registration = theory_registration target,
   142         locale_dependency = locale_dependency target,
   144         locale_dependency = locale_dependency target,
   143         pretty = pretty target,
   145         pretty = pretty target,
   144         exit = the_default I before_exit
   146         exit = conclude #> Local_Theory.target_of #> Sign.change_end_local}
   145           #> Local_Theory.target_of #> Sign.change_end_local}
       
   146   end;
   147   end;
   147 
   148 
   148 val theory_init = init NONE "";
   149 fun init ident thy =
       
   150   init' {setup = Data.put (SOME (make_target thy ident)), conclude = I} ident thy;
       
   151 
       
   152 val theory_init = init "";
   149 
   153 
   150 fun theory_map f = theory_init #> f #> Local_Theory.exit_global;
   154 fun theory_map f = theory_init #> f #> Local_Theory.exit_global;
   151 
   155 
   152 
   156 
   153 (* toplevel interaction *)
   157 (* toplevel interaction *)
   154 
   158 
   155 fun begin ("-", _) thy = theory_init thy
   159 fun begin ("-", _) thy = theory_init thy
   156   | begin target thy = init NONE (Locale.check thy target) thy;
   160   | begin target thy = init (Locale.check thy target) thy;
   157 
   161 
   158 val exit = Local_Theory.assert_bottom #> Local_Theory.exit_global;
   162 val exit = Local_Theory.assert_bottom #> Local_Theory.exit_global;
   159 
   163 
   160 fun switch NONE (Context.Theory thy) =
   164 fun switch NONE (Context.Theory thy) =
   161       (Context.Theory o exit, theory_init thy)
   165       (Context.Theory o exit, theory_init thy)
   162   | switch (SOME name) (Context.Theory thy) =
   166   | switch (SOME name) (Context.Theory thy) =
   163       (Context.Theory o exit, begin name thy)
   167       (Context.Theory o exit, begin name thy)
   164   | switch NONE (Context.Proof lthy) =
   168   | switch NONE (Context.Proof lthy) =
   165       (Context.Proof o Local_Theory.reset, lthy)
   169       (Context.Proof o Local_Theory.reset, lthy)
   166   | switch (SOME name) (Context.Proof lthy) =
   170   | switch (SOME name) (Context.Proof lthy) =
   167       (Context.Proof o init NONE (ident_of lthy) o exit,
   171       (Context.Proof o init (ident_of lthy) o exit,
   168         (begin name o exit o Local_Theory.assert_nonbrittle) lthy);
   172         (begin name o exit o Local_Theory.assert_nonbrittle) lthy);
   169 
   173 
   170 end;
   174 end;