19 val restore: local_theory -> local_theory |
19 val restore: local_theory -> local_theory |
20 val level: Proof.context -> int |
20 val level: Proof.context -> int |
21 val assert_bottom: bool -> local_theory -> local_theory |
21 val assert_bottom: bool -> local_theory -> local_theory |
22 val mark_brittle: local_theory -> local_theory |
22 val mark_brittle: local_theory -> local_theory |
23 val assert_nonbrittle: local_theory -> local_theory |
23 val assert_nonbrittle: local_theory -> local_theory |
24 val open_target: Name_Space.naming -> operations -> (local_theory -> local_theory) -> |
|
25 local_theory -> local_theory |
|
26 val close_target: local_theory -> local_theory |
|
27 val map_contexts: (int -> Proof.context -> Proof.context) -> local_theory -> local_theory |
24 val map_contexts: (int -> Proof.context -> Proof.context) -> local_theory -> local_theory |
28 val background_naming_of: local_theory -> Name_Space.naming |
25 val background_naming_of: local_theory -> Name_Space.naming |
29 val map_background_naming: (Name_Space.naming -> Name_Space.naming) -> |
26 val map_background_naming: (Name_Space.naming -> Name_Space.naming) -> |
30 local_theory -> local_theory |
27 local_theory -> local_theory |
31 val restore_background_naming: local_theory -> local_theory -> local_theory |
28 val restore_background_naming: local_theory -> local_theory -> local_theory |
71 val init: Name_Space.naming -> operations -> Proof.context -> local_theory |
68 val init: Name_Space.naming -> operations -> Proof.context -> local_theory |
72 val exit: local_theory -> Proof.context |
69 val exit: local_theory -> Proof.context |
73 val exit_global: local_theory -> theory |
70 val exit_global: local_theory -> theory |
74 val exit_result: (morphism -> 'a -> 'b) -> 'a * local_theory -> 'b * Proof.context |
71 val exit_result: (morphism -> 'a -> 'b) -> 'a * local_theory -> 'b * Proof.context |
75 val exit_result_global: (morphism -> 'a -> 'b) -> 'a * local_theory -> 'b * theory |
72 val exit_result_global: (morphism -> 'a -> 'b) -> 'a * local_theory -> 'b * theory |
|
73 val init_target: Name_Space.naming -> operations -> (local_theory -> local_theory) -> |
|
74 local_theory -> Binding.scope * local_theory |
|
75 val open_target: local_theory -> Binding.scope * local_theory |
|
76 val close_target: local_theory -> local_theory |
76 end; |
77 end; |
77 |
78 |
78 structure Local_Theory: LOCAL_THEORY = |
79 structure Local_Theory: LOCAL_THEORY = |
79 struct |
80 struct |
80 |
81 |
142 if b andalso not b' then error "Not at bottom of local theory nesting" |
143 if b andalso not b' then error "Not at bottom of local theory nesting" |
143 else if not b andalso b' then error "Already at bottom of local theory nesting" |
144 else if not b andalso b' then error "Already at bottom of local theory nesting" |
144 else lthy |
145 else lthy |
145 end; |
146 end; |
146 |
147 |
147 fun open_target background_naming operations after_close lthy = |
|
148 let |
|
149 val _ = assert lthy; |
|
150 val (_, target) = Proof_Context.new_scope lthy; |
|
151 in |
|
152 target |> Data.map (cons (make_lthy (background_naming, operations, after_close, true, target))) |
|
153 end; |
|
154 |
|
155 fun close_target lthy = |
|
156 let |
|
157 val _ = assert_bottom false lthy; |
|
158 val ({after_close, ...} :: rest) = Data.get lthy; |
|
159 in lthy |> Data.put rest |> restore |> after_close end; |
|
160 |
|
161 fun map_contexts f lthy = |
148 fun map_contexts f lthy = |
162 let val n = level lthy in |
149 let val n = level lthy in |
163 lthy |> (Data.map o map_index) |
150 lthy |> (Data.map o map_index) |
164 (fn (i, {background_naming, operations, after_close, brittle, target}) => |
151 (fn (i, {background_naming, operations, after_close, brittle, target}) => |
165 make_lthy (background_naming, operations, after_close, brittle, |
152 make_lthy (background_naming, operations, after_close, brittle, |
348 val type_alias = syntax_alias Sign.type_alias Proof_Context.type_alias; |
335 val type_alias = syntax_alias Sign.type_alias Proof_Context.type_alias; |
349 val const_alias = syntax_alias Sign.const_alias Proof_Context.const_alias; |
336 val const_alias = syntax_alias Sign.const_alias Proof_Context.const_alias; |
350 |
337 |
351 |
338 |
352 |
339 |
353 (** init and exit **) |
340 (** manage targets **) |
354 |
341 |
355 (* init *) |
342 (* outermost target *) |
356 |
343 |
357 fun init background_naming operations target = |
344 fun init background_naming operations target = |
358 target |> Data.map |
345 target |> Data.map |
359 (fn [] => [make_lthy (background_naming, operations, I, false, target)] |
346 (fn [] => [make_lthy (background_naming, operations, I, false, target)] |
360 | _ => error "Local theory already initialized"); |
347 | _ => error "Local theory already initialized"); |
361 |
348 |
362 |
|
363 (* exit *) |
|
364 |
|
365 val exit = operation #exit; |
349 val exit = operation #exit; |
366 val exit_global = Proof_Context.theory_of o exit; |
350 val exit_global = Proof_Context.theory_of o exit; |
367 |
351 |
368 fun exit_result f (x, lthy) = |
352 fun exit_result f (x, lthy) = |
369 let |
353 let |
376 val thy = exit_global lthy; |
360 val thy = exit_global lthy; |
377 val thy_ctxt = Proof_Context.init_global thy; |
361 val thy_ctxt = Proof_Context.init_global thy; |
378 val phi = standard_morphism lthy thy_ctxt; |
362 val phi = standard_morphism lthy thy_ctxt; |
379 in (f phi x, thy) end; |
363 in (f phi x, thy) end; |
380 |
364 |
|
365 |
|
366 (* nested targets *) |
|
367 |
|
368 fun init_target background_naming operations after_close lthy = |
|
369 let |
|
370 val _ = assert lthy; |
|
371 val (scope, target) = Proof_Context.new_scope lthy; |
|
372 val lthy' = |
|
373 target |
|
374 |> Data.map (cons (make_lthy (background_naming, operations, after_close, true, target))); |
|
375 in (scope, lthy') end; |
|
376 |
|
377 fun open_target lthy = |
|
378 init_target (background_naming_of lthy) (operations_of lthy) I lthy; |
|
379 |
|
380 fun close_target lthy = |
|
381 let |
|
382 val _ = assert_bottom false lthy; |
|
383 val ({after_close, ...} :: rest) = Data.get lthy; |
|
384 in lthy |> Data.put rest |> restore |> after_close end; |
|
385 |
381 end; |
386 end; |