author | wenzelm |
Tue, 17 Aug 1999 17:52:04 +0200 | |
changeset 7235 | 3c3defaad8ae |
parent 7210 | ae9a645e8728 |
child 7266 | 28d95a7a265a |
permissions | -rw-r--r-- |
6699 | 1 |
(* Title: Pure/Interface/proof_general.ML |
2 |
ID: $Id$ |
|
3 |
Author: Markus Wenzel, TU Muenchen |
|
4 |
||
5 |
Configuration for ProofGeneral of LFCS Edinburgh. |
|
6 |
*) |
|
7 |
||
8 |
signature PROOF_GENERAL = |
|
9 |
sig |
|
6947 | 10 |
val write_keywords: unit -> unit |
6699 | 11 |
val setup: (theory -> theory) list |
7193 | 12 |
val help: unit -> unit |
13 |
val show_context: unit -> theory |
|
14 |
val kill_goal: unit -> unit |
|
15 |
val repeat_undo: int -> unit |
|
7235 | 16 |
val isa_restart: unit -> unit |
6699 | 17 |
val init: bool -> unit |
18 |
end; |
|
19 |
||
20 |
structure ProofGeneral: PROOF_GENERAL = |
|
21 |
struct |
|
22 |
||
23 |
||
6720
353bd9b74b1f
write_keywords generates outer syntax keyword classification in elisp;
wenzelm
parents:
6699
diff
changeset
|
24 |
(** generate keyword classification file **) |
353bd9b74b1f
write_keywords generates outer syntax keyword classification in elisp;
wenzelm
parents:
6699
diff
changeset
|
25 |
|
353bd9b74b1f
write_keywords generates outer syntax keyword classification in elisp;
wenzelm
parents:
6699
diff
changeset
|
26 |
local |
353bd9b74b1f
write_keywords generates outer syntax keyword classification in elisp;
wenzelm
parents:
6699
diff
changeset
|
27 |
|
353bd9b74b1f
write_keywords generates outer syntax keyword classification in elisp;
wenzelm
parents:
6699
diff
changeset
|
28 |
val regexp_meta = explode ".*+?[]^$"; |
353bd9b74b1f
write_keywords generates outer syntax keyword classification in elisp;
wenzelm
parents:
6699
diff
changeset
|
29 |
val regexp_quote = implode o map (fn c => if c mem regexp_meta then "\\\\" ^ c else c) o explode; |
353bd9b74b1f
write_keywords generates outer syntax keyword classification in elisp;
wenzelm
parents:
6699
diff
changeset
|
30 |
|
353bd9b74b1f
write_keywords generates outer syntax keyword classification in elisp;
wenzelm
parents:
6699
diff
changeset
|
31 |
fun defconst name strs = |
353bd9b74b1f
write_keywords generates outer syntax keyword classification in elisp;
wenzelm
parents:
6699
diff
changeset
|
32 |
"\n(defconst isar-keywords-" ^ name ^ |
353bd9b74b1f
write_keywords generates outer syntax keyword classification in elisp;
wenzelm
parents:
6699
diff
changeset
|
33 |
"\n '(" ^ space_implode "\n " (map (quote o regexp_quote) strs) ^ "))\n"; |
353bd9b74b1f
write_keywords generates outer syntax keyword classification in elisp;
wenzelm
parents:
6699
diff
changeset
|
34 |
|
353bd9b74b1f
write_keywords generates outer syntax keyword classification in elisp;
wenzelm
parents:
6699
diff
changeset
|
35 |
fun make_elisp_commands commands kind = |
7027 | 36 |
defconst kind (mapfilter (fn (c, _, k, _) => if k = kind then Some c else None) commands); |
6720
353bd9b74b1f
write_keywords generates outer syntax keyword classification in elisp;
wenzelm
parents:
6699
diff
changeset
|
37 |
|
353bd9b74b1f
write_keywords generates outer syntax keyword classification in elisp;
wenzelm
parents:
6699
diff
changeset
|
38 |
fun make_elisp_syntax (keywords, commands) = |
353bd9b74b1f
write_keywords generates outer syntax keyword classification in elisp;
wenzelm
parents:
6699
diff
changeset
|
39 |
";;\n\ |
353bd9b74b1f
write_keywords generates outer syntax keyword classification in elisp;
wenzelm
parents:
6699
diff
changeset
|
40 |
\;; Keyword classification tables for Isabelle/Isar.\n\ |
353bd9b74b1f
write_keywords generates outer syntax keyword classification in elisp;
wenzelm
parents:
6699
diff
changeset
|
41 |
\;; This file generated by Isabelle -- DO NOT EDIT!\n\ |
353bd9b74b1f
write_keywords generates outer syntax keyword classification in elisp;
wenzelm
parents:
6699
diff
changeset
|
42 |
\;;\n\ |
6724 | 43 |
\;; $" ^ "Id$\n\ |
6720
353bd9b74b1f
write_keywords generates outer syntax keyword classification in elisp;
wenzelm
parents:
6699
diff
changeset
|
44 |
\;;\n" ^ |
7027 | 45 |
defconst "minor" (filter Syntax.is_identifier keywords) ^ |
6720
353bd9b74b1f
write_keywords generates outer syntax keyword classification in elisp;
wenzelm
parents:
6699
diff
changeset
|
46 |
implode (map (make_elisp_commands commands) OuterSyntax.Keyword.kinds) ^ |
353bd9b74b1f
write_keywords generates outer syntax keyword classification in elisp;
wenzelm
parents:
6699
diff
changeset
|
47 |
"\n(provide 'isar-keywords)\n"; |
353bd9b74b1f
write_keywords generates outer syntax keyword classification in elisp;
wenzelm
parents:
6699
diff
changeset
|
48 |
|
6947 | 49 |
val keywords_file = "isar-keywords.el"; |
50 |
||
6720
353bd9b74b1f
write_keywords generates outer syntax keyword classification in elisp;
wenzelm
parents:
6699
diff
changeset
|
51 |
in |
353bd9b74b1f
write_keywords generates outer syntax keyword classification in elisp;
wenzelm
parents:
6699
diff
changeset
|
52 |
|
6947 | 53 |
fun write_keywords () = |
7027 | 54 |
File.write (Path.unpack keywords_file) |
55 |
(make_elisp_syntax (OuterSyntax.dest_keywords (), OuterSyntax.dest_parsers ())); |
|
6720
353bd9b74b1f
write_keywords generates outer syntax keyword classification in elisp;
wenzelm
parents:
6699
diff
changeset
|
56 |
|
353bd9b74b1f
write_keywords generates outer syntax keyword classification in elisp;
wenzelm
parents:
6699
diff
changeset
|
57 |
end; |
353bd9b74b1f
write_keywords generates outer syntax keyword classification in elisp;
wenzelm
parents:
6699
diff
changeset
|
58 |
|
353bd9b74b1f
write_keywords generates outer syntax keyword classification in elisp;
wenzelm
parents:
6699
diff
changeset
|
59 |
|
353bd9b74b1f
write_keywords generates outer syntax keyword classification in elisp;
wenzelm
parents:
6699
diff
changeset
|
60 |
|
6699 | 61 |
(** compile-time theory setup **) |
62 |
||
63 |
(* token translations *) |
|
64 |
||
65 |
val proof_generalN = "ProofGeneral"; |
|
66 |
||
67 |
local |
|
68 |
||
69 |
val end_tag = oct_char "350"; |
|
70 |
val tclass_tag = oct_char "351"; |
|
71 |
val tfree_tag = oct_char "352"; |
|
72 |
val tvar_tag = oct_char "353"; |
|
73 |
val free_tag = oct_char "354"; |
|
74 |
val bound_tag = oct_char "355"; |
|
75 |
val var_tag = oct_char "356"; |
|
76 |
||
77 |
fun tagit p x = (p ^ x ^ end_tag, real (size x)); |
|
78 |
||
79 |
in |
|
80 |
||
81 |
val proof_general_trans = |
|
82 |
Syntax.tokentrans_mode proof_generalN |
|
83 |
[("class", tagit tclass_tag), |
|
84 |
("tfree", tagit tfree_tag), |
|
85 |
("tvar", tagit tvar_tag), |
|
86 |
("free", tagit free_tag), |
|
87 |
("bound", tagit bound_tag), |
|
88 |
("var", tagit var_tag)]; |
|
89 |
||
90 |
end; |
|
91 |
||
92 |
||
93 |
(* setup *) |
|
94 |
||
95 |
val setup = [Theory.add_tokentrfuns proof_general_trans]; |
|
96 |
||
97 |
||
98 |
||
7193 | 99 |
(** run-time operations **) |
6699 | 100 |
|
101 |
(* messages *) |
|
102 |
||
7193 | 103 |
val plain_output = std_output o suffix "\n"; |
7195 | 104 |
fun plain_writeln x = Library.setmp writeln_fn plain_output x; |
7193 | 105 |
|
106 |
fun decorate_lines bg en "" = plain_output o enclose bg en |
|
107 |
| decorate_lines bg en prfx = plain_output o enclose bg en o prefix_lines prfx; |
|
6699 | 108 |
|
109 |
fun setup_messages () = |
|
110 |
(writeln_fn := (decorate_lines (oct_char "360") (oct_char "361") ""); |
|
111 |
warning_fn := (decorate_lines (oct_char "362") (oct_char "363") "### "); |
|
112 |
error_fn := (decorate_lines (oct_char "364") (oct_char "365") "*** ")); |
|
113 |
||
114 |
||
115 |
(* theory / proof state *) |
|
116 |
||
7193 | 117 |
fun print_current_goals n max th = plain_writeln (Goals.print_current_goals_default n max) th; |
118 |
||
119 |
fun setup_state isar = |
|
6699 | 120 |
(current_goals_markers := |
121 |
let |
|
122 |
val begin_state = oct_char "366"; |
|
123 |
val end_state= oct_char "367"; |
|
124 |
val begin_goal = oct_char "370"; |
|
125 |
in (begin_state, end_state, begin_goal) end; |
|
7193 | 126 |
if isar then |
127 |
(Toplevel.print_state_fn := plain_writeln Toplevel.print_state_default; |
|
128 |
Toplevel.prompt_state_fn := (suffix (oct_char "372") o Toplevel.prompt_state_default)) |
|
129 |
else Goals.print_current_goals_fn := print_current_goals); |
|
6699 | 130 |
|
131 |
||
7100 | 132 |
(* theory loader actions *) |
133 |
||
134 |
local |
|
135 |
||
136 |
fun tell_pg msg name = writeln ("Proof General, " ^ msg ^ " " ^ quote name); |
|
137 |
||
7193 | 138 |
fun isa_action action name = |
139 |
let val files = map (File.sysify_path o #1) (ThyInfo.loaded_files name) in |
|
140 |
if action = ThyInfo.Update then seq (tell_pg "this file is loaded:") files |
|
141 |
else seq (tell_pg "you can unlock the file") files |
|
142 |
end; |
|
143 |
||
144 |
fun isar_action action name = |
|
145 |
if action = ThyInfo.Update then tell_pg "this theory is loaded:" name |
|
146 |
else tell_pg "you can unlock the theory" name; |
|
7100 | 147 |
|
148 |
in |
|
7193 | 149 |
fun setup_thy_loader isar = ThyInfo.add_hook (if isar then isar_action else isa_action); |
7100 | 150 |
end; |
151 |
||
152 |
||
7193 | 153 |
(* some top-level commands for ProofGeneral/isa *) |
154 |
||
155 |
val help = writeln o Session.welcome; |
|
156 |
val show_context = Context.the_context; |
|
157 |
||
158 |
fun kill_goal () = |
|
7235 | 159 |
(Goals.reset_goals (); writeln ("Proof General, please clear the goals buffer.")); |
7193 | 160 |
|
161 |
fun repeat_undo 0 = () |
|
162 |
| repeat_undo n = (undo(); repeat_undo (n - 1)); |
|
163 |
||
164 |
fun isa_restart () = |
|
7210 | 165 |
(ml_prompts ("> " ^ oct_char "372") ("- " ^ oct_char "373"); |
7193 | 166 |
ThyInfo.touch_all_thys (); |
167 |
kill_goal (); |
|
168 |
writeln ("Proof General, please clear the response buffer."); |
|
169 |
writeln "Isabelle Proof General: Isabelle process ready!"); |
|
170 |
||
171 |
||
6699 | 172 |
(* init *) |
173 |
||
174 |
fun init isar = |
|
175 |
(setup_messages (); |
|
7193 | 176 |
setup_state isar; |
177 |
setup_thy_loader isar; |
|
6699 | 178 |
print_mode := [proof_generalN]; |
179 |
set quick_and_dirty; |
|
7193 | 180 |
if isar then Isar.sync_main () else isa_restart ()); |
6699 | 181 |
|
182 |
||
183 |
end; |