author | wenzelm |
Thu, 18 May 2000 19:04:04 +0200 | |
changeset 8886 | 111476895bf2 |
parent 8807 | 0046be1769f9 |
child 9009 | 20e132267a83 |
permissions | -rw-r--r-- |
5831 | 1 |
(* Title: Pure/Isar/isar_cmd.ML |
2 |
ID: $Id$ |
|
3 |
Author: Markus Wenzel, TU Muenchen |
|
8807 | 4 |
License: GPL (GNU GENERAL PUBLIC LICENSE) |
5831 | 5 |
|
6 |
Non-logical toplevel commands. |
|
7 |
*) |
|
8 |
||
9 |
signature ISAR_CMD = |
|
10 |
sig |
|
7462 | 11 |
val welcome: Toplevel.transition -> Toplevel.transition |
12 |
val init_toplevel: Toplevel.transition -> Toplevel.transition |
|
5831 | 13 |
val exit: Toplevel.transition -> Toplevel.transition |
14 |
val quit: Toplevel.transition -> Toplevel.transition |
|
7908 | 15 |
val touch_child_thys: string -> Toplevel.transition -> Toplevel.transition |
7101 | 16 |
val touch_all_thys: Toplevel.transition -> Toplevel.transition |
17 |
val touch_thy: string -> Toplevel.transition -> Toplevel.transition |
|
18 |
val remove_thy: string -> Toplevel.transition -> Toplevel.transition |
|
7931 | 19 |
val kill_thy: string -> Toplevel.transition -> Toplevel.transition |
8463 | 20 |
val pr: string list * int option -> Toplevel.transition -> Toplevel.transition |
8453 | 21 |
val disable_pr: Toplevel.transition -> Toplevel.transition |
22 |
val enable_pr: Toplevel.transition -> Toplevel.transition |
|
6734 | 23 |
val cannot_undo: string -> Toplevel.transition -> Toplevel.transition |
7729 | 24 |
val clear_undos_theory: int -> Toplevel.transition -> Toplevel.transition |
6742 | 25 |
val redo: Toplevel.transition -> Toplevel.transition |
26 |
val undos_proof: int -> Toplevel.transition -> Toplevel.transition |
|
7936 | 27 |
val kill_proof_notify: (unit -> unit) -> Toplevel.transition -> Toplevel.transition |
6742 | 28 |
val kill_proof: Toplevel.transition -> Toplevel.transition |
29 |
val undo_theory: Toplevel.transition -> Toplevel.transition |
|
6686 | 30 |
val undo: Toplevel.transition -> Toplevel.transition |
8498 | 31 |
val kill: Toplevel.transition -> Toplevel.transition |
5831 | 32 |
val use: string -> Toplevel.transition -> Toplevel.transition |
33 |
val use_mltext_theory: string -> Toplevel.transition -> Toplevel.transition |
|
7891 | 34 |
val use_mltext: bool -> string -> Toplevel.transition -> Toplevel.transition |
5831 | 35 |
val use_commit: Toplevel.transition -> Toplevel.transition |
36 |
val cd: string -> Toplevel.transition -> Toplevel.transition |
|
37 |
val pwd: Toplevel.transition -> Toplevel.transition |
|
38 |
val use_thy: string -> Toplevel.transition -> Toplevel.transition |
|
6694 | 39 |
val use_thy_only: string -> Toplevel.transition -> Toplevel.transition |
6195 | 40 |
val update_thy: string -> Toplevel.transition -> Toplevel.transition |
7101 | 41 |
val update_thy_only: string -> Toplevel.transition -> Toplevel.transition |
7124 | 42 |
val pretty_setmargin: int -> Toplevel.transition -> Toplevel.transition |
7308 | 43 |
val print_context: Toplevel.transition -> Toplevel.transition |
5831 | 44 |
val print_theory: Toplevel.transition -> Toplevel.transition |
45 |
val print_syntax: Toplevel.transition -> Toplevel.transition |
|
5880 | 46 |
val print_theorems: Toplevel.transition -> Toplevel.transition |
5831 | 47 |
val print_attributes: Toplevel.transition -> Toplevel.transition |
48 |
val print_methods: Toplevel.transition -> Toplevel.transition |
|
7615 | 49 |
val print_thms_containing: xstring list -> Toplevel.transition -> Toplevel.transition |
5831 | 50 |
val print_binds: Toplevel.transition -> Toplevel.transition |
51 |
val print_lthms: Toplevel.transition -> Toplevel.transition |
|
8369 | 52 |
val print_cases: Toplevel.transition -> Toplevel.transition |
8463 | 53 |
val print_thms: string list * (string * Args.src list) list |
54 |
-> Toplevel.transition -> Toplevel.transition |
|
55 |
val print_prop: string list * string -> Toplevel.transition -> Toplevel.transition |
|
56 |
val print_term: string list * string -> Toplevel.transition -> Toplevel.transition |
|
57 |
val print_type: string list * string -> Toplevel.transition -> Toplevel.transition |
|
5831 | 58 |
end; |
59 |
||
60 |
structure IsarCmd: ISAR_CMD = |
|
61 |
struct |
|
62 |
||
63 |
||
7462 | 64 |
(* variations on init / exit *) |
65 |
||
66 |
val init_toplevel = Toplevel.imperative (fn () => raise Toplevel.RESTART); |
|
67 |
val welcome = Toplevel.imperative (writeln o Session.welcome); |
|
5831 | 68 |
|
69 |
val exit = Toplevel.keep (fn state => |
|
70 |
(Context.set_context (try Toplevel.theory_of state); |
|
6635 | 71 |
writeln "Leaving the Isar loop. Invoke 'loop();' to restart."; |
5831 | 72 |
raise Toplevel.TERMINATE)); |
73 |
||
74 |
val quit = Toplevel.imperative quit; |
|
75 |
||
7101 | 76 |
|
77 |
(* touch theories *) |
|
78 |
||
7908 | 79 |
fun touch_child_thys name = Toplevel.imperative (fn () => ThyInfo.touch_child_thys name); |
7101 | 80 |
val touch_all_thys = Toplevel.imperative ThyInfo.touch_all_thys; |
81 |
fun touch_thy name = Toplevel.imperative (fn () => ThyInfo.touch_thy name); |
|
82 |
fun remove_thy name = Toplevel.imperative (fn () => ThyInfo.remove_thy name); |
|
7931 | 83 |
fun kill_thy name = Toplevel.imperative (fn () => IsarThy.kill_theory name); |
7101 | 84 |
|
5831 | 85 |
|
8453 | 86 |
(* print state *) |
87 |
||
8463 | 88 |
fun with_modes modes e = |
89 |
Library.setmp print_mode (modes @ ! print_mode) e (); |
|
90 |
||
91 |
fun pr (ms, limit) = Toplevel.keep (fn state => |
|
92 |
((case limit of Some n => goals_limit := n | None => ()); Toplevel.quiet := false; |
|
8886 | 93 |
with_modes ms (fn () => Toplevel.print_state true state))); |
8453 | 94 |
|
95 |
val disable_pr = Toplevel.imperative (fn () => Toplevel.quiet := true); |
|
96 |
val enable_pr = Toplevel.imperative (fn () => Toplevel.quiet := false); |
|
97 |
||
98 |
||
6686 | 99 |
(* history commands *) |
100 |
||
6734 | 101 |
fun cannot_undo txt = Toplevel.imperative (fn () => error ("Cannot undo " ^ quote txt)); |
7729 | 102 |
val clear_undos_theory = Toplevel.history o History.clear; |
6686 | 103 |
val redo = Toplevel.history History.redo o Toplevel.proof ProofHistory.redo; |
104 |
||
6742 | 105 |
fun undos_proof n = Toplevel.proof (fn prf => |
106 |
if ProofHistory.is_initial prf then raise Toplevel.UNDEF else funpow n ProofHistory.undo prf); |
|
6686 | 107 |
|
7936 | 108 |
fun kill_proof_notify (f: unit -> unit) = Toplevel.history (fn hist => |
6742 | 109 |
(case History.current hist of |
110 |
Toplevel.Theory _ => raise Toplevel.UNDEF |
|
7936 | 111 |
| Toplevel.Proof _ => (f (); History.undo hist))); |
112 |
||
113 |
val kill_proof = kill_proof_notify (K ()); |
|
6686 | 114 |
|
6742 | 115 |
val undo_theory = Toplevel.history (fn hist => |
116 |
if History.is_initial hist then raise Toplevel.UNDEF else History.undo hist); |
|
6686 | 117 |
|
7413 | 118 |
val undo = Toplevel.kill o undo_theory o undos_proof 1; |
8498 | 119 |
val kill = Toplevel.kill o kill_proof; |
6686 | 120 |
|
121 |
||
5831 | 122 |
(* use ML text *) |
123 |
||
6264 | 124 |
fun use name = Toplevel.keep (fn state => |
125 |
Context.setmp (try Toplevel.theory_of state) ThyInfo.use name); |
|
5831 | 126 |
|
127 |
(*passes changes of theory context*) |
|
8349
611342539639
moved use_mltext, use_mltext_theory, use_let, use_setup to context.ML;
wenzelm
parents:
7936
diff
changeset
|
128 |
val use_mltext_theory = Toplevel.theory' o Context.use_mltext_theory; |
5831 | 129 |
|
130 |
(*ignore result theory context*) |
|
7891 | 131 |
fun use_mltext v txt = Toplevel.keep' (fn verb => fn state => |
8349
611342539639
moved use_mltext, use_mltext_theory, use_let, use_setup to context.ML;
wenzelm
parents:
7936
diff
changeset
|
132 |
(Context.use_mltext txt (v andalso verb) (try Toplevel.theory_of state))); |
5831 | 133 |
|
134 |
(*Note: commit is dynamically bound*) |
|
7891 | 135 |
val use_commit = use_mltext false "commit();"; |
5831 | 136 |
|
137 |
||
138 |
(* current working directory *) |
|
139 |
||
7790 | 140 |
fun cd dir = Toplevel.imperative (fn () => (File.cd (Path.unpack dir))); |
141 |
val pwd = Toplevel.imperative (fn () => writeln (Path.pack (File.pwd ()))); |
|
5831 | 142 |
|
143 |
||
144 |
(* load theory files *) |
|
145 |
||
6243 | 146 |
fun use_thy name = Toplevel.imperative (fn () => Context.save ThyInfo.use_thy name); |
6694 | 147 |
fun use_thy_only name = Toplevel.imperative (fn () => Context.save ThyInfo.use_thy_only name); |
6243 | 148 |
fun update_thy name = Toplevel.imperative (fn () => Context.save ThyInfo.update_thy name); |
7124 | 149 |
fun update_thy_only name = |
150 |
Toplevel.imperative (fn () => Context.save ThyInfo.update_thy_only name); |
|
151 |
||
152 |
||
153 |
(* pretty_setmargin *) |
|
154 |
||
155 |
fun pretty_setmargin n = Toplevel.imperative (fn () => Pretty.setmargin n); |
|
5831 | 156 |
|
157 |
||
7308 | 158 |
(* print theory *) |
5831 | 159 |
|
7308 | 160 |
val print_context = Toplevel.keep Toplevel.print_state_context; |
5831 | 161 |
val print_theory = Toplevel.keep (PureThy.print_theory o Toplevel.theory_of); |
162 |
val print_syntax = Toplevel.keep (Display.print_syntax o Toplevel.theory_of); |
|
5880 | 163 |
val print_theorems = Toplevel.keep (PureThy.print_theorems o Toplevel.theory_of); |
5831 | 164 |
val print_attributes = Toplevel.keep (Attrib.print_attributes o Toplevel.theory_of); |
165 |
val print_methods = Toplevel.keep (Method.print_methods o Toplevel.theory_of); |
|
166 |
||
7615 | 167 |
fun print_thms_containing cs = Toplevel.keep (fn state => |
168 |
ThmDatabase.print_thms_containing (Toplevel.theory_of state) cs); |
|
169 |
||
5831 | 170 |
|
171 |
(* print proof context contents *) |
|
172 |
||
173 |
val print_binds = Toplevel.keep (ProofContext.print_binds o Proof.context_of o Toplevel.proof_of); |
|
174 |
val print_lthms = Toplevel.keep (ProofContext.print_thms o Proof.context_of o Toplevel.proof_of); |
|
8369 | 175 |
val print_cases = Toplevel.keep (ProofContext.print_cases o Proof.context_of o Toplevel.proof_of); |
5831 | 176 |
|
177 |
||
7012 | 178 |
(* print theorems / types / terms / props *) |
5880 | 179 |
|
8463 | 180 |
fun print_thms (ms, args) = Toplevel.keep (fn state => |
8498 | 181 |
let |
182 |
val st = Toplevel.node_case Proof.init_state Proof.enter_forward state; |
|
183 |
val transfer = Thm.transfer (Toplevel.theory_of state); |
|
184 |
in |
|
185 |
with_modes ms (fn () => |
|
186 |
Pretty.writeln (Proof.pretty_thms (map transfer (IsarThy.get_thmss args st)))) |
|
187 |
end); |
|
5895 | 188 |
|
8463 | 189 |
fun print_type (ms, s) = Toplevel.keep (fn state => |
5831 | 190 |
let |
191 |
val sign = Toplevel.sign_of state; |
|
7503 | 192 |
val T = ProofContext.read_typ (Toplevel.context_of state) s; |
8463 | 193 |
in with_modes ms (fn () => Pretty.writeln (Pretty.quote (Sign.pretty_typ sign T))) end); |
5831 | 194 |
|
8463 | 195 |
fun print_term (ms, s) = Toplevel.keep (fn state => |
5831 | 196 |
let |
197 |
val sign = Toplevel.sign_of state; |
|
7503 | 198 |
val t = ProofContext.read_term (Toplevel.context_of state) s; |
5831 | 199 |
val T = Term.type_of t; |
200 |
in |
|
8463 | 201 |
with_modes ms (fn () => Pretty.writeln |
202 |
(Pretty.block [Pretty.quote (Sign.pretty_term sign t), Pretty.fbrk, |
|
203 |
Pretty.str "::", Pretty.brk 1, Pretty.quote (Sign.pretty_typ sign T)])) |
|
5831 | 204 |
end); |
205 |
||
8463 | 206 |
fun print_prop (ms, s) = Toplevel.keep (fn state => |
5831 | 207 |
let |
208 |
val sign = Toplevel.sign_of state; |
|
7503 | 209 |
val prop = ProofContext.read_prop (Toplevel.context_of state) s; |
8463 | 210 |
in with_modes ms (fn () => Pretty.writeln (Pretty.quote (Sign.pretty_term sign prop))) end); |
5831 | 211 |
|
212 |
||
213 |
end; |