src/Pure/Isar/local_theory.ML
changeset 57194 d110b0d1bc12
parent 56809 b60009672a65
child 57924 a3360da1d2f0
equal deleted inserted replaced
57193:d59c4383cae4 57194:d110b0d1bc12
   110 );
   110 );
   111 
   111 
   112 fun assert lthy =
   112 fun assert lthy =
   113   if null (Data.get lthy) then error "Missing local theory context" else lthy;
   113   if null (Data.get lthy) then error "Missing local theory context" else lthy;
   114 
   114 
   115 val get_last_lthy = List.last o Data.get o assert;
   115 val bottom_of = List.last o Data.get o assert;
   116 val get_first_lthy = hd o Data.get o assert;
   116 val top_of = hd o Data.get o assert;
   117 
   117 
   118 fun map_first_lthy f =
   118 fun map_bottom f =
   119   assert #>
   119   assert #>
   120   Data.map (fn {naming, operations, after_close, brittle, target} :: parents =>
   120   Data.map (fn {naming, operations, after_close, brittle, target} :: parents =>
   121     make_lthy (f (naming, operations, after_close, brittle, target)) :: parents);
   121     make_lthy (f (naming, operations, after_close, brittle, target)) :: parents);
   122 
   122 
   123 fun restore lthy = #target (get_first_lthy lthy) |> Data.put (Data.get lthy);
   123 fun restore lthy = #target (top_of lthy) |> Data.put (Data.get lthy);
   124 
   124 
   125 
   125 
   126 (* nested structure *)
   126 (* nested structure *)
   127 
   127 
   128 val level = length o Data.get;  (*1: main target at bottom, >= 2: nested context*)
   128 val level = length o Data.get;  (*1: main target at bottom, >= 2: nested context*)
   161 
   161 
   162 (* brittle context -- implicit for nested structures *)
   162 (* brittle context -- implicit for nested structures *)
   163 
   163 
   164 fun mark_brittle lthy =
   164 fun mark_brittle lthy =
   165   if level lthy = 1
   165   if level lthy = 1
   166   then map_first_lthy (fn (naming, operations, after_close, brittle, target) =>
   166   then map_bottom (fn (naming, operations, after_close, brittle, target) =>
   167     (naming, operations, after_close, true, target)) lthy
   167     (naming, operations, after_close, true, target)) lthy
   168   else lthy;
   168   else lthy;
   169 
   169 
   170 fun assert_nonbrittle lthy =
   170 fun assert_nonbrittle lthy =
   171   if #brittle (get_first_lthy lthy)
   171   if #brittle (top_of lthy)
   172   then error "Brittle local theory context"
   172   then error "Brittle local theory context"
   173   else lthy;
   173   else lthy;
   174 
   174 
   175 
   175 
   176 (* naming *)
   176 (* naming *)
   177 
   177 
   178 val naming_of = #naming o get_first_lthy;
   178 val naming_of = #naming o top_of;
   179 val full_name = Name_Space.full_name o naming_of;
   179 val full_name = Name_Space.full_name o naming_of;
   180 
   180 
   181 fun map_naming f =
   181 fun map_naming f =
   182   map_first_lthy (fn (naming, operations, after_close, brittle, target) =>
   182   map_bottom (fn (naming, operations, after_close, brittle, target) =>
   183     (f naming, operations, after_close, brittle, target));
   183     (f naming, operations, after_close, brittle, target));
   184 
   184 
   185 val conceal = map_naming Name_Space.conceal;
   185 val conceal = map_naming Name_Space.conceal;
   186 val new_group = map_naming Name_Space.new_group;
   186 val new_group = map_naming Name_Space.new_group;
   187 val reset_group = map_naming Name_Space.reset_group;
   187 val reset_group = map_naming Name_Space.reset_group;
   220 fun background_theory f = #2 o background_theory_result (f #> pair ());
   220 fun background_theory f = #2 o background_theory_result (f #> pair ());
   221 
   221 
   222 
   222 
   223 (* target contexts *)
   223 (* target contexts *)
   224 
   224 
   225 val target_of = #target o get_last_lthy;
   225 val target_of = #target o bottom_of;
   226 
   226 
   227 fun target f lthy =
   227 fun target f lthy =
   228   let
   228   let
   229     val ctxt = target_of lthy;
   229     val ctxt = target_of lthy;
   230     val ctxt' = ctxt
   230     val ctxt' = ctxt
   247 
   247 
   248 
   248 
   249 
   249 
   250 (** operations **)
   250 (** operations **)
   251 
   251 
   252 val operations_of = #operations o get_first_lthy;
   252 val operations_of = #operations o top_of;
   253 
   253 
   254 
   254 
   255 (* primitives *)
   255 (* primitives *)
   256 
   256 
   257 fun operation f lthy = f (operations_of lthy) lthy;
   257 fun operation f lthy = f (operations_of lthy) lthy;
   309 
   309 
   310 
   310 
   311 (* activation of locale fragments *)
   311 (* activation of locale fragments *)
   312 
   312 
   313 fun activate_nonbrittle dep_morph mixin export =
   313 fun activate_nonbrittle dep_morph mixin export =
   314   map_first_lthy (fn (naming, operations, after_close, brittle, target) =>
   314   map_bottom (fn (naming, operations, after_close, brittle, target) =>
   315     (naming, operations, after_close, brittle,
   315     (naming, operations, after_close, brittle,
   316       (Context.proof_map ooo Locale.add_registration) dep_morph mixin export target));
   316       (Context.proof_map ooo Locale.add_registration) dep_morph mixin export target));
   317 
   317 
   318 fun activate dep_morph mixin export =
   318 fun activate dep_morph mixin export =
   319   mark_brittle #> activate_nonbrittle dep_morph mixin export;
   319   mark_brittle #> activate_nonbrittle dep_morph mixin export;