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