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
|
|
10 |
val break: Toplevel.transition -> Toplevel.transition
|
|
11 |
val exit: Toplevel.transition -> Toplevel.transition
|
5991
|
12 |
val restart: Toplevel.transition -> Toplevel.transition
|
5831
|
13 |
val quit: Toplevel.transition -> Toplevel.transition
|
6734
|
14 |
val cannot_undo: string -> Toplevel.transition -> Toplevel.transition
|
6686
|
15 |
val clear_undo: Toplevel.transition -> Toplevel.transition
|
|
16 |
val undo: Toplevel.transition -> Toplevel.transition
|
|
17 |
val redo: Toplevel.transition -> Toplevel.transition
|
|
18 |
val undos: int -> Toplevel.transition -> Toplevel.transition
|
5831
|
19 |
val use: string -> Toplevel.transition -> Toplevel.transition
|
|
20 |
val use_mltext_theory: string -> Toplevel.transition -> Toplevel.transition
|
|
21 |
val use_mltext: string -> Toplevel.transition -> Toplevel.transition
|
|
22 |
val use_commit: Toplevel.transition -> Toplevel.transition
|
|
23 |
val cd: string -> Toplevel.transition -> Toplevel.transition
|
|
24 |
val pwd: Toplevel.transition -> Toplevel.transition
|
|
25 |
val use_thy: string -> Toplevel.transition -> Toplevel.transition
|
6694
|
26 |
val use_thy_only: string -> Toplevel.transition -> Toplevel.transition
|
6195
|
27 |
val update_thy: string -> Toplevel.transition -> Toplevel.transition
|
5831
|
28 |
val print_theory: Toplevel.transition -> Toplevel.transition
|
|
29 |
val print_syntax: Toplevel.transition -> Toplevel.transition
|
5880
|
30 |
val print_theorems: Toplevel.transition -> Toplevel.transition
|
5831
|
31 |
val print_attributes: Toplevel.transition -> Toplevel.transition
|
|
32 |
val print_methods: Toplevel.transition -> Toplevel.transition
|
|
33 |
val print_binds: Toplevel.transition -> Toplevel.transition
|
|
34 |
val print_lthms: Toplevel.transition -> Toplevel.transition
|
5880
|
35 |
val print_thms: xstring * Args.src list -> Toplevel.transition -> Toplevel.transition
|
5831
|
36 |
val print_prop: string -> Toplevel.transition -> Toplevel.transition
|
|
37 |
val print_term: string -> Toplevel.transition -> Toplevel.transition
|
|
38 |
val print_type: string -> Toplevel.transition -> Toplevel.transition
|
|
39 |
end;
|
|
40 |
|
|
41 |
structure IsarCmd: ISAR_CMD =
|
|
42 |
struct
|
|
43 |
|
|
44 |
|
|
45 |
(* variations on exit *)
|
|
46 |
|
5913
|
47 |
val break = Toplevel.keep (fn state => raise Toplevel.BREAK state);
|
5831
|
48 |
|
|
49 |
val exit = Toplevel.keep (fn state =>
|
|
50 |
(Context.set_context (try Toplevel.theory_of state);
|
6635
|
51 |
writeln "Leaving the Isar loop. Invoke 'loop();' to restart.";
|
5831
|
52 |
raise Toplevel.TERMINATE));
|
|
53 |
|
5991
|
54 |
val restart = Toplevel.imperative (fn () => raise Toplevel.RESTART);
|
5831
|
55 |
val quit = Toplevel.imperative quit;
|
|
56 |
|
|
57 |
|
6686
|
58 |
(* history commands *)
|
|
59 |
|
6734
|
60 |
fun cannot_undo txt = Toplevel.imperative (fn () => error ("Cannot undo " ^ quote txt));
|
|
61 |
|
6686
|
62 |
val clear_undo = Toplevel.history History.clear o Toplevel.proof ProofHistory.clear;
|
|
63 |
val redo = Toplevel.history History.redo o Toplevel.proof ProofHistory.redo;
|
|
64 |
|
|
65 |
fun undo_proof prf =
|
|
66 |
if ProofHistory.is_initial prf then raise Toplevel.UNDEF else ProofHistory.undo prf;
|
|
67 |
|
|
68 |
fun undo_node hist =
|
|
69 |
if History.is_initial hist then raise Toplevel.UNDEF else History.undo hist;
|
|
70 |
|
|
71 |
val undo = Toplevel.kill o Toplevel.history undo_node o Toplevel.proof undo_proof;
|
|
72 |
|
|
73 |
(* FIXME fix *)
|
|
74 |
fun undos n = Toplevel.history (funpow n History.undo) o Toplevel.proof (funpow n undo_proof);
|
|
75 |
|
|
76 |
|
5831
|
77 |
(* use ML text *)
|
|
78 |
|
6264
|
79 |
fun use name = Toplevel.keep (fn state =>
|
|
80 |
Context.setmp (try Toplevel.theory_of state) ThyInfo.use name);
|
5831
|
81 |
|
|
82 |
(*passes changes of theory context*)
|
|
83 |
val use_mltext_theory = Toplevel.theory o IsarThy.use_mltext_theory;
|
|
84 |
|
|
85 |
(*ignore result theory context*)
|
|
86 |
fun use_mltext txt = Toplevel.keep (fn state =>
|
|
87 |
(IsarThy.use_mltext txt (try Toplevel.theory_of state); ()));
|
|
88 |
|
|
89 |
(*Note: commit is dynamically bound*)
|
|
90 |
val use_commit = use_mltext "commit();";
|
|
91 |
|
|
92 |
|
|
93 |
(* current working directory *)
|
|
94 |
|
6228
|
95 |
fun print_cd _ = writeln (Path.pack (File.pwd ()));
|
5831
|
96 |
|
6228
|
97 |
fun cd dir = Toplevel.imperative (fn () => (File.cd (Path.unpack dir); print_cd ()));
|
5831
|
98 |
val pwd = Toplevel.imperative print_cd;
|
|
99 |
|
|
100 |
|
|
101 |
(* load theory files *)
|
|
102 |
|
6243
|
103 |
fun use_thy name = Toplevel.imperative (fn () => Context.save ThyInfo.use_thy name);
|
6694
|
104 |
fun use_thy_only name = Toplevel.imperative (fn () => Context.save ThyInfo.use_thy_only name);
|
6243
|
105 |
fun update_thy name = Toplevel.imperative (fn () => Context.save ThyInfo.update_thy name);
|
5831
|
106 |
|
|
107 |
|
|
108 |
(* print theory contents *)
|
|
109 |
|
|
110 |
val print_theory = Toplevel.keep (PureThy.print_theory o Toplevel.theory_of);
|
|
111 |
val print_syntax = Toplevel.keep (Display.print_syntax o Toplevel.theory_of);
|
5880
|
112 |
val print_theorems = Toplevel.keep (PureThy.print_theorems o Toplevel.theory_of);
|
5831
|
113 |
val print_attributes = Toplevel.keep (Attrib.print_attributes o Toplevel.theory_of);
|
|
114 |
val print_methods = Toplevel.keep (Method.print_methods o Toplevel.theory_of);
|
|
115 |
|
|
116 |
|
|
117 |
(* print proof context contents *)
|
|
118 |
|
|
119 |
val print_binds = Toplevel.keep (ProofContext.print_binds o Proof.context_of o Toplevel.proof_of);
|
|
120 |
val print_lthms = Toplevel.keep (ProofContext.print_thms o Proof.context_of o Toplevel.proof_of);
|
|
121 |
|
|
122 |
|
|
123 |
(* print theorems *)
|
|
124 |
|
5880
|
125 |
fun global_attribs thy ths srcs =
|
6091
|
126 |
#2 (Thm.applys_attributes ((Theory.copy thy, ths), map (Attrib.global_attribute thy) srcs));
|
5880
|
127 |
|
|
128 |
fun local_attribs st ths srcs =
|
6091
|
129 |
#2 (Thm.applys_attributes ((Proof.context_of st, ths),
|
5880
|
130 |
map (Attrib.local_attribute (Proof.theory_of st)) srcs));
|
|
131 |
|
5913
|
132 |
fun print_thms (name, srcs) = Toplevel.keep (fn state =>
|
5831
|
133 |
let
|
6091
|
134 |
val ths = map (Thm.transfer (Toplevel.theory_of state))
|
6662
|
135 |
(Toplevel.node_case PureThy.get_thms (ProofContext.get_thms o Proof.context_of)
|
5831
|
136 |
state name);
|
6662
|
137 |
val ths' = Toplevel.node_case global_attribs local_attribs state ths srcs;
|
6091
|
138 |
in Display.print_thms ths' end);
|
5895
|
139 |
|
5831
|
140 |
|
|
141 |
(* print types, terms and props *)
|
|
142 |
|
|
143 |
fun read_typ thy = Sign.read_typ (Theory.sign_of thy, K None);
|
|
144 |
|
|
145 |
fun read_term T thy s =
|
|
146 |
Thm.term_of (#1 (Thm.read_def_cterm (Theory.sign_of thy, K None, K None) [] true (s, T)));
|
|
147 |
|
|
148 |
|
|
149 |
fun print_type s = Toplevel.keep (fn state =>
|
|
150 |
let
|
|
151 |
val sign = Toplevel.sign_of state;
|
6662
|
152 |
val T = Toplevel.node_case read_typ (ProofContext.read_typ o Proof.context_of) state s;
|
5831
|
153 |
in Pretty.writeln (Pretty.quote (Sign.pretty_typ sign T)) end);
|
|
154 |
|
|
155 |
fun print_term s = Toplevel.keep (fn state =>
|
|
156 |
let
|
|
157 |
val sign = Toplevel.sign_of state;
|
6662
|
158 |
val t = Toplevel.node_case (read_term (TVar (("'z", 0), logicS)))
|
5831
|
159 |
(ProofContext.read_term o Proof.context_of) state s;
|
|
160 |
val T = Term.type_of t;
|
|
161 |
in
|
|
162 |
Pretty.writeln (Pretty.block [Pretty.quote (Sign.pretty_term sign t), Pretty.fbrk,
|
|
163 |
Pretty.str "::", Pretty.brk 1, Pretty.quote (Sign.pretty_typ sign T)])
|
|
164 |
end);
|
|
165 |
|
|
166 |
fun print_prop s = Toplevel.keep (fn state =>
|
|
167 |
let
|
|
168 |
val sign = Toplevel.sign_of state;
|
|
169 |
val prop =
|
6662
|
170 |
Toplevel.node_case (read_term propT) (ProofContext.read_prop o Proof.context_of) state s;
|
5831
|
171 |
in Pretty.writeln (Pretty.quote (Sign.pretty_term sign prop)) end);
|
|
172 |
|
|
173 |
|
|
174 |
end;
|