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 get_session: unit -> string list
|
|
11 |
val add_session: string -> unit
|
|
12 |
val reset_session: unit -> unit
|
|
13 |
val get_context: unit -> theory
|
|
14 |
val context: theory -> unit
|
4364
|
15 |
val reset_context: unit -> unit
|
4843
|
16 |
val thm: xstring -> thm
|
|
17 |
val thms: xstring -> thm list
|
4914
|
18 |
val Goal: string -> thm list
|
|
19 |
val Goalw: thm list -> string -> thm list
|
4338
|
20 |
end;
|
|
21 |
|
4486
|
22 |
signature CONTEXT =
|
|
23 |
sig
|
|
24 |
include BASIC_CONTEXT
|
|
25 |
val >> : (theory -> theory) -> unit
|
|
26 |
end;
|
|
27 |
|
4338
|
28 |
structure Context: CONTEXT =
|
|
29 |
struct
|
|
30 |
|
|
31 |
|
4843
|
32 |
(** session **)
|
4338
|
33 |
|
|
34 |
val current_session = ref ([]: string list);
|
|
35 |
|
|
36 |
fun get_session () = ! current_session;
|
|
37 |
fun add_session s = current_session := ! current_session @ [s];
|
|
38 |
fun reset_session () = current_session := [];
|
|
39 |
|
|
40 |
|
4843
|
41 |
|
|
42 |
(** theory context **)
|
4338
|
43 |
|
4364
|
44 |
val current_theory = ref (None: theory option);
|
4338
|
45 |
|
4364
|
46 |
fun get_context () =
|
|
47 |
(case current_theory of
|
|
48 |
ref (Some thy) => thy
|
|
49 |
| _ => error "Unknown theory context");
|
|
50 |
|
|
51 |
fun context thy = current_theory := Some thy;
|
|
52 |
fun reset_context () = current_theory := None;
|
4338
|
53 |
|
|
54 |
|
4843
|
55 |
(* map context *)
|
|
56 |
|
4486
|
57 |
nonfix >>;
|
|
58 |
fun >> f = current_theory := Some (f (get_context ()));
|
|
59 |
|
|
60 |
|
4843
|
61 |
(* retrieve thms *)
|
|
62 |
|
|
63 |
fun thm name = PureThy.get_thm (get_context ()) name;
|
|
64 |
fun thms name = PureThy.get_thms (get_context ()) name;
|
|
65 |
|
|
66 |
|
4914
|
67 |
(* shortcut goal commands *)
|
|
68 |
|
|
69 |
fun Goal s = Goals.goal (get_context ()) s;
|
|
70 |
fun Goalw thms s = Goals.goalw (get_context ()) thms s;
|
|
71 |
|
|
72 |
|
4338
|
73 |
end;
|
|
74 |
|
4486
|
75 |
|
|
76 |
structure BasicContext: BASIC_CONTEXT = Context;
|
|
77 |
open BasicContext;
|