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
|
|
12 |
val quit: Toplevel.transition -> Toplevel.transition
|
|
13 |
val use: string -> Toplevel.transition -> Toplevel.transition
|
|
14 |
val use_mltext_theory: string -> Toplevel.transition -> Toplevel.transition
|
|
15 |
val use_mltext: string -> Toplevel.transition -> Toplevel.transition
|
|
16 |
val use_commit: Toplevel.transition -> Toplevel.transition
|
|
17 |
val cd: string -> Toplevel.transition -> Toplevel.transition
|
|
18 |
val pwd: Toplevel.transition -> Toplevel.transition
|
|
19 |
val use_thy: string -> Toplevel.transition -> Toplevel.transition
|
|
20 |
val load: string -> Toplevel.transition -> Toplevel.transition
|
|
21 |
val print_theory: Toplevel.transition -> Toplevel.transition
|
|
22 |
val print_syntax: Toplevel.transition -> Toplevel.transition
|
|
23 |
val print_attributes: Toplevel.transition -> Toplevel.transition
|
|
24 |
val print_methods: Toplevel.transition -> Toplevel.transition
|
|
25 |
val print_binds: Toplevel.transition -> Toplevel.transition
|
|
26 |
val print_lthms: Toplevel.transition -> Toplevel.transition
|
|
27 |
val print_thms: xstring -> Toplevel.transition -> Toplevel.transition
|
|
28 |
val print_prop: string -> Toplevel.transition -> Toplevel.transition
|
|
29 |
val print_term: string -> Toplevel.transition -> Toplevel.transition
|
|
30 |
val print_type: string -> Toplevel.transition -> Toplevel.transition
|
|
31 |
end;
|
|
32 |
|
|
33 |
structure IsarCmd: ISAR_CMD =
|
|
34 |
struct
|
|
35 |
|
|
36 |
|
|
37 |
(* variations on exit *)
|
|
38 |
|
|
39 |
val break = Toplevel.imperative (fn () => raise Toplevel.BREAK);
|
|
40 |
|
|
41 |
val exit = Toplevel.keep (fn state =>
|
|
42 |
(Context.set_context (try Toplevel.theory_of state);
|
|
43 |
writeln "Leaving the Isar loop. Invoke 'main_loop();' to restart.";
|
|
44 |
raise Toplevel.TERMINATE));
|
|
45 |
|
|
46 |
val quit = Toplevel.imperative quit;
|
|
47 |
|
|
48 |
|
|
49 |
(* use ML text *)
|
|
50 |
|
|
51 |
fun use name = Toplevel.imperative (fn () => Use.use name);
|
|
52 |
|
|
53 |
(*passes changes of theory context*)
|
|
54 |
val use_mltext_theory = Toplevel.theory o IsarThy.use_mltext_theory;
|
|
55 |
|
|
56 |
(*ignore result theory context*)
|
|
57 |
fun use_mltext txt = Toplevel.keep (fn state =>
|
|
58 |
(IsarThy.use_mltext txt (try Toplevel.theory_of state); ()));
|
|
59 |
|
|
60 |
(*Note: commit is dynamically bound*)
|
|
61 |
val use_commit = use_mltext "commit();";
|
|
62 |
|
|
63 |
|
|
64 |
(* current working directory *)
|
|
65 |
|
|
66 |
fun print_cd _ = writeln (Library.pwd ());
|
|
67 |
|
|
68 |
fun cd dir = Toplevel.imperative (fn () => (Use.cd dir; print_cd ()));
|
|
69 |
val pwd = Toplevel.imperative print_cd;
|
|
70 |
|
|
71 |
|
|
72 |
(* load theory files *)
|
|
73 |
|
|
74 |
fun use_thy name = Toplevel.imperative (fn () => ThyRead.use_thy name);
|
|
75 |
|
|
76 |
fun load name =
|
|
77 |
Toplevel.imperative (fn () => Toplevel.excursion (OuterSyntax.read_file (name ^ ".thy")));
|
|
78 |
|
|
79 |
|
|
80 |
(* print theory contents *)
|
|
81 |
|
|
82 |
val print_theory = Toplevel.keep (PureThy.print_theory o Toplevel.theory_of);
|
|
83 |
val print_syntax = Toplevel.keep (Display.print_syntax o Toplevel.theory_of);
|
|
84 |
val print_attributes = Toplevel.keep (Attrib.print_attributes o Toplevel.theory_of);
|
|
85 |
val print_methods = Toplevel.keep (Method.print_methods o Toplevel.theory_of);
|
|
86 |
|
|
87 |
|
|
88 |
(* print proof context contents *)
|
|
89 |
|
|
90 |
val print_binds = Toplevel.keep (ProofContext.print_binds o Proof.context_of o Toplevel.proof_of);
|
|
91 |
val print_lthms = Toplevel.keep (ProofContext.print_thms o Proof.context_of o Toplevel.proof_of);
|
|
92 |
|
|
93 |
|
|
94 |
(* print theorems *)
|
|
95 |
|
|
96 |
fun print_thms name = Toplevel.keep (fn state =>
|
|
97 |
let
|
|
98 |
val prt_tthm = Attribute.pretty_tthm;
|
|
99 |
fun prt_tthms [th] = prt_tthm th
|
|
100 |
| prt_tthms ths = Pretty.block (Pretty.fbreaks (map prt_tthm ths));
|
|
101 |
|
|
102 |
val tthms = map (apfst (Thm.transfer (Toplevel.theory_of state)))
|
|
103 |
(Toplevel.node_cases PureThy.get_tthms (ProofContext.get_tthms o Proof.context_of)
|
|
104 |
state name);
|
|
105 |
in Pretty.writeln (prt_tthms tthms) end);
|
|
106 |
|
|
107 |
|
|
108 |
(* print types, terms and props *)
|
|
109 |
|
|
110 |
fun read_typ thy = Sign.read_typ (Theory.sign_of thy, K None);
|
|
111 |
|
|
112 |
fun read_term T thy s =
|
|
113 |
Thm.term_of (#1 (Thm.read_def_cterm (Theory.sign_of thy, K None, K None) [] true (s, T)));
|
|
114 |
|
|
115 |
|
|
116 |
fun print_type s = Toplevel.keep (fn state =>
|
|
117 |
let
|
|
118 |
val sign = Toplevel.sign_of state;
|
|
119 |
val T = Toplevel.node_cases read_typ (ProofContext.read_typ o Proof.context_of) state s;
|
|
120 |
in Pretty.writeln (Pretty.quote (Sign.pretty_typ sign T)) end);
|
|
121 |
|
|
122 |
fun print_term s = Toplevel.keep (fn state =>
|
|
123 |
let
|
|
124 |
val sign = Toplevel.sign_of state;
|
|
125 |
val t = Toplevel.node_cases (read_term (TVar (("'z", 0), logicS)))
|
|
126 |
(ProofContext.read_term o Proof.context_of) state s;
|
|
127 |
val T = Term.type_of t;
|
|
128 |
in
|
|
129 |
Pretty.writeln (Pretty.block [Pretty.quote (Sign.pretty_term sign t), Pretty.fbrk,
|
|
130 |
Pretty.str "::", Pretty.brk 1, Pretty.quote (Sign.pretty_typ sign T)])
|
|
131 |
end);
|
|
132 |
|
|
133 |
fun print_prop s = Toplevel.keep (fn state =>
|
|
134 |
let
|
|
135 |
val sign = Toplevel.sign_of state;
|
|
136 |
val prop =
|
|
137 |
Toplevel.node_cases (read_term propT) (ProofContext.read_prop o Proof.context_of) state s;
|
|
138 |
in Pretty.writeln (Pretty.quote (Sign.pretty_term sign prop)) end);
|
|
139 |
|
|
140 |
|
|
141 |
end;
|