4338
|
1 |
(* Title: Pure/Thy/context.ML
|
|
2 |
ID: $Id$
|
|
3 |
Author: Markus Wenzel, TU Muenchen
|
|
4 |
|
|
5 |
Global contexts: session and theory.
|
|
6 |
*)
|
|
7 |
|
4486
|
8 |
signature BASIC_CONTEXT =
|
4338
|
9 |
sig
|
|
10 |
val context: theory -> unit
|
5049
|
11 |
val the_context: unit -> theory
|
5059
|
12 |
val thm: xstring -> thm
|
|
13 |
val thms: xstring -> thm list
|
4914
|
14 |
val Goal: string -> thm list
|
|
15 |
val Goalw: thm list -> string -> thm list
|
5249
|
16 |
val Open_locale: xstring -> unit
|
6022
|
17 |
val Close_locale: xstring -> unit
|
|
18 |
val Print_scope: unit -> unit
|
6017
|
19 |
val Export: thm -> thm
|
4338
|
20 |
end;
|
|
21 |
|
4486
|
22 |
signature CONTEXT =
|
|
23 |
sig
|
|
24 |
include BASIC_CONTEXT
|
5031
|
25 |
val get_session: unit -> string list
|
|
26 |
val add_session: string -> unit
|
|
27 |
val reset_session: unit -> unit
|
4925
|
28 |
val welcome: unit -> string
|
5031
|
29 |
val get_context: unit -> theory option
|
|
30 |
val set_context: theory option -> unit
|
|
31 |
val reset_context: unit -> unit
|
4486
|
32 |
val >> : (theory -> theory) -> unit
|
|
33 |
end;
|
|
34 |
|
4338
|
35 |
structure Context: CONTEXT =
|
|
36 |
struct
|
|
37 |
|
|
38 |
|
4843
|
39 |
(** session **)
|
4338
|
40 |
|
|
41 |
val current_session = ref ([]: string list);
|
|
42 |
|
|
43 |
fun get_session () = ! current_session;
|
|
44 |
fun add_session s = current_session := ! current_session @ [s];
|
|
45 |
fun reset_session () = current_session := [];
|
|
46 |
|
4925
|
47 |
fun welcome () =
|
|
48 |
"Welcome to Isabelle/" ^
|
|
49 |
(case get_session () of [] => "Pure" | ss => space_implode "/" ss) ^
|
|
50 |
" (" ^ version ^ ")";
|
|
51 |
|
4338
|
52 |
|
4843
|
53 |
|
|
54 |
(** theory context **)
|
4338
|
55 |
|
5027
|
56 |
local
|
|
57 |
val current_theory = ref (None: theory option);
|
|
58 |
in
|
|
59 |
fun get_context () = ! current_theory;
|
|
60 |
fun set_context opt_thy = current_theory := opt_thy;
|
|
61 |
end;
|
4338
|
62 |
|
5027
|
63 |
fun the_context () =
|
|
64 |
(case get_context () of
|
|
65 |
Some thy => thy
|
4364
|
66 |
| _ => error "Unknown theory context");
|
|
67 |
|
5027
|
68 |
fun context thy = set_context (Some thy);
|
|
69 |
fun reset_context () = set_context None;
|
4338
|
70 |
|
|
71 |
|
4843
|
72 |
(* map context *)
|
|
73 |
|
4486
|
74 |
nonfix >>;
|
5027
|
75 |
fun >> f = set_context (Some (f (the_context ())));
|
4486
|
76 |
|
|
77 |
|
4843
|
78 |
(* retrieve thms *)
|
|
79 |
|
5249
|
80 |
fun thm name = Locale.get_thm (the_context ()) name;
|
|
81 |
fun thms name = Locale.get_thms (the_context ()) name;
|
4843
|
82 |
|
|
83 |
|
4914
|
84 |
(* shortcut goal commands *)
|
|
85 |
|
5042
|
86 |
fun Goal s = Goals.atomic_goal (the_context ()) s;
|
|
87 |
fun Goalw thms s = Goals.atomic_goalw (the_context ()) thms s;
|
4914
|
88 |
|
|
89 |
|
5249
|
90 |
(* scope manipulation *)
|
|
91 |
|
|
92 |
fun Open_locale xname = (Locale.open_locale xname (the_context ()); ());
|
6022
|
93 |
fun Close_locale xname = (Locale.close_locale xname (the_context ()); ());
|
|
94 |
fun Print_scope () = (Locale.print_scope (the_context()); ());
|
6017
|
95 |
fun Export th = export_thy (the_context ()) th;
|
5249
|
96 |
|
4338
|
97 |
end;
|
|
98 |
|
4486
|
99 |
|
|
100 |
structure BasicContext: BASIC_CONTEXT = Context;
|
|
101 |
open BasicContext;
|