72453
|
1 |
(* Title: Pure/Isar/target_context.ML
|
|
2 |
Author: Florian Haftmann
|
|
3 |
|
|
4 |
Handling of named and nested targets at the Isar toplevel via context begin / end blocks.
|
|
5 |
*)
|
|
6 |
|
|
7 |
signature TARGET_CONTEXT =
|
|
8 |
sig
|
|
9 |
val context_begin_named_cmd: xstring * Position.T -> theory -> local_theory
|
|
10 |
val end_named_cmd: local_theory -> theory
|
|
11 |
val switch_named_cmd: (xstring * Position.T) option -> Context.generic ->
|
|
12 |
(local_theory -> Context.generic) * local_theory
|
|
13 |
val context_begin_nested_cmd: (xstring * Position.T) list -> Element.context list ->
|
|
14 |
Context.generic -> local_theory
|
|
15 |
val end_nested_cmd: local_theory -> Context.generic
|
|
16 |
end;
|
|
17 |
|
|
18 |
structure Target_Context: TARGET_CONTEXT =
|
|
19 |
struct
|
|
20 |
|
|
21 |
fun context_begin_named_cmd ("-", _) thy = Named_Target.theory_init thy
|
|
22 |
| context_begin_named_cmd target thy = Named_Target.init (Locale.check thy target) thy;
|
|
23 |
|
|
24 |
val end_named_cmd = Local_Theory.assert_bottom #> Local_Theory.exit_global;
|
|
25 |
|
|
26 |
fun switch_named_cmd NONE (Context.Theory thy) =
|
|
27 |
(Context.Theory o end_named_cmd, Named_Target.theory_init thy)
|
|
28 |
| switch_named_cmd (SOME name) (Context.Theory thy) =
|
|
29 |
(Context.Theory o end_named_cmd, context_begin_named_cmd name thy)
|
|
30 |
| switch_named_cmd NONE (Context.Proof lthy) =
|
|
31 |
(Context.Proof o Local_Theory.reset, lthy)
|
|
32 |
| switch_named_cmd (SOME name) (Context.Proof lthy) =
|
|
33 |
(Context.Proof o Named_Target.reinit lthy o end_named_cmd,
|
|
34 |
(context_begin_named_cmd name o end_named_cmd o Local_Theory.assert_nonbrittle) lthy);
|
|
35 |
|
|
36 |
fun includes raw_incls lthy =
|
|
37 |
Bundle.includes (map (Bundle.check lthy) raw_incls) lthy;
|
|
38 |
|
|
39 |
fun context_begin_nested_cmd raw_incls raw_elems gthy =
|
|
40 |
gthy
|
|
41 |
|> Context.cases Named_Target.theory_init Local_Theory.assert
|
|
42 |
|> includes raw_incls
|
|
43 |
|> Expression.read_declaration ([], []) I raw_elems
|
|
44 |
|> (#4 o fst)
|
|
45 |
|> Local_Theory.begin_nested
|
|
46 |
|> snd;
|
|
47 |
|
|
48 |
fun end_nested_cmd lthy =
|
|
49 |
if Named_Target.is_theory lthy
|
|
50 |
then Context.Theory (Local_Theory.exit_global lthy)
|
|
51 |
else Context.Proof lthy;
|
|
52 |
|
|
53 |
end;
|
|
54 |
|
|
55 |
structure Local_Theory : LOCAL_THEORY = struct open Local_Theory; end;
|