5831
|
1 |
(* Title: Pure/Isar/isar_cmd.ML
|
|
2 |
ID: $Id$
|
|
3 |
Author: Markus Wenzel, TU Muenchen
|
|
4 |
|
|
5 |
Non-logical toplevel commands.
|
|
6 |
*)
|
|
7 |
|
|
8 |
signature ISAR_CMD =
|
|
9 |
sig
|
7462
|
10 |
val welcome: Toplevel.transition -> Toplevel.transition
|
|
11 |
val init_toplevel: Toplevel.transition -> Toplevel.transition
|
5831
|
12 |
val exit: Toplevel.transition -> Toplevel.transition
|
|
13 |
val quit: Toplevel.transition -> Toplevel.transition
|
7101
|
14 |
val touch_all_thys: Toplevel.transition -> Toplevel.transition
|
|
15 |
val touch_thy: string -> Toplevel.transition -> Toplevel.transition
|
|
16 |
val remove_thy: string -> Toplevel.transition -> Toplevel.transition
|
6734
|
17 |
val cannot_undo: string -> Toplevel.transition -> Toplevel.transition
|
7729
|
18 |
val clear_undos_theory: int -> Toplevel.transition -> Toplevel.transition
|
6742
|
19 |
val redo: Toplevel.transition -> Toplevel.transition
|
|
20 |
val undos_proof: int -> Toplevel.transition -> Toplevel.transition
|
|
21 |
val kill_proof: Toplevel.transition -> Toplevel.transition
|
|
22 |
val undo_theory: Toplevel.transition -> Toplevel.transition
|
6686
|
23 |
val undo: Toplevel.transition -> Toplevel.transition
|
5831
|
24 |
val use: string -> Toplevel.transition -> Toplevel.transition
|
|
25 |
val use_mltext_theory: string -> Toplevel.transition -> Toplevel.transition
|
|
26 |
val use_mltext: string -> Toplevel.transition -> Toplevel.transition
|
|
27 |
val use_commit: Toplevel.transition -> Toplevel.transition
|
|
28 |
val cd: string -> Toplevel.transition -> Toplevel.transition
|
|
29 |
val pwd: Toplevel.transition -> Toplevel.transition
|
|
30 |
val use_thy: string -> Toplevel.transition -> Toplevel.transition
|
6694
|
31 |
val use_thy_only: string -> Toplevel.transition -> Toplevel.transition
|
6195
|
32 |
val update_thy: string -> Toplevel.transition -> Toplevel.transition
|
7101
|
33 |
val update_thy_only: string -> Toplevel.transition -> Toplevel.transition
|
7124
|
34 |
val pretty_setmargin: int -> Toplevel.transition -> Toplevel.transition
|
7308
|
35 |
val print_context: Toplevel.transition -> Toplevel.transition
|
5831
|
36 |
val print_theory: Toplevel.transition -> Toplevel.transition
|
|
37 |
val print_syntax: Toplevel.transition -> Toplevel.transition
|
5880
|
38 |
val print_theorems: Toplevel.transition -> Toplevel.transition
|
5831
|
39 |
val print_attributes: Toplevel.transition -> Toplevel.transition
|
|
40 |
val print_methods: Toplevel.transition -> Toplevel.transition
|
7615
|
41 |
val print_thms_containing: xstring list -> Toplevel.transition -> Toplevel.transition
|
5831
|
42 |
val print_binds: Toplevel.transition -> Toplevel.transition
|
|
43 |
val print_lthms: Toplevel.transition -> Toplevel.transition
|
7012
|
44 |
val print_thms: (string * Args.src list) list -> Toplevel.transition -> Toplevel.transition
|
5831
|
45 |
val print_prop: string -> Toplevel.transition -> Toplevel.transition
|
|
46 |
val print_term: string -> Toplevel.transition -> Toplevel.transition
|
|
47 |
val print_type: string -> Toplevel.transition -> Toplevel.transition
|
|
48 |
end;
|
|
49 |
|
|
50 |
structure IsarCmd: ISAR_CMD =
|
|
51 |
struct
|
|
52 |
|
|
53 |
|
7462
|
54 |
(* variations on init / exit *)
|
|
55 |
|
|
56 |
val init_toplevel = Toplevel.imperative (fn () => raise Toplevel.RESTART);
|
|
57 |
val welcome = Toplevel.imperative (writeln o Session.welcome);
|
5831
|
58 |
|
|
59 |
val exit = Toplevel.keep (fn state =>
|
|
60 |
(Context.set_context (try Toplevel.theory_of state);
|
6635
|
61 |
writeln "Leaving the Isar loop. Invoke 'loop();' to restart.";
|
5831
|
62 |
raise Toplevel.TERMINATE));
|
|
63 |
|
|
64 |
val quit = Toplevel.imperative quit;
|
|
65 |
|
7101
|
66 |
|
|
67 |
(* touch theories *)
|
|
68 |
|
|
69 |
val touch_all_thys = Toplevel.imperative ThyInfo.touch_all_thys;
|
|
70 |
fun touch_thy name = Toplevel.imperative (fn () => ThyInfo.touch_thy name);
|
|
71 |
fun remove_thy name = Toplevel.imperative (fn () => ThyInfo.remove_thy name);
|
|
72 |
|
5831
|
73 |
|
6686
|
74 |
(* history commands *)
|
|
75 |
|
6734
|
76 |
fun cannot_undo txt = Toplevel.imperative (fn () => error ("Cannot undo " ^ quote txt));
|
7729
|
77 |
val clear_undos_theory = Toplevel.history o History.clear;
|
6686
|
78 |
val redo = Toplevel.history History.redo o Toplevel.proof ProofHistory.redo;
|
|
79 |
|
6742
|
80 |
fun undos_proof n = Toplevel.proof (fn prf =>
|
|
81 |
if ProofHistory.is_initial prf then raise Toplevel.UNDEF else funpow n ProofHistory.undo prf);
|
6686
|
82 |
|
6742
|
83 |
val kill_proof = Toplevel.history (fn hist =>
|
|
84 |
(case History.current hist of
|
|
85 |
Toplevel.Theory _ => raise Toplevel.UNDEF
|
|
86 |
| Toplevel.Proof _ => History.undo hist));
|
6686
|
87 |
|
6742
|
88 |
val undo_theory = Toplevel.history (fn hist =>
|
|
89 |
if History.is_initial hist then raise Toplevel.UNDEF else History.undo hist);
|
6686
|
90 |
|
7413
|
91 |
val undo = Toplevel.kill o undo_theory o undos_proof 1;
|
6686
|
92 |
|
|
93 |
|
5831
|
94 |
(* use ML text *)
|
|
95 |
|
6264
|
96 |
fun use name = Toplevel.keep (fn state =>
|
|
97 |
Context.setmp (try Toplevel.theory_of state) ThyInfo.use name);
|
5831
|
98 |
|
|
99 |
(*passes changes of theory context*)
|
7615
|
100 |
val use_mltext_theory = Toplevel.theory' o IsarThy.use_mltext_theory;
|
5831
|
101 |
|
|
102 |
(*ignore result theory context*)
|
7615
|
103 |
fun use_mltext txt = Toplevel.keep' (fn verb => fn state =>
|
|
104 |
(IsarThy.use_mltext txt verb (try Toplevel.theory_of state)));
|
5831
|
105 |
|
|
106 |
(*Note: commit is dynamically bound*)
|
|
107 |
val use_commit = use_mltext "commit();";
|
|
108 |
|
|
109 |
|
|
110 |
(* current working directory *)
|
|
111 |
|
6228
|
112 |
fun print_cd _ = writeln (Path.pack (File.pwd ()));
|
5831
|
113 |
|
6228
|
114 |
fun cd dir = Toplevel.imperative (fn () => (File.cd (Path.unpack dir); print_cd ()));
|
5831
|
115 |
val pwd = Toplevel.imperative print_cd;
|
|
116 |
|
|
117 |
|
|
118 |
(* load theory files *)
|
|
119 |
|
6243
|
120 |
fun use_thy name = Toplevel.imperative (fn () => Context.save ThyInfo.use_thy name);
|
6694
|
121 |
fun use_thy_only name = Toplevel.imperative (fn () => Context.save ThyInfo.use_thy_only name);
|
6243
|
122 |
fun update_thy name = Toplevel.imperative (fn () => Context.save ThyInfo.update_thy name);
|
7124
|
123 |
fun update_thy_only name =
|
|
124 |
Toplevel.imperative (fn () => Context.save ThyInfo.update_thy_only name);
|
|
125 |
|
|
126 |
|
|
127 |
(* pretty_setmargin *)
|
|
128 |
|
|
129 |
fun pretty_setmargin n = Toplevel.imperative (fn () => Pretty.setmargin n);
|
5831
|
130 |
|
|
131 |
|
7308
|
132 |
(* print theory *)
|
5831
|
133 |
|
7308
|
134 |
val print_context = Toplevel.keep Toplevel.print_state_context;
|
5831
|
135 |
val print_theory = Toplevel.keep (PureThy.print_theory o Toplevel.theory_of);
|
|
136 |
val print_syntax = Toplevel.keep (Display.print_syntax o Toplevel.theory_of);
|
5880
|
137 |
val print_theorems = Toplevel.keep (PureThy.print_theorems o Toplevel.theory_of);
|
5831
|
138 |
val print_attributes = Toplevel.keep (Attrib.print_attributes o Toplevel.theory_of);
|
|
139 |
val print_methods = Toplevel.keep (Method.print_methods o Toplevel.theory_of);
|
|
140 |
|
7615
|
141 |
fun print_thms_containing cs = Toplevel.keep (fn state =>
|
|
142 |
ThmDatabase.print_thms_containing (Toplevel.theory_of state) cs);
|
|
143 |
|
5831
|
144 |
|
|
145 |
(* print proof context contents *)
|
|
146 |
|
|
147 |
val print_binds = Toplevel.keep (ProofContext.print_binds o Proof.context_of o Toplevel.proof_of);
|
|
148 |
val print_lthms = Toplevel.keep (ProofContext.print_thms o Proof.context_of o Toplevel.proof_of);
|
|
149 |
|
|
150 |
|
7012
|
151 |
(* print theorems / types / terms / props *)
|
5880
|
152 |
|
7012
|
153 |
fun print_thms args = Toplevel.keep (fn state =>
|
|
154 |
let val st = Toplevel.node_case Proof.init_state Proof.enter_forward state
|
7413
|
155 |
in Pretty.writeln (Proof.pretty_thms (IsarThy.get_thmss args st)) end);
|
5895
|
156 |
|
5831
|
157 |
fun print_type s = Toplevel.keep (fn state =>
|
|
158 |
let
|
|
159 |
val sign = Toplevel.sign_of state;
|
7503
|
160 |
val T = ProofContext.read_typ (Toplevel.context_of state) s;
|
5831
|
161 |
in Pretty.writeln (Pretty.quote (Sign.pretty_typ sign T)) end);
|
|
162 |
|
|
163 |
fun print_term s = Toplevel.keep (fn state =>
|
|
164 |
let
|
|
165 |
val sign = Toplevel.sign_of state;
|
7503
|
166 |
val t = ProofContext.read_term (Toplevel.context_of state) s;
|
5831
|
167 |
val T = Term.type_of t;
|
|
168 |
in
|
|
169 |
Pretty.writeln (Pretty.block [Pretty.quote (Sign.pretty_term sign t), Pretty.fbrk,
|
|
170 |
Pretty.str "::", Pretty.brk 1, Pretty.quote (Sign.pretty_typ sign T)])
|
|
171 |
end);
|
|
172 |
|
|
173 |
fun print_prop s = Toplevel.keep (fn state =>
|
|
174 |
let
|
|
175 |
val sign = Toplevel.sign_of state;
|
7503
|
176 |
val prop = ProofContext.read_prop (Toplevel.context_of state) s;
|
5831
|
177 |
in Pretty.writeln (Pretty.quote (Sign.pretty_term sign prop)) end);
|
|
178 |
|
|
179 |
|
|
180 |
end;
|