author | wenzelm |
Fri, 15 Aug 2008 15:50:52 +0200 | |
changeset 27885 | 76b51cd0a37c |
parent 27865 | 27a8ad9612a3 |
child 28020 | 1ff5167592ba |
permissions | -rw-r--r-- |
21637 | 1 |
(* Title: Pure/ProofGeneral/proof_general_pgip.ML |
2 |
ID: $Id$ |
|
3 |
Author: David Aspinall and Markus Wenzel |
|
4 |
||
5 |
Isabelle configuration for Proof General using PGIP protocol. |
|
21940 | 6 |
See http://proofgeneral.inf.ed.ac.uk/kit |
21637 | 7 |
*) |
8 |
||
9 |
signature PROOF_GENERAL_PGIP = |
|
10 |
sig |
|
21940 | 11 |
val init_pgip: bool -> unit (* main PGIP loop with true; fail with false *) |
21642 | 12 |
|
21649
40e6fdd26f82
Support PGIP communication for preferences in Emacs mode.
aspinall
parents:
21646
diff
changeset
|
13 |
(* These two are just to support the semi-PGIP Emacs mode *) |
21940 | 14 |
val init_pgip_channel: (string -> unit) -> unit |
15 |
val process_pgip: string -> unit |
|
22042
64f8f5433f30
Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents:
22028
diff
changeset
|
16 |
|
23435
061f28854017
Remove dedicated flag setting elements in favour of setproverflag. Restore displayconfig response in askpgip.
aspinall
parents:
23226
diff
changeset
|
17 |
(* More message functions... *) |
061f28854017
Remove dedicated flag setting elements in favour of setproverflag. Restore displayconfig response in askpgip.
aspinall
parents:
23226
diff
changeset
|
18 |
val nonfatal_error : string -> unit (* recoverable (batch) error: carry on scripting *) |
22228
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
19 |
val log_msg : string -> unit (* for internal log messages *) |
23759
90bccef65004
Fix nested PGIP messages. Update for schema simplifications.
aspinall
parents:
23723
diff
changeset
|
20 |
val error_with_pos : PgipTypes.displayarea -> PgipTypes.fatality -> Position.T -> string -> unit |
22159 | 21 |
|
22163 | 22 |
val get_currently_open_file : unit -> Path.T option (* interface focus *) |
21637 | 23 |
end |
24 |
||
25 |
structure ProofGeneralPgip : PROOF_GENERAL_PGIP = |
|
26 |
struct |
|
27 |
||
28 |
open Pgip; |
|
29 |
||
21949 | 30 |
|
23641
d6f9d3acffaa
toplevel prompt/print_state: proper markup, removed hooks;
wenzelm
parents:
23621
diff
changeset
|
31 |
(** print mode **) |
21637 | 32 |
|
22408 | 33 |
val proof_generalN = "ProofGeneral"; |
34 |
val pgmlsymbols_flag = ref true; |
|
21637 | 35 |
|
23641
d6f9d3acffaa
toplevel prompt/print_state: proper markup, removed hooks;
wenzelm
parents:
23621
diff
changeset
|
36 |
|
d6f9d3acffaa
toplevel prompt/print_state: proper markup, removed hooks;
wenzelm
parents:
23621
diff
changeset
|
37 |
(* symbol output *) |
d6f9d3acffaa
toplevel prompt/print_state: proper markup, removed hooks;
wenzelm
parents:
23621
diff
changeset
|
38 |
|
21637 | 39 |
local |
40 |
||
41 |
fun xsym_output "\\" = "\\\\" |
|
42 |
| xsym_output s = if Symbol.is_raw s then Symbol.decode_raw s else s; |
|
43 |
||
44 |
fun pgml_sym s = |
|
45 |
(case Symbol.decode s of |
|
46 |
Symbol.Char s => XML.text s |
|
26706 | 47 |
| Symbol.Sym sn => |
22408 | 48 |
let val ascii = implode (map xsym_output (Symbol.explode s)) |
49 |
in if !pgmlsymbols_flag then XML.element "sym" [("name", sn)] [XML.text ascii] |
|
50 |
else ascii end |
|
51 |
| Symbol.Ctrl sn => XML.element "ctrl" [("name", sn)] [XML.text sn] (* FIXME: no such PGML *) |
|
52 |
| Symbol.Raw raw => raw); |
|
21637 | 53 |
|
54 |
fun pgml_output str = |
|
55 |
let val syms = Symbol.explode str |
|
23621 | 56 |
in (implode (map pgml_sym syms), Symbol.length syms) end; |
57 |
||
21637 | 58 |
in |
59 |
||
22408 | 60 |
fun setup_proofgeneral_output () = |
23641
d6f9d3acffaa
toplevel prompt/print_state: proper markup, removed hooks;
wenzelm
parents:
23621
diff
changeset
|
61 |
Output.add_mode proof_generalN pgml_output Symbol.encode_raw; |
21637 | 62 |
|
63 |
end; |
|
64 |
||
65 |
||
23641
d6f9d3acffaa
toplevel prompt/print_state: proper markup, removed hooks;
wenzelm
parents:
23621
diff
changeset
|
66 |
(* assembling and issuing PGIP packets *) |
21637 | 67 |
|
68 |
val pgip_refid = ref NONE: string option ref; |
|
69 |
val pgip_refseq = ref NONE: int option ref; |
|
70 |
||
71 |
local |
|
72 |
val pgip_class = "pg" |
|
73 |
val pgip_tag = "Isabelle/Isar" |
|
74 |
val pgip_id = ref "" |
|
75 |
val pgip_seq = ref 0 |
|
76 |
fun pgip_serial () = inc pgip_seq |
|
77 |
||
78 |
fun assemble_pgips pgips = |
|
21940 | 79 |
Pgip { tag = SOME pgip_tag, |
80 |
class = pgip_class, |
|
81 |
seq = pgip_serial(), |
|
82 |
id = !pgip_id, |
|
83 |
destid = !pgip_refid, |
|
84 |
(* destid=refid since Isabelle only communicates back to sender *) |
|
85 |
refid = !pgip_refid, |
|
86 |
refseq = !pgip_refseq, |
|
87 |
content = pgips } |
|
21637 | 88 |
in |
89 |
||
90 |
fun init_pgip_session_id () = |
|
91 |
pgip_id := getenv "HOSTNAME" ^ "/" ^ getenv "USER" ^ "/" ^ |
|
92 |
getenv "ISABELLE_PID" ^ "/" ^ Time.toString (Time.now ()) |
|
93 |
||
94 |
fun matching_pgip_id id = (id = !pgip_id) |
|
95 |
||
22590 | 96 |
val output_xml_fn = ref Output.writeln_default |
26541 | 97 |
fun output_xml s = (!output_xml_fn) (XML.string_of s); (* TODO: string buffer *) |
21637 | 98 |
|
23641
d6f9d3acffaa
toplevel prompt/print_state: proper markup, removed hooks;
wenzelm
parents:
23621
diff
changeset
|
99 |
val output_pgips = |
26541 | 100 |
XML.string_of o PgipOutput.output o assemble_pgips o map PgipOutput.output; |
23641
d6f9d3acffaa
toplevel prompt/print_state: proper markup, removed hooks;
wenzelm
parents:
23621
diff
changeset
|
101 |
|
26706 | 102 |
val output_pgmlterm = |
26541 | 103 |
XML.string_of o Pgml.pgmlterm_to_xml; |
23759
90bccef65004
Fix nested PGIP messages. Update for schema simplifications.
aspinall
parents:
23723
diff
changeset
|
104 |
|
26706 | 105 |
val output_pgmltext = |
26541 | 106 |
XML.string_of o Pgml.pgml_to_xml; |
23759
90bccef65004
Fix nested PGIP messages. Update for schema simplifications.
aspinall
parents:
23723
diff
changeset
|
107 |
|
90bccef65004
Fix nested PGIP messages. Update for schema simplifications.
aspinall
parents:
23723
diff
changeset
|
108 |
|
21940 | 109 |
fun issue_pgip_rawtext str = |
23723 | 110 |
output_xml (PgipOutput.output (assemble_pgips [XML.Output str])) |
21637 | 111 |
|
112 |
fun issue_pgips pgipops = |
|
113 |
output_xml (PgipOutput.output (assemble_pgips (map PgipOutput.output pgipops))); |
|
114 |
||
115 |
fun issue_pgip pgipop = |
|
116 |
output_xml (PgipOutput.output (assemble_pgips [PgipOutput.output pgipop])); |
|
117 |
||
118 |
end; |
|
119 |
||
120 |
||
23759
90bccef65004
Fix nested PGIP messages. Update for schema simplifications.
aspinall
parents:
23723
diff
changeset
|
121 |
fun pgml area terms = Pgml.Pgml { version=NONE,systemid=NONE, |
23801 | 122 |
area=SOME area, content=terms } |
23641
d6f9d3acffaa
toplevel prompt/print_state: proper markup, removed hooks;
wenzelm
parents:
23621
diff
changeset
|
123 |
|
21637 | 124 |
(** messages and notification **) |
125 |
||
126 |
local |
|
127 |
val delay_msgs = ref false (*true: accumulate messages*) |
|
128 |
val delayed_msgs = ref [] |
|
129 |
||
130 |
fun queue_or_issue pgip = |
|
21940 | 131 |
if ! delay_msgs then |
132 |
delayed_msgs := pgip :: ! delayed_msgs |
|
133 |
else issue_pgip pgip |
|
23759
90bccef65004
Fix nested PGIP messages. Update for schema simplifications.
aspinall
parents:
23723
diff
changeset
|
134 |
|
26706 | 135 |
fun wrap_pgml area s = |
136 |
if String.isPrefix "<pgml" s then |
|
23801 | 137 |
XML.Output s (* already pgml outermost *) |
26706 | 138 |
else |
23801 | 139 |
Pgml.pgml_to_xml (pgml area [Pgml.Raw (XML.Output s)]) (* mixed *) |
23759
90bccef65004
Fix nested PGIP messages. Update for schema simplifications.
aspinall
parents:
23723
diff
changeset
|
140 |
|
21637 | 141 |
in |
23759
90bccef65004
Fix nested PGIP messages. Update for schema simplifications.
aspinall
parents:
23723
diff
changeset
|
142 |
fun normalmsg area s = |
21940 | 143 |
let |
23759
90bccef65004
Fix nested PGIP messages. Update for schema simplifications.
aspinall
parents:
23723
diff
changeset
|
144 |
val content = wrap_pgml area s |
90bccef65004
Fix nested PGIP messages. Update for schema simplifications.
aspinall
parents:
23723
diff
changeset
|
145 |
val pgip = Normalresponse { content=[content] } |
21940 | 146 |
in |
147 |
queue_or_issue pgip |
|
148 |
end |
|
21637 | 149 |
|
23759
90bccef65004
Fix nested PGIP messages. Update for schema simplifications.
aspinall
parents:
23723
diff
changeset
|
150 |
fun errormsg area fatality s = |
21940 | 151 |
let |
23759
90bccef65004
Fix nested PGIP messages. Update for schema simplifications.
aspinall
parents:
23723
diff
changeset
|
152 |
val content = wrap_pgml area s |
90bccef65004
Fix nested PGIP messages. Update for schema simplifications.
aspinall
parents:
23723
diff
changeset
|
153 |
val pgip = Errorresponse { fatality=fatality, |
90bccef65004
Fix nested PGIP messages. Update for schema simplifications.
aspinall
parents:
23723
diff
changeset
|
154 |
location=NONE, |
90bccef65004
Fix nested PGIP messages. Update for schema simplifications.
aspinall
parents:
23723
diff
changeset
|
155 |
content=[content] } |
21940 | 156 |
in |
157 |
queue_or_issue pgip |
|
158 |
end |
|
21637 | 159 |
|
22159 | 160 |
(* Error responses with useful locations *) |
23759
90bccef65004
Fix nested PGIP messages. Update for schema simplifications.
aspinall
parents:
23723
diff
changeset
|
161 |
fun error_with_pos area fatality pos s = |
22159 | 162 |
let |
23759
90bccef65004
Fix nested PGIP messages. Update for schema simplifications.
aspinall
parents:
23723
diff
changeset
|
163 |
val content = wrap_pgml area s |
90bccef65004
Fix nested PGIP messages. Update for schema simplifications.
aspinall
parents:
23723
diff
changeset
|
164 |
val pgip = Errorresponse { fatality=fatality, |
90bccef65004
Fix nested PGIP messages. Update for schema simplifications.
aspinall
parents:
23723
diff
changeset
|
165 |
location=SOME (PgipIsabelle.location_of_position pos), |
90bccef65004
Fix nested PGIP messages. Update for schema simplifications.
aspinall
parents:
23723
diff
changeset
|
166 |
content=[content] } |
22159 | 167 |
in |
168 |
queue_or_issue pgip |
|
169 |
end |
|
170 |
||
21637 | 171 |
fun start_delay_msgs () = (set delay_msgs; delayed_msgs := []) |
172 |
fun end_delayed_msgs () = (reset delay_msgs; ! delayed_msgs) |
|
173 |
end; |
|
174 |
||
175 |
(* NB: all of the standard error/message functions now expect already-escaped text. |
|
176 |
FIXME: this may cause us problems now we're generating trees; on the other |
|
21940 | 177 |
hand the output functions were tuned some time ago, so it ought to be |
23759
90bccef65004
Fix nested PGIP messages. Update for schema simplifications.
aspinall
parents:
23723
diff
changeset
|
178 |
enough to use XML.Output always above. *) |
22042
64f8f5433f30
Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents:
22028
diff
changeset
|
179 |
(* NB 2: all of standard functions print strings terminated with new lines, but we don't |
22228
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
180 |
add new lines explicitly in PGIP: they are left implicit. It means that PGIP messages |
22042
64f8f5433f30
Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents:
22028
diff
changeset
|
181 |
can't be written without newlines. *) |
21637 | 182 |
|
183 |
fun setup_messages () = |
|
23759
90bccef65004
Fix nested PGIP messages. Update for schema simplifications.
aspinall
parents:
23723
diff
changeset
|
184 |
(Output.writeln_fn := (fn s => normalmsg Message s); |
27604 | 185 |
Output.status_fn := (fn _ => ()); |
23840 | 186 |
Output.priority_fn := (fn s => normalmsg Status s); |
187 |
Output.tracing_fn := (fn s => normalmsg Tracing s); |
|
23759
90bccef65004
Fix nested PGIP messages. Update for schema simplifications.
aspinall
parents:
23723
diff
changeset
|
188 |
Output.warning_fn := (fn s => errormsg Message Warning s); |
90bccef65004
Fix nested PGIP messages. Update for schema simplifications.
aspinall
parents:
23723
diff
changeset
|
189 |
Output.error_fn := (fn s => errormsg Message Fatal s); |
90bccef65004
Fix nested PGIP messages. Update for schema simplifications.
aspinall
parents:
23723
diff
changeset
|
190 |
Output.debug_fn := (fn s => errormsg Message Debug s)); |
22042
64f8f5433f30
Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents:
22028
diff
changeset
|
191 |
|
23759
90bccef65004
Fix nested PGIP messages. Update for schema simplifications.
aspinall
parents:
23723
diff
changeset
|
192 |
fun panic s = (errormsg Message Panic ("## SYSTEM EXIT ##\n" ^ s); exit 1); |
90bccef65004
Fix nested PGIP messages. Update for schema simplifications.
aspinall
parents:
23723
diff
changeset
|
193 |
fun nonfatal_error s = errormsg Message Nonfatal s; |
90bccef65004
Fix nested PGIP messages. Update for schema simplifications.
aspinall
parents:
23723
diff
changeset
|
194 |
fun log_msg s = errormsg Message Log s; |
21983
9fb029d1189b
Use Isar toplevel print_exn_fn for generating error responses instead of Output.error_msg.
aspinall
parents:
21972
diff
changeset
|
195 |
|
21637 | 196 |
|
197 |
(* immediate messages *) |
|
198 |
||
26706 | 199 |
fun tell_clear_goals () = |
23759
90bccef65004
Fix nested PGIP messages. Update for schema simplifications.
aspinall
parents:
23723
diff
changeset
|
200 |
issue_pgip (Normalresponse { content = [Pgml.pgml_to_xml (pgml Display [])] }) |
26706 | 201 |
fun tell_clear_response () = |
23759
90bccef65004
Fix nested PGIP messages. Update for schema simplifications.
aspinall
parents:
23723
diff
changeset
|
202 |
issue_pgip (Normalresponse { content = [Pgml.pgml_to_xml (pgml Message [])] }) |
22042
64f8f5433f30
Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents:
22028
diff
changeset
|
203 |
|
22228
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
204 |
fun tell_file_loaded completed path = |
22042
64f8f5433f30
Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents:
22028
diff
changeset
|
205 |
issue_pgip (Informfileloaded {url=PgipTypes.pgipurl_of_path path, |
22228
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
206 |
completed=completed}) |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
207 |
fun tell_file_outdated completed path = |
22042
64f8f5433f30
Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents:
22028
diff
changeset
|
208 |
issue_pgip (Informfileoutdated {url=PgipTypes.pgipurl_of_path path, |
22228
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
209 |
completed=completed}) |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
210 |
fun tell_file_retracted completed path = |
22042
64f8f5433f30
Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents:
22028
diff
changeset
|
211 |
issue_pgip (Informfileretracted {url=PgipTypes.pgipurl_of_path path, |
22228
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
212 |
completed=completed}) |
21637 | 213 |
|
214 |
||
23641
d6f9d3acffaa
toplevel prompt/print_state: proper markup, removed hooks;
wenzelm
parents:
23621
diff
changeset
|
215 |
(* common markup *) |
21637 | 216 |
|
217 |
local |
|
218 |
||
23641
d6f9d3acffaa
toplevel prompt/print_state: proper markup, removed hooks;
wenzelm
parents:
23621
diff
changeset
|
219 |
val no_text = chr 0; |
d6f9d3acffaa
toplevel prompt/print_state: proper markup, removed hooks;
wenzelm
parents:
23621
diff
changeset
|
220 |
|
23759
90bccef65004
Fix nested PGIP messages. Update for schema simplifications.
aspinall
parents:
23723
diff
changeset
|
221 |
val pgmlterms_no_text= [Pgml.Raw (XML.Output no_text)] |
90bccef65004
Fix nested PGIP messages. Update for schema simplifications.
aspinall
parents:
23723
diff
changeset
|
222 |
|
23641
d6f9d3acffaa
toplevel prompt/print_state: proper markup, removed hooks;
wenzelm
parents:
23621
diff
changeset
|
223 |
fun split_markup text = |
d6f9d3acffaa
toplevel prompt/print_state: proper markup, removed hooks;
wenzelm
parents:
23621
diff
changeset
|
224 |
(case space_explode no_text text of |
d6f9d3acffaa
toplevel prompt/print_state: proper markup, removed hooks;
wenzelm
parents:
23621
diff
changeset
|
225 |
[bg, en] => (bg, en) |
23759
90bccef65004
Fix nested PGIP messages. Update for schema simplifications.
aspinall
parents:
23723
diff
changeset
|
226 |
| _ => (error ("Internal error: failed to split XML markup:\n" ^ text); ("", ""))); |
90bccef65004
Fix nested PGIP messages. Update for schema simplifications.
aspinall
parents:
23723
diff
changeset
|
227 |
|
90bccef65004
Fix nested PGIP messages. Update for schema simplifications.
aspinall
parents:
23723
diff
changeset
|
228 |
|
23801 | 229 |
fun block_markup markup = |
26706 | 230 |
let |
231 |
val pgml = Pgml.Box { orient = NONE, |
|
23801 | 232 |
indent = Markup.get_int markup Markup.indentN, |
233 |
content = pgmlterms_no_text } |
|
23759
90bccef65004
Fix nested PGIP messages. Update for schema simplifications.
aspinall
parents:
23723
diff
changeset
|
234 |
in split_markup (output_pgmlterm pgml) end; |
90bccef65004
Fix nested PGIP messages. Update for schema simplifications.
aspinall
parents:
23723
diff
changeset
|
235 |
|
23801 | 236 |
fun break_markup markup = |
26706 | 237 |
let |
23801 | 238 |
val pgml = Pgml.Break { mandatory = NONE, |
239 |
indent = Markup.get_int markup Markup.widthN } |
|
23759
90bccef65004
Fix nested PGIP messages. Update for schema simplifications.
aspinall
parents:
23723
diff
changeset
|
240 |
in (output_pgmlterm pgml, "") end; |
90bccef65004
Fix nested PGIP messages. Update for schema simplifications.
aspinall
parents:
23723
diff
changeset
|
241 |
|
23801 | 242 |
fun fbreak_markup markup = |
26706 | 243 |
let |
23801 | 244 |
val pgml = Pgml.Break { mandatory = SOME true, indent = NONE } |
23759
90bccef65004
Fix nested PGIP messages. Update for schema simplifications.
aspinall
parents:
23723
diff
changeset
|
245 |
in (output_pgmlterm pgml, "") end; |
90bccef65004
Fix nested PGIP messages. Update for schema simplifications.
aspinall
parents:
23723
diff
changeset
|
246 |
|
90bccef65004
Fix nested PGIP messages. Update for schema simplifications.
aspinall
parents:
23723
diff
changeset
|
247 |
val state_markup = |
90bccef65004
Fix nested PGIP messages. Update for schema simplifications.
aspinall
parents:
23723
diff
changeset
|
248 |
split_markup (output_pgmltext (pgml PgipTypes.Display pgmlterms_no_text)) |
21637 | 249 |
|
26706 | 250 |
val token_markups = |
27828
edafacb690a3
renamed Markup.class to Markup.tclass, to avoid potential conflicts with spacial meaning in markup languages (e.g. HTML);
wenzelm
parents:
27604
diff
changeset
|
251 |
[Markup.tclassN, Markup.tfreeN, Markup.tvarN, Markup.freeN, |
26706 | 252 |
Markup.boundN, Markup.varN, Markup.skolemN]; |
21637 | 253 |
|
254 |
in |
|
255 |
||
26706 | 256 |
val _ = Markup.add_mode proof_generalN (fn (markup as (name, _)) => |
257 |
if name = Markup.blockN then block_markup markup |
|
258 |
else if name = Markup.breakN then break_markup markup |
|
259 |
else if name = Markup.fbreakN then fbreak_markup markup |
|
260 |
else if name = Markup.stateN then state_markup |
|
261 |
else if member (op =) token_markups name then XML.output_markup ("atom", [("kind", name)]) |
|
262 |
else ("", "")); |
|
21637 | 263 |
|
264 |
end; |
|
265 |
||
266 |
||
267 |
(* theory loader actions *) |
|
268 |
||
269 |
local |
|
22228
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
270 |
(* da: TODO: PGIP has a completed flag so the prover can indicate to the |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
271 |
interface which files are busy performing a particular action. |
22042
64f8f5433f30
Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents:
22028
diff
changeset
|
272 |
To make use of this we need to adjust the hook in thy_info.ML |
22228
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
273 |
(may actually be difficult to tell the interface *which* action is in |
22042
64f8f5433f30
Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents:
22028
diff
changeset
|
274 |
progress, but we could add a generic "Lock" action which uses |
64f8f5433f30
Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents:
22028
diff
changeset
|
275 |
informfileloaded: the broker/UI should not infer too much from incomplete |
64f8f5433f30
Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents:
22028
diff
changeset
|
276 |
operations). |
22228
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
277 |
*) |
21637 | 278 |
fun trace_action action name = |
279 |
if action = ThyInfo.Update then |
|
22228
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
280 |
List.app (tell_file_loaded true) (ThyInfo.loaded_files name) |
22042
64f8f5433f30
Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents:
22028
diff
changeset
|
281 |
else if action = ThyInfo.Outdate then |
64f8f5433f30
Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents:
22028
diff
changeset
|
282 |
List.app (tell_file_outdated true) (ThyInfo.loaded_files name) |
64f8f5433f30
Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents:
22028
diff
changeset
|
283 |
else if action = ThyInfo.Remove then |
22228
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
284 |
List.app (tell_file_retracted true) (ThyInfo.loaded_files name) |
22042
64f8f5433f30
Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents:
22028
diff
changeset
|
285 |
else () |
64f8f5433f30
Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents:
22028
diff
changeset
|
286 |
|
21637 | 287 |
|
288 |
in |
|
289 |
fun setup_thy_loader () = ThyInfo.add_hook trace_action; |
|
26613 | 290 |
fun sync_thy_loader () = List.app (trace_action ThyInfo.Update) (ThyInfo.get_names ()); |
21637 | 291 |
end; |
292 |
||
293 |
||
21949 | 294 |
(* get informed about files *) |
21637 | 295 |
|
22042
64f8f5433f30
Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents:
22028
diff
changeset
|
296 |
val thy_name = Path.implode o #1 o Path.split_ext o Path.base; |
21637 | 297 |
|
298 |
val inform_file_retracted = ThyInfo.if_known_thy ThyInfo.remove_thy o thy_name; |
|
299 |
val inform_file_processed = ThyInfo.if_known_thy ThyInfo.touch_child_thys o thy_name; |
|
300 |
||
22042
64f8f5433f30
Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents:
22028
diff
changeset
|
301 |
fun proper_inform_file_processed path state = |
64f8f5433f30
Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents:
22028
diff
changeset
|
302 |
let val name = thy_name path in |
21637 | 303 |
if Toplevel.is_toplevel state andalso ThyInfo.known_thy name then |
304 |
(ThyInfo.touch_child_thys name; |
|
24079 | 305 |
ThyInfo.register_thy name handle ERROR msg => |
23913 | 306 |
(warning (cat_lines [msg, "Failed to register theory: " ^ quote name]); |
22042
64f8f5433f30
Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents:
22028
diff
changeset
|
307 |
tell_file_retracted true (Path.base path))) |
21637 | 308 |
else raise Toplevel.UNDEF |
309 |
end; |
|
310 |
||
311 |
||
312 |
(* restart top-level loop (keeps most state information) *) |
|
313 |
||
314 |
val welcome = priority o Session.welcome; |
|
315 |
||
316 |
fun restart () = |
|
317 |
(sync_thy_loader (); |
|
318 |
tell_clear_goals (); |
|
319 |
tell_clear_response (); |
|
27578 | 320 |
Isar.init_point (); |
321 |
welcome ()); |
|
21637 | 322 |
|
323 |
||
324 |
(* theorem dependency output *) |
|
22408 | 325 |
|
326 |
val show_theorem_dependencies = ref false; |
|
327 |
||
21637 | 328 |
local |
329 |
||
330 |
val spaces_quote = space_implode " " o map quote; |
|
331 |
||
332 |
fun thm_deps_message (thms, deps) = |
|
21940 | 333 |
let |
334 |
val valuethms = XML.Elem("value",[("name", "thms")],[XML.Text thms]) |
|
335 |
val valuedeps = XML.Elem("value",[("name", "deps")],[XML.Text deps]) |
|
21637 | 336 |
in |
21940 | 337 |
issue_pgip (Metainforesponse {attrs=[("infotype", "isabelle_theorem_dependencies")], |
338 |
content=[valuethms,valuedeps]}) |
|
21637 | 339 |
end |
340 |
||
21969 | 341 |
fun tell_thm_deps ths = |
22408 | 342 |
if !show_theorem_dependencies then |
22228
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
343 |
let |
27865
27a8ad9612a3
moved basic thm operations from structure PureThy to Thm (cf. more_thm.ML);
wenzelm
parents:
27860
diff
changeset
|
344 |
val names = map Thm.get_name_hint (filter Thm.has_name_hint ths); |
22228
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
345 |
val deps = (Symtab.keys (fold Proofterm.thms_of_proof' |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
346 |
(map Thm.proof_of ths) Symtab.empty)) |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
347 |
in |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
348 |
if null names orelse null deps then () |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
349 |
else thm_deps_message (spaces_quote names, spaces_quote deps) |
22225 | 350 |
end |
351 |
else () |
|
21637 | 352 |
|
353 |
in |
|
354 |
||
355 |
fun setup_present_hook () = |
|
27860 | 356 |
ProofDisplay.add_hook (fn res => tell_thm_deps (maps #2 res)); |
21637 | 357 |
|
358 |
end; |
|
359 |
||
360 |
(** lexicalstructure element with keywords (PGIP version of elisp keywords file) **) |
|
361 |
||
21940 | 362 |
fun lexicalstructure_keywords () = |
27353
71c4dd53d4cb
moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents:
27177
diff
changeset
|
363 |
let val keywords = OuterKeyword.dest_keywords () |
71c4dd53d4cb
moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents:
27177
diff
changeset
|
364 |
val commands = OuterKeyword.dest_commands () |
71c4dd53d4cb
moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents:
27177
diff
changeset
|
365 |
fun keyword_elt kind keyword = |
71c4dd53d4cb
moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents:
27177
diff
changeset
|
366 |
XML.Elem("keyword", [("word", keyword), ("category", kind)], []) |
21940 | 367 |
in |
21637 | 368 |
(* Also, note we don't call init_outer_syntax here to add interface commands, |
369 |
but they should never appear in scripts anyway so it shouldn't matter *) |
|
27353
71c4dd53d4cb
moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents:
27177
diff
changeset
|
370 |
Lexicalstructure |
71c4dd53d4cb
moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents:
27177
diff
changeset
|
371 |
{content = map (keyword_elt "minor") keywords @ map (keyword_elt "major") commands} |
21637 | 372 |
end |
373 |
||
374 |
(* TODO: we can issue a lexicalstructure/keyword when the syntax gets extended dynamically; |
|
375 |
hooks needed in outer_syntax.ML to do that. *) |
|
376 |
||
377 |
||
378 |
(* Configuration: GUI config, proverinfo messages *) |
|
379 |
||
380 |
local |
|
381 |
val isabellewww = "http://isabelle.in.tum.de/" |
|
382 |
val staticconfig = "~~/lib/ProofGeneral/pgip_isar.xml" |
|
21940 | 383 |
fun orenv v d = case getenv v of "" => d | s => s |
21637 | 384 |
fun config_file() = orenv "ISABELLE_PGIPCONFIG" staticconfig |
385 |
fun isabelle_www() = orenv "ISABELLE_HOMEPAGE" isabellewww |
|
386 |
in |
|
387 |
fun send_pgip_config () = |
|
388 |
let |
|
21858
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
wenzelm
parents:
21655
diff
changeset
|
389 |
val path = Path.explode (config_file()) |
21940 | 390 |
val ex = File.exists path |
21637 | 391 |
|
21940 | 392 |
val wwwpage = |
393 |
(Url.explode (isabelle_www())) |
|
21969 | 394 |
handle ERROR _ => |
22699
938c1011ac94
removed unused Output.panic hook -- internal to PG wrapper;
wenzelm
parents:
22678
diff
changeset
|
395 |
(panic ("Error in URL in environment variable ISABELLE_HOMEPAGE."); |
21940 | 396 |
Url.explode isabellewww) |
397 |
||
398 |
val proverinfo = |
|
21637 | 399 |
Proverinfo { name = "Isabelle", |
26109
c69c3559355b
more elaborate structure Distribution (filled-in by makedist);
wenzelm
parents:
25847
diff
changeset
|
400 |
version = Distribution.version, |
21940 | 401 |
instance = Session.name(), |
402 |
descr = "The Isabelle/Isar theorem prover", |
|
403 |
url = wwwpage, |
|
404 |
filenameextns = ".thy;" } |
|
21637 | 405 |
in |
21940 | 406 |
if ex then |
407 |
(issue_pgip proverinfo; |
|
408 |
issue_pgip_rawtext (File.read path); |
|
409 |
issue_pgip (lexicalstructure_keywords())) |
|
22699
938c1011ac94
removed unused Output.panic hook -- internal to PG wrapper;
wenzelm
parents:
22678
diff
changeset
|
410 |
else panic ("PGIP configuration file \"" ^ config_file() ^ "\" not found") |
21637 | 411 |
end; |
412 |
end |
|
413 |
||
414 |
||
22216
c3f5aa951a68
Tweak preferences for PGIP interfaces. Make <askids> return theory successors instead of parents (ideally should be content elements).
aspinall
parents:
22171
diff
changeset
|
415 |
(* Preferences: tweak for PGIP interfaces *) |
c3f5aa951a68
Tweak preferences for PGIP interfaces. Make <askids> return theory successors instead of parents (ideally should be content elements).
aspinall
parents:
22171
diff
changeset
|
416 |
|
c3f5aa951a68
Tweak preferences for PGIP interfaces. Make <askids> return theory successors instead of parents (ideally should be content elements).
aspinall
parents:
22171
diff
changeset
|
417 |
val preferences = ref Preferences.preferences; |
c3f5aa951a68
Tweak preferences for PGIP interfaces. Make <askids> return theory successors instead of parents (ideally should be content elements).
aspinall
parents:
22171
diff
changeset
|
418 |
|
c3f5aa951a68
Tweak preferences for PGIP interfaces. Make <askids> return theory successors instead of parents (ideally should be content elements).
aspinall
parents:
22171
diff
changeset
|
419 |
fun setup_preferences_tweak() = |
c3f5aa951a68
Tweak preferences for PGIP interfaces. Make <askids> return theory successors instead of parents (ideally should be content elements).
aspinall
parents:
22171
diff
changeset
|
420 |
preferences := |
c3f5aa951a68
Tweak preferences for PGIP interfaces. Make <askids> return theory successors instead of parents (ideally should be content elements).
aspinall
parents:
22171
diff
changeset
|
421 |
(!preferences |> Preferences.set_default ("show-question-marks","false") |
22408 | 422 |
|> Preferences.remove "show-question-marks" (* we use markup, not ?s *) |
22590 | 423 |
|> Preferences.remove "theorem-dependencies" (* set internally *) |
424 |
|> Preferences.remove "full-proofs") (* set internally *) |
|
22228
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
425 |
|
21637 | 426 |
|
427 |
||
428 |
(* Sending commands to Isar *) |
|
429 |
||
26622 | 430 |
fun isarcmd s = Isar.>>> (OuterSyntax.parse Position.none s); |
21637 | 431 |
|
21940 | 432 |
(* TODO: |
27565 | 433 |
- apply a command given a transition function; |
21885
5a11263bd8cf
Remove obsolete prefixes from error and warning messages.
aspinall
parents:
21867
diff
changeset
|
434 |
- fix position from path of currently open file [line numbers risk garbling though]. |
5a11263bd8cf
Remove obsolete prefixes from error and warning messages.
aspinall
parents:
21867
diff
changeset
|
435 |
*) |
21637 | 436 |
|
437 |
(* load an arbitrary file (must be .thy or .ML) *) |
|
438 |
||
439 |
fun use_thy_or_ml_file file = |
|
440 |
let |
|
21858
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
wenzelm
parents:
21655
diff
changeset
|
441 |
val (path,extn) = Path.split_ext (Path.explode file) |
21637 | 442 |
in |
443 |
case extn of |
|
21940 | 444 |
"" => isarcmd ("use_thy " ^ quote (Path.implode path)) |
445 |
| "thy" => isarcmd ("use_thy " ^ quote (Path.implode path)) |
|
21637 | 446 |
| "ML" => isarcmd ("use " ^ quote file) |
22028 | 447 |
| other => error ("Don't know how to read a file with extension " ^ quote other) |
21637 | 448 |
end |
449 |
||
450 |
||
21867 | 451 |
(******* PGIP actions *******) |
21637 | 452 |
|
453 |
||
21940 | 454 |
(* Responses to each of the PGIP input commands. |
21637 | 455 |
These are programmed uniformly for extensibility. *) |
456 |
||
23834
ad6ad61332fa
avoid redundant variables in patterns (which made Alice vomit);
wenzelm
parents:
23801
diff
changeset
|
457 |
fun askpgip (Askpgip _) = |
23435
061f28854017
Remove dedicated flag setting elements in favour of setproverflag. Restore displayconfig response in askpgip.
aspinall
parents:
23226
diff
changeset
|
458 |
(issue_pgip |
061f28854017
Remove dedicated flag setting elements in favour of setproverflag. Restore displayconfig response in askpgip.
aspinall
parents:
23226
diff
changeset
|
459 |
(Usespgip { version = PgipIsabelle.isabelle_pgip_version_supported, |
061f28854017
Remove dedicated flag setting elements in favour of setproverflag. Restore displayconfig response in askpgip.
aspinall
parents:
23226
diff
changeset
|
460 |
pgipelems = PgipIsabelle.accepted_inputs }); |
061f28854017
Remove dedicated flag setting elements in favour of setproverflag. Restore displayconfig response in askpgip.
aspinall
parents:
23226
diff
changeset
|
461 |
send_pgip_config()) |
21637 | 462 |
|
23834
ad6ad61332fa
avoid redundant variables in patterns (which made Alice vomit);
wenzelm
parents:
23801
diff
changeset
|
463 |
fun askpgml (Askpgml _) = |
21637 | 464 |
issue_pgip |
21940 | 465 |
(Usespgml { version = PgipIsabelle.isabelle_pgml_version_supported }) |
21637 | 466 |
|
23834
ad6ad61332fa
avoid redundant variables in patterns (which made Alice vomit);
wenzelm
parents:
23801
diff
changeset
|
467 |
fun askprefs (Askprefs _) = |
21940 | 468 |
let |
469 |
fun preference_of {name, descr, default, pgiptype, get, set } = |
|
470 |
{ name = name, descr = SOME descr, default = SOME default, |
|
471 |
pgiptype = pgiptype } |
|
21637 | 472 |
in |
21940 | 473 |
List.app (fn (prefcat, prefs) => |
474 |
issue_pgip (Hasprefs {prefcategory=SOME prefcat, |
|
475 |
prefs=map preference_of prefs})) |
|
22216
c3f5aa951a68
Tweak preferences for PGIP interfaces. Make <askids> return theory successors instead of parents (ideally should be content elements).
aspinall
parents:
22171
diff
changeset
|
476 |
(!preferences) |
21940 | 477 |
end |
21637 | 478 |
|
23834
ad6ad61332fa
avoid redundant variables in patterns (which made Alice vomit);
wenzelm
parents:
23801
diff
changeset
|
479 |
fun askconfig (Askconfig _) = () (* TODO: add config response *) |
21637 | 480 |
|
481 |
local |
|
21940 | 482 |
fun lookuppref pref = |
483 |
case AList.lookup (op =) |
|
484 |
(map (fn p => (#name p,p)) |
|
22216
c3f5aa951a68
Tweak preferences for PGIP interfaces. Make <askids> return theory successors instead of parents (ideally should be content elements).
aspinall
parents:
22171
diff
changeset
|
485 |
(maps snd (!preferences))) pref of |
21940 | 486 |
NONE => error ("Unknown prover preference: " ^ quote pref) |
487 |
| SOME p => p |
|
21637 | 488 |
in |
21940 | 489 |
fun setpref (Setpref vs) = |
490 |
let |
|
491 |
val name = #name vs |
|
492 |
val value = #value vs |
|
493 |
val set = #set (lookuppref name) |
|
21637 | 494 |
in |
21940 | 495 |
set value |
21637 | 496 |
end |
497 |
||
21902 | 498 |
fun getpref (Getpref vs) = |
21940 | 499 |
let |
500 |
val name = #name vs |
|
501 |
val get = #get (lookuppref name) |
|
502 |
in |
|
21637 | 503 |
issue_pgip (Prefval {name=name, value=get ()}) |
504 |
end |
|
505 |
end |
|
506 |
||
23834
ad6ad61332fa
avoid redundant variables in patterns (which made Alice vomit);
wenzelm
parents:
23801
diff
changeset
|
507 |
fun proverinit _ = restart () |
21637 | 508 |
|
23834
ad6ad61332fa
avoid redundant variables in patterns (which made Alice vomit);
wenzelm
parents:
23801
diff
changeset
|
509 |
fun proverexit _ = isarcmd "quit" |
21637 | 510 |
|
26706 | 511 |
fun set_proverflag_quiet b = |
22408 | 512 |
isarcmd (if b then "disable_pr" else "enable_pr") |
21637 | 513 |
|
22408 | 514 |
fun set_proverflag_pgmlsymbols b = |
515 |
(pgmlsymbols_flag := b; |
|
24614 | 516 |
NAMED_CRITICAL "print_mode" (fn () => |
26706 | 517 |
change print_mode |
22590 | 518 |
(fn mode => |
24614 | 519 |
remove (op =) Symbol.xsymbolsN mode @ (if b then [Symbol.xsymbolsN] else [])))) |
22408 | 520 |
|
521 |
fun set_proverflag_thmdeps b = |
|
522 |
(show_theorem_dependencies := b; |
|
25223 | 523 |
Proofterm.proofs := (if b then 1 else 2)) |
21637 | 524 |
|
22408 | 525 |
fun setproverflag (Setproverflag vs) = |
26706 | 526 |
let |
22590 | 527 |
val flagname = #flagname vs |
528 |
val value = #value vs |
|
22408 | 529 |
in |
22590 | 530 |
(case flagname of |
531 |
"quiet" => set_proverflag_quiet value |
|
532 |
| "pgmlsymbols" => set_proverflag_pgmlsymbols value |
|
26706 | 533 |
| "metainfo:thmdeps" => set_proverflag_thmdeps value |
534 |
| _ => log_msg ("Unrecognised prover control flag: " ^ |
|
23801 | 535 |
(quote flagname) ^ " ignored.")) |
26706 | 536 |
end |
22408 | 537 |
|
21637 | 538 |
|
21940 | 539 |
fun dostep (Dostep vs) = |
540 |
let |
|
541 |
val text = #text vs |
|
542 |
in |
|
543 |
isarcmd text |
|
21637 | 544 |
end |
545 |
||
21902 | 546 |
fun undostep (Undostep vs) = |
21940 | 547 |
let |
548 |
val times = #times vs |
|
549 |
in |
|
550 |
isarcmd ("undos_proof " ^ Int.toString times) |
|
21637 | 551 |
end |
552 |
||
27565 | 553 |
fun redostep _ = sys_error "redo unavailable" |
21940 | 554 |
|
23834
ad6ad61332fa
avoid redundant variables in patterns (which made Alice vomit);
wenzelm
parents:
23801
diff
changeset
|
555 |
fun abortgoal _ = isarcmd "kill" (* was: ProofGeneral.kill_proof *) |
21637 | 556 |
|
557 |
||
21867 | 558 |
(*** PGIP identifier tables ***) |
559 |
||
22228
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
560 |
(* TODO: these ones should be triggered by hooks after a |
22159 | 561 |
declaration addition/removal, to be sent automatically. *) |
21867 | 562 |
|
22159 | 563 |
fun addids t = issue_pgip (Addids {idtables = [t]}) |
564 |
fun delids t = issue_pgip (Delids {idtables = [t]}) |
|
21867 | 565 |
|
27177 | 566 |
|
567 |
local |
|
568 |
||
569 |
fun theory_facts name = |
|
570 |
let val thy = ThyInfo.get_theory name |
|
571 |
in (map PureThy.facts_of (Theory.parents_of thy), PureThy.facts_of thy) end; |
|
572 |
||
573 |
fun thms_of_thy name = map fst (theory_facts name |-> Facts.extern_static); |
|
574 |
fun qualified_thms_of_thy name = map fst (theory_facts name |-> Facts.dest_static); |
|
575 |
||
576 |
in |
|
577 |
||
21940 | 578 |
fun askids (Askids vs) = |
21637 | 579 |
let |
21940 | 580 |
val url = #url vs (* ask for identifiers within a file *) |
581 |
val thyname = #thyname vs (* ask for identifiers within a theory *) |
|
582 |
val objtype = #objtype vs (* ask for identifiers of a particular type *) |
|
21867 | 583 |
|
21940 | 584 |
fun idtable ty ctx ids = {objtype=ty,context=ctx,ids=ids} |
21867 | 585 |
|
22228
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
586 |
fun setids t = issue_pgip (Setids {idtables = [t]}) |
22159 | 587 |
|
22225 | 588 |
(* fake one-level nested "subtheories" by picking apart names. *) |
22243
0f24888c8591
proper use of NameSpace.is_qualified (avoids compatibility issues of the SML B library);
wenzelm
parents:
22228
diff
changeset
|
589 |
val immed_thms_of_thy = filter_out NameSpace.is_qualified o thms_of_thy |
22225 | 590 |
fun thy_prefix s = case space_explode NameSpace.separator s of |
22228
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
591 |
x::_::_ => SOME x (* String.find? *) |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
592 |
| _ => NONE |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
593 |
fun subthys_of_thy s = |
23178 | 594 |
List.foldl (fn (NONE,xs) => xs | (SOME x,xs) => insert op= x xs) [] |
22228
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
595 |
(map thy_prefix (thms_of_thy s)) |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
596 |
fun subthms_of_thy thy = |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
597 |
(case thy_prefix thy of |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
598 |
NONE => immed_thms_of_thy thy |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
599 |
| SOME prf => filter (String.isPrefix (unprefix (prf ^ NameSpace.separator) thy)) |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
600 |
(thms_of_thy prf)) |
26706 | 601 |
in |
21940 | 602 |
case (thyname,objtype) of |
22228
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
603 |
(NONE, NONE) => |
26613 | 604 |
setids (idtable ObjFile NONE (ThyInfo.get_names())) (*FIXME: uris*) |
22228
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
605 |
| (NONE, SOME ObjFile) => |
26613 | 606 |
setids (idtable ObjFile NONE (ThyInfo.get_names())) (*FIXME: uris*) |
22228
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
607 |
| (SOME fi, SOME ObjFile) => |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
608 |
setids (idtable ObjTheory (SOME fi) [fi]) (* TODO: check exists *) |
22225 | 609 |
| (NONE, SOME ObjTheory) => |
26613 | 610 |
setids (idtable ObjTheory NONE (ThyInfo.get_names())) |
22225 | 611 |
| (SOME thy, SOME ObjTheory) => |
22228
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
612 |
setids (idtable ObjTheory (SOME thy) (subthys_of_thy thy)) |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
613 |
| (SOME thy, SOME ObjTheorem) => |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
614 |
setids (idtable ObjTheorem (SOME thy) (subthms_of_thy thy)) |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
615 |
| (NONE, SOME ObjTheorem) => |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
616 |
(* A large query, but not unreasonable. ~5000 results for HOL.*) |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
617 |
(* Several setids should be allowed, but Eclipse code is currently broken: |
23226 | 618 |
List.app (fn thy => setids (idtable ObjTheorem (SOME thy) (subthms_of_thy thy))) |
26613 | 619 |
(ThyInfo.get_names()) *) |
22225 | 620 |
setids (idtable ObjTheorem NONE (* this one gives ~7000 for HOL *) |
26613 | 621 |
(maps qualified_thms_of_thy (ThyInfo.get_names()))) |
22225 | 622 |
| _ => warning ("askids: ignored argument combination") |
21637 | 623 |
end |
624 |
||
27177 | 625 |
end; |
626 |
||
22159 | 627 |
fun askrefs (Askrefs vs) = |
628 |
let |
|
629 |
val url = #url vs (* ask for references of a file (i.e. immediate pre-requisites) *) |
|
630 |
val thyname = #thyname vs (* ask for references of a theory (other theories) *) |
|
631 |
val objtype = #objtype vs (* ask for references of a particular type... *) |
|
632 |
val name = #name vs (* ... with this name *) |
|
633 |
||
634 |
fun idtable ty ctx ids = {objtype=ty,context=ctx,ids=ids} |
|
635 |
||
22228
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
636 |
val thy_name = Path.implode o #1 o Path.split_ext o Path.base |
22159 | 637 |
|
22228
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
638 |
fun filerefs f = |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
639 |
let val thy = thy_name f |
24189
1fa9852643a3
simplified ThyLoad.deps_thy etc.: discontinued attached ML files;
wenzelm
parents:
24079
diff
changeset
|
640 |
val filerefs = #uses (ThyLoad.deps_thy (Path.dir f) thy) |
22228
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
641 |
in |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
642 |
issue_pgip (Setrefs {url=url, thyname=NONE, objtype=SOME PgipTypes.ObjFile, |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
643 |
name=NONE, idtables=[], fileurls=filerefs}) |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
644 |
end |
22159 | 645 |
|
22228
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
646 |
fun thyrefs thy = |
24189
1fa9852643a3
simplified ThyLoad.deps_thy etc.: discontinued attached ML files;
wenzelm
parents:
24079
diff
changeset
|
647 |
let val thyrefs = #imports (ThyLoad.deps_thy Path.current thy) |
22228
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
648 |
in |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
649 |
issue_pgip (Setrefs {url=url, thyname=thyname, objtype=SOME PgipTypes.ObjTheory, |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
650 |
name=NONE, idtables=[{context=NONE, objtype=PgipTypes.ObjTheory, |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
651 |
ids=thyrefs}], fileurls=[]}) |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
652 |
end |
22159 | 653 |
|
22228
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
654 |
fun thmrefs thmname = |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
655 |
let |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
656 |
(* TODO: interim: this is probably not right. |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
657 |
What we want is mapping onto simple PGIP name/context model. *) |
26603 | 658 |
val ctx = Toplevel.context_of (Isar.state ()) (* NB: raises UNDEF *) |
22228
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
659 |
val thy = Context.theory_of_proof ctx |
26343
0dd2eab7b296
simplified get_thm(s): back to plain name argument;
wenzelm
parents:
26336
diff
changeset
|
660 |
val ths = [PureThy.get_thm thy thmname] |
22228
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
661 |
val deps = filter_out (equal "") |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
662 |
(Symtab.keys (fold Proofterm.thms_of_proof |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
663 |
(map Thm.proof_of ths) Symtab.empty)) |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
664 |
in |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
665 |
if null deps then () |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
666 |
else issue_pgip (Setrefs {url=url, thyname=thyname, name=name, |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
667 |
objtype=SOME PgipTypes.ObjTheorem, |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
668 |
idtables=[{context=NONE, objtype=PgipTypes.ObjTheorem, |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
669 |
ids=deps}], fileurls=[]}) |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
670 |
end |
22159 | 671 |
in |
672 |
case (url,thyname,objtype,name) of |
|
22228
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
673 |
(SOME file, NONE, _, _) => filerefs file |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
674 |
| (_,SOME thy,_,_) => thyrefs thy |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
675 |
| (_,_,SOME PgipTypes.ObjTheorem,SOME thmname) => thmrefs thmname |
22159 | 676 |
| _ => error ("Unimplemented/invalid case of <askrefs>") |
677 |
end |
|
678 |
||
679 |
||
680 |
||
21940 | 681 |
fun showid (Showid vs) = |
21637 | 682 |
let |
21940 | 683 |
val thyname = #thyname vs |
684 |
val objtype = #objtype vs |
|
685 |
val name = #name vs |
|
22337
d4599c206446
Fix <pgipquit>. Remove unused pgmlatomsN. Make showid match askids. Use string functions for showid, avoiding printwrap kludge.
aspinall
parents:
22249
diff
changeset
|
686 |
|
26603 | 687 |
val topthy = Toplevel.theory_of o Isar.state |
21637 | 688 |
|
22590 | 689 |
fun splitthy id = |
690 |
let val comps = NameSpace.explode id |
|
691 |
in case comps of |
|
692 |
(thy::(rest as _::_)) => (ThyInfo.get_theory thy, space_implode "." rest) |
|
693 |
| [plainid] => (topthy(),plainid) |
|
694 |
| _ => raise Toplevel.UNDEF (* assert false *) |
|
26706 | 695 |
end |
696 |
||
21637 | 697 |
|
22337
d4599c206446
Fix <pgipquit>. Remove unused pgmlatomsN. Make showid match askids. Use string functions for showid, avoiding printwrap kludge.
aspinall
parents:
22249
diff
changeset
|
698 |
fun idvalue strings = |
26706 | 699 |
issue_pgip (Idvalue { thyname=thyname, objtype=objtype, name=name, |
23759
90bccef65004
Fix nested PGIP messages. Update for schema simplifications.
aspinall
parents:
23723
diff
changeset
|
700 |
text=[XML.Elem("pgml",[], |
23723 | 701 |
map XML.Output strings)] }) |
22337
d4599c206446
Fix <pgipquit>. Remove unused pgmlatomsN. Make showid match askids. Use string functions for showid, avoiding printwrap kludge.
aspinall
parents:
22249
diff
changeset
|
702 |
|
22590 | 703 |
fun string_of_thm th = Output.output |
704 |
(Pretty.string_of |
|
705 |
(Display.pretty_thm_aux |
|
26939
1035c89b4c02
moved global pretty/string_of functions from Sign to Syntax;
wenzelm
parents:
26723
diff
changeset
|
706 |
(Syntax.pp_global (Thm.theory_of_thm th)) |
22590 | 707 |
false (* quote *) |
708 |
false (* show hyps *) |
|
709 |
[] (* asms *) |
|
710 |
th)) |
|
22337
d4599c206446
Fix <pgipquit>. Remove unused pgmlatomsN. Make showid match askids. Use string functions for showid, avoiding printwrap kludge.
aspinall
parents:
22249
diff
changeset
|
711 |
|
26343
0dd2eab7b296
simplified get_thm(s): back to plain name argument;
wenzelm
parents:
26336
diff
changeset
|
712 |
fun strings_of_thm (thy, name) = map string_of_thm (PureThy.get_thms thy name) |
22337
d4599c206446
Fix <pgipquit>. Remove unused pgmlatomsN. Make showid match askids. Use string functions for showid, avoiding printwrap kludge.
aspinall
parents:
22249
diff
changeset
|
713 |
|
22590 | 714 |
val string_of_thy = Output.output o |
715 |
Pretty.string_of o (ProofDisplay.pretty_full_theory false) |
|
21940 | 716 |
in |
717 |
case (thyname, objtype) of |
|
22337
d4599c206446
Fix <pgipquit>. Remove unused pgmlatomsN. Make showid match askids. Use string functions for showid, avoiding printwrap kludge.
aspinall
parents:
22249
diff
changeset
|
718 |
(_,ObjTheory) => idvalue [string_of_thy (ThyInfo.get_theory name)] |
d4599c206446
Fix <pgipquit>. Remove unused pgmlatomsN. Make showid match askids. Use string functions for showid, avoiding printwrap kludge.
aspinall
parents:
22249
diff
changeset
|
719 |
| (SOME thy, ObjTheorem) => idvalue (strings_of_thm (ThyInfo.get_theory thy, name)) |
d4599c206446
Fix <pgipquit>. Remove unused pgmlatomsN. Make showid match askids. Use string functions for showid, avoiding printwrap kludge.
aspinall
parents:
22249
diff
changeset
|
720 |
| (NONE, ObjTheorem) => idvalue (strings_of_thm (splitthy name)) |
21940 | 721 |
| (_, ot) => error ("Cannot show objects of type "^(PgipTypes.name_of_objtype ot)) |
21637 | 722 |
end |
723 |
||
21867 | 724 |
(*** Inspecting state ***) |
725 |
||
21940 | 726 |
(* The file which is currently being processed interactively. |
21637 | 727 |
In the pre-PGIP code, this was informed to Isabelle and the theory loader |
728 |
on completion, but that allows for circularity in case we read |
|
729 |
ourselves. So PGIP opens the filename at the start of a script. |
|
730 |
We ought to prevent problems by modifying the theory loader to know |
|
21940 | 731 |
about this special status, but for now we just keep a local reference. |
732 |
*) |
|
21637 | 733 |
|
734 |
val currently_open_file = ref (NONE : pgipurl option) |
|
735 |
||
22163 | 736 |
fun get_currently_open_file () = ! currently_open_file; |
737 |
||
23834
ad6ad61332fa
avoid redundant variables in patterns (which made Alice vomit);
wenzelm
parents:
23801
diff
changeset
|
738 |
fun askguise _ = |
21637 | 739 |
(* The "guise" is the PGIP abstraction of the prover's state. |
740 |
The <informguise> message is merely used for consistency checking. *) |
|
21940 | 741 |
let |
742 |
val openfile = !currently_open_file |
|
21637 | 743 |
|
26603 | 744 |
val topthy = Toplevel.theory_of o Isar.state |
21940 | 745 |
val topthy_name = Context.theory_name o topthy |
21637 | 746 |
|
21940 | 747 |
val opentheory = SOME (topthy_name()) handle Toplevel.UNDEF => NONE |
21637 | 748 |
|
21940 | 749 |
fun topproofpos () = try Toplevel.proof_position_of (Isar.state ()); |
750 |
val openproofpos = topproofpos() |
|
21637 | 751 |
in |
752 |
issue_pgip (Informguise { file = openfile, |
|
21940 | 753 |
theory = opentheory, |
754 |
(* would be nice to get thm name... *) |
|
755 |
theorem = NONE, |
|
756 |
proofpos = openproofpos }) |
|
21637 | 757 |
end |
758 |
||
21902 | 759 |
fun parsescript (Parsescript vs) = |
21637 | 760 |
let |
21940 | 761 |
val text = #text vs |
762 |
val systemdata = #systemdata vs |
|
763 |
val location = #location vs (* TODO: extract position *) |
|
21637 | 764 |
|
21867 | 765 |
val _ = start_delay_msgs () (* gather parsing errs/warns *) |
25274 | 766 |
val doc = PgipParser.pgip_parser Position.none text |
21637 | 767 |
val errs = end_delayed_msgs () |
768 |
||
21940 | 769 |
val sysattrs = PgipTypes.opt_attr "systemdata" systemdata |
770 |
val locattrs = PgipTypes.attrs_of_location location |
|
21637 | 771 |
in |
772 |
issue_pgip (Parseresult { attrs= sysattrs@locattrs, |
|
21940 | 773 |
doc = doc, |
774 |
errs = map PgipOutput.output errs }) |
|
21637 | 775 |
end |
776 |
||
23834
ad6ad61332fa
avoid redundant variables in patterns (which made Alice vomit);
wenzelm
parents:
23801
diff
changeset
|
777 |
fun showproofstate _ = isarcmd "pr" |
21637 | 778 |
|
23834
ad6ad61332fa
avoid redundant variables in patterns (which made Alice vomit);
wenzelm
parents:
23801
diff
changeset
|
779 |
fun showctxt _ = isarcmd "print_context" |
21637 | 780 |
|
21902 | 781 |
fun searchtheorems (Searchtheorems vs) = |
21940 | 782 |
let |
783 |
val arg = #arg vs |
|
21637 | 784 |
in |
21969 | 785 |
isarcmd ("find_theorems " ^ arg) |
21637 | 786 |
end |
787 |
||
21940 | 788 |
fun setlinewidth (Setlinewidth vs) = |
789 |
let |
|
790 |
val width = #width vs |
|
21637 | 791 |
in |
21940 | 792 |
isarcmd ("pretty_setmargin " ^ Int.toString width) (* FIXME: conversion back/forth! *) |
21637 | 793 |
end |
794 |
||
21902 | 795 |
fun viewdoc (Viewdoc vs) = |
21940 | 796 |
let |
797 |
val arg = #arg vs |
|
798 |
in |
|
799 |
isarcmd ("print_" ^ arg) (* FIXME: isatool doc?. Return URLs, maybe? *) |
|
21637 | 800 |
end |
801 |
||
21867 | 802 |
(*** Theory ***) |
803 |
||
21902 | 804 |
fun doitem (Doitem vs) = |
21637 | 805 |
let |
21940 | 806 |
val text = #text vs |
21637 | 807 |
in |
21940 | 808 |
isarcmd text |
21637 | 809 |
end |
810 |
||
23834
ad6ad61332fa
avoid redundant variables in patterns (which made Alice vomit);
wenzelm
parents:
23801
diff
changeset
|
811 |
fun undoitem _ = |
21972
1b68312c4cf0
Initialise parser at startup. Remove some obsolete ProofGeneral.XXX outer syntax, mapping PGIP commands directly to Isar.
aspinall
parents:
21970
diff
changeset
|
812 |
isarcmd "undo" |
21637 | 813 |
|
23834
ad6ad61332fa
avoid redundant variables in patterns (which made Alice vomit);
wenzelm
parents:
23801
diff
changeset
|
814 |
fun redoitem _ = |
21972
1b68312c4cf0
Initialise parser at startup. Remove some obsolete ProofGeneral.XXX outer syntax, mapping PGIP commands directly to Isar.
aspinall
parents:
21970
diff
changeset
|
815 |
isarcmd "redo" |
21637 | 816 |
|
23834
ad6ad61332fa
avoid redundant variables in patterns (which made Alice vomit);
wenzelm
parents:
23801
diff
changeset
|
817 |
fun aborttheory _ = |
21972
1b68312c4cf0
Initialise parser at startup. Remove some obsolete ProofGeneral.XXX outer syntax, mapping PGIP commands directly to Isar.
aspinall
parents:
21970
diff
changeset
|
818 |
isarcmd "kill" (* was: "init_toplevel" *) |
21637 | 819 |
|
21902 | 820 |
fun retracttheory (Retracttheory vs) = |
21940 | 821 |
let |
822 |
val thyname = #thyname vs |
|
21637 | 823 |
in |
21940 | 824 |
isarcmd ("kill_thy " ^ quote thyname) |
21637 | 825 |
end |
826 |
||
21867 | 827 |
|
828 |
(*** Files ***) |
|
829 |
||
830 |
(* Path management: we allow theory files to have dependencies in |
|
831 |
their own directory, but when we change directory for a new file we |
|
832 |
remove the path. Leaving it there can cause confusion with |
|
833 |
difference in batch mode. |
|
21940 | 834 |
NB: PGIP does not assume that the prover has a load path. |
21867 | 835 |
*) |
836 |
||
837 |
local |
|
838 |
val current_working_dir = ref (NONE : string option) |
|
839 |
in |
|
21940 | 840 |
fun changecwd_dir newdirpath = |
841 |
let |
|
21867 | 842 |
val newdir = File.platform_path newdirpath |
21940 | 843 |
in |
21867 | 844 |
(case (!current_working_dir) of |
845 |
NONE => () |
|
846 |
| SOME dir => ThyLoad.del_path dir; |
|
847 |
ThyLoad.add_path newdir; |
|
848 |
current_working_dir := SOME newdir) |
|
849 |
end |
|
850 |
end |
|
851 |
||
21940 | 852 |
fun changecwd (Changecwd vs) = |
853 |
let |
|
854 |
val url = #url vs |
|
855 |
val newdir = PgipTypes.path_of_pgipurl url |
|
21867 | 856 |
in |
21940 | 857 |
changecwd_dir url |
21867 | 858 |
end |
859 |
||
21902 | 860 |
fun openfile (Openfile vs) = |
21940 | 861 |
let |
21867 | 862 |
val url = #url vs |
863 |
val filepath = PgipTypes.path_of_pgipurl url |
|
864 |
val filedir = Path.dir filepath |
|
865 |
val thy_name = Path.implode o #1 o Path.split_ext o Path.base |
|
866 |
val openfile_retract = Output.no_warnings (ThyInfo.if_known_thy ThyInfo.remove_thy) o thy_name; |
|
867 |
in |
|
868 |
case !currently_open_file of |
|
22028 | 869 |
SOME f => raise PGIP ("<openfile> when a file is already open!\nCurrently open file: " ^ |
22228
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
870 |
PgipTypes.string_of_pgipurl url) |
21867 | 871 |
| NONE => (openfile_retract filepath; |
21940 | 872 |
changecwd_dir filedir; |
22228
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
873 |
priority ("Working in file: " ^ PgipTypes.string_of_pgipurl url); |
21940 | 874 |
currently_open_file := SOME url) |
21867 | 875 |
end |
876 |
||
23834
ad6ad61332fa
avoid redundant variables in patterns (which made Alice vomit);
wenzelm
parents:
23801
diff
changeset
|
877 |
fun closefile _ = |
21867 | 878 |
case !currently_open_file of |
22042
64f8f5433f30
Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents:
22028
diff
changeset
|
879 |
SOME f => (proper_inform_file_processed f (Isar.state()); |
22228
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
880 |
priority ("Finished working in file: " ^ PgipTypes.string_of_pgipurl f); |
21867 | 881 |
currently_open_file := NONE) |
882 |
| NONE => raise PGIP ("<closefile> when no file is open!") |
|
883 |
||
21940 | 884 |
fun loadfile (Loadfile vs) = |
885 |
let |
|
886 |
val url = #url vs |
|
887 |
in |
|
22171
58f554f51f0d
Let <loadfile> execute even while a file is open interactively.
aspinall
parents:
22163
diff
changeset
|
888 |
(* da: this doesn't seem to cause a problem, batch loading uses |
58f554f51f0d
Let <loadfile> execute even while a file is open interactively.
aspinall
parents:
22163
diff
changeset
|
889 |
a different state context. Of course confusion is still possible, |
58f554f51f0d
Let <loadfile> execute even while a file is open interactively.
aspinall
parents:
22163
diff
changeset
|
890 |
e.g. file loaded depends on open file which is not yet saved. *) |
58f554f51f0d
Let <loadfile> execute even while a file is open interactively.
aspinall
parents:
22163
diff
changeset
|
891 |
(* case !currently_open_file of |
22028 | 892 |
SOME f => raise PGIP ("<loadfile> when a file is open!\nCurrently open file: " ^ |
22228
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
893 |
PgipTypes.string_of_pgipurl url) |
22171
58f554f51f0d
Let <loadfile> execute even while a file is open interactively.
aspinall
parents:
22163
diff
changeset
|
894 |
| NONE => *) |
22228
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
895 |
use_thy_or_ml_file (File.platform_path url) |
21637 | 896 |
end |
897 |
||
23834
ad6ad61332fa
avoid redundant variables in patterns (which made Alice vomit);
wenzelm
parents:
23801
diff
changeset
|
898 |
fun abortfile _ = |
21637 | 899 |
case !currently_open_file of |
900 |
SOME f => (isarcmd "init_toplevel"; |
|
22228
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
901 |
priority ("Aborted working in file: " ^ |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
902 |
PgipTypes.string_of_pgipurl f); |
21940 | 903 |
currently_open_file := NONE) |
21637 | 904 |
| NONE => raise PGIP ("<abortfile> when no file is open!") |
905 |
||
21940 | 906 |
fun retractfile (Retractfile vs) = |
907 |
let |
|
908 |
val url = #url vs |
|
21637 | 909 |
in |
21940 | 910 |
case !currently_open_file of |
21637 | 911 |
SOME f => raise PGIP ("<retractfile> when a file is open!") |
22028 | 912 |
| NONE => (priority ("Retracting file: " ^ PgipTypes.string_of_pgipurl url); |
22228
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
913 |
(* TODO: next should be in thy loader, here just for testing *) |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
914 |
let |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
915 |
val name = thy_name url |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
916 |
in List.app (tell_file_retracted false) (ThyInfo.loaded_files name) end; |
7c27195a4afc
proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents:
22225
diff
changeset
|
917 |
inform_file_retracted url) |
21637 | 918 |
end |
919 |
||
920 |
||
21867 | 921 |
(*** System ***) |
21637 | 922 |
|
21902 | 923 |
fun systemcmd (Systemcmd vs) = |
21940 | 924 |
let |
21637 | 925 |
val arg = #arg vs |
926 |
in |
|
927 |
isarcmd arg |
|
928 |
end |
|
929 |
||
930 |
exception PGIP_QUIT; |
|
23834
ad6ad61332fa
avoid redundant variables in patterns (which made Alice vomit);
wenzelm
parents:
23801
diff
changeset
|
931 |
fun quitpgip _ = raise PGIP_QUIT |
21637 | 932 |
|
21902 | 933 |
fun process_input inp = case inp |
934 |
of Pgip.Askpgip _ => askpgip inp |
|
935 |
| Pgip.Askpgml _ => askpgml inp |
|
21940 | 936 |
| Pgip.Askprefs _ => askprefs inp |
21902 | 937 |
| Pgip.Askconfig _ => askconfig inp |
938 |
| Pgip.Getpref _ => getpref inp |
|
939 |
| Pgip.Setpref _ => setpref inp |
|
940 |
| Pgip.Proverinit _ => proverinit inp |
|
941 |
| Pgip.Proverexit _ => proverexit inp |
|
22408 | 942 |
| Pgip.Setproverflag _ => setproverflag inp |
21902 | 943 |
| Pgip.Dostep _ => dostep inp |
944 |
| Pgip.Undostep _ => undostep inp |
|
945 |
| Pgip.Redostep _ => redostep inp |
|
23435
061f28854017
Remove dedicated flag setting elements in favour of setproverflag. Restore displayconfig response in askpgip.
aspinall
parents:
23226
diff
changeset
|
946 |
| Pgip.Forget _ => error "<forget> not implemented by Isabelle" |
061f28854017
Remove dedicated flag setting elements in favour of setproverflag. Restore displayconfig response in askpgip.
aspinall
parents:
23226
diff
changeset
|
947 |
| Pgip.Restoregoal _ => error "<restoregoal> not implemented by Isabelle" |
21902 | 948 |
| Pgip.Abortgoal _ => abortgoal inp |
949 |
| Pgip.Askids _ => askids inp |
|
22159 | 950 |
| Pgip.Askrefs _ => askrefs inp |
21902 | 951 |
| Pgip.Showid _ => showid inp |
952 |
| Pgip.Askguise _ => askguise inp |
|
953 |
| Pgip.Parsescript _ => parsescript inp |
|
954 |
| Pgip.Showproofstate _ => showproofstate inp |
|
955 |
| Pgip.Showctxt _ => showctxt inp |
|
956 |
| Pgip.Searchtheorems _ => searchtheorems inp |
|
957 |
| Pgip.Setlinewidth _ => setlinewidth inp |
|
958 |
| Pgip.Viewdoc _ => viewdoc inp |
|
959 |
| Pgip.Doitem _ => doitem inp |
|
960 |
| Pgip.Undoitem _ => undoitem inp |
|
961 |
| Pgip.Redoitem _ => redoitem inp |
|
962 |
| Pgip.Aborttheory _ => aborttheory inp |
|
963 |
| Pgip.Retracttheory _ => retracttheory inp |
|
964 |
| Pgip.Loadfile _ => loadfile inp |
|
965 |
| Pgip.Openfile _ => openfile inp |
|
966 |
| Pgip.Closefile _ => closefile inp |
|
967 |
| Pgip.Abortfile _ => abortfile inp |
|
968 |
| Pgip.Retractfile _ => retractfile inp |
|
969 |
| Pgip.Changecwd _ => changecwd inp |
|
970 |
| Pgip.Systemcmd _ => systemcmd inp |
|
971 |
| Pgip.Quitpgip _ => quitpgip inp |
|
21637 | 972 |
|
973 |
||
21940 | 974 |
fun process_pgip_element pgipxml = |
21637 | 975 |
case pgipxml of |
21969 | 976 |
xml as (XML.Elem elem) => |
21940 | 977 |
(case Pgip.input elem of |
978 |
NONE => warning ("Unrecognized PGIP command, ignored: \n" ^ |
|
26541 | 979 |
(XML.string_of xml)) |
21940 | 980 |
| SOME inp => (process_input inp)) (* errors later; packet discarded *) |
21969 | 981 |
| XML.Text t => ignored_text_warning t |
23723 | 982 |
| XML.Output t => ignored_text_warning t |
21637 | 983 |
and ignored_text_warning t = |
21940 | 984 |
if size (Symbol.strip_blanks t) > 0 then |
985 |
warning ("Ignored text in PGIP packet: \n" ^ t) |
|
21637 | 986 |
else () |
987 |
||
988 |
fun process_pgip_tree xml = |
|
989 |
(pgip_refid := NONE; |
|
990 |
pgip_refseq := NONE; |
|
991 |
(case xml of |
|
992 |
XML.Elem ("pgip", attrs, pgips) => |
|
993 |
(let |
|
994 |
val class = PgipTypes.get_attr "class" attrs |
|
995 |
val dest = PgipTypes.get_attr_opt "destid" attrs |
|
21940 | 996 |
val seq = PgipTypes.read_pgipnat (PgipTypes.get_attr "seq" attrs) |
21637 | 997 |
(* Respond to prover broadcasts, or messages for us. Ignore rest *) |
21940 | 998 |
val processit = |
999 |
case dest of |
|
21637 | 1000 |
NONE => class = "pa" |
21940 | 1001 |
| SOME id => matching_pgip_id id |
1002 |
in if processit then |
|
1003 |
(pgip_refid := PgipTypes.get_attr_opt "id" attrs; |
|
1004 |
pgip_refseq := SOME seq; |
|
1005 |
List.app process_pgip_element pgips; |
|
1006 |
(* return true to indicate <ready/> *) |
|
1007 |
true) |
|
1008 |
else |
|
1009 |
(* no response to ignored messages. *) |
|
1010 |
false |
|
21637 | 1011 |
end) |
1012 |
| _ => raise PGIP "Invalid PGIP packet received") |
|
1013 |
handle PGIP msg => |
|
1014 |
(Output.error_msg ((msg ^ "\nPGIP error occured in XML text below:\n") ^ |
|
26541 | 1015 |
(XML.string_of xml)); |
21940 | 1016 |
true)) |
21637 | 1017 |
|
21649
40e6fdd26f82
Support PGIP communication for preferences in Emacs mode.
aspinall
parents:
21646
diff
changeset
|
1018 |
(* External input *) |
40e6fdd26f82
Support PGIP communication for preferences in Emacs mode.
aspinall
parents:
21646
diff
changeset
|
1019 |
|
26541 | 1020 |
val process_pgip_plain = K () o process_pgip_tree o XML.parse |
21637 | 1021 |
|
1022 |
(* PGIP loop: process PGIP input only *) |
|
1023 |
||
1024 |
local |
|
1025 |
||
1026 |
exception XML_PARSE |
|
1027 |
||
1028 |
fun loop ready src = |
|
1029 |
let |
|
1030 |
val _ = if ready then issue_pgip (Ready ()) else () |
|
21969 | 1031 |
val pgipo = |
1032 |
(case try Source.get_single src of |
|
1033 |
SOME pgipo => pgipo |
|
1034 |
| NONE => raise XML_PARSE) |
|
21637 | 1035 |
in |
1036 |
case pgipo of |
|
1037 |
NONE => () |
|
1038 |
| SOME (pgip,src') => |
|
1039 |
let |
|
21940 | 1040 |
val ready' = (process_pgip_tree pgip) |
22337
d4599c206446
Fix <pgipquit>. Remove unused pgmlatomsN. Make showid match askids. Use string functions for showid, avoiding printwrap kludge.
aspinall
parents:
22249
diff
changeset
|
1041 |
handle PGIP_QUIT => raise PGIP_QUIT |
22590 | 1042 |
| e => (handler (e,SOME src'); true) |
21637 | 1043 |
in |
1044 |
loop ready' src' |
|
1045 |
end |
|
1046 |
end handle e => handler (e,SOME src) (* error in XML parse or Ready issue *) |
|
1047 |
||
1048 |
and handler (e,srco) = |
|
1049 |
case (e,srco) of |
|
1050 |
(XML_PARSE,SOME src) => |
|
22699
938c1011ac94
removed unused Output.panic hook -- internal to PG wrapper;
wenzelm
parents:
22678
diff
changeset
|
1051 |
panic "Invalid XML input, aborting" (* TODO: attempt recovery *) |
21940 | 1052 |
| (Interrupt,SOME src) => |
1053 |
(Output.error_msg "Interrupt during PGIP processing"; loop true src) |
|
1054 |
| (Toplevel.UNDEF,SOME src) => |
|
1055 |
(Output.error_msg "No working context defined"; loop true src) |
|
1056 |
| (e,SOME src) => |
|
1057 |
(Output.error_msg (Toplevel.exn_message e); loop true src) |
|
22337
d4599c206446
Fix <pgipquit>. Remove unused pgmlatomsN. Make showid match askids. Use string functions for showid, avoiding printwrap kludge.
aspinall
parents:
22249
diff
changeset
|
1058 |
| (PGIP_QUIT,_) => () |
21637 | 1059 |
| (_,NONE) => () |
1060 |
in |
|
1061 |
(* TODO: add socket interface *) |
|
1062 |
||
26552
5677b4faf295
renamed XML.parse_comment_whspc to XML.parse_comments;
wenzelm
parents:
26548
diff
changeset
|
1063 |
val xmlP = XML.parse_comments |-- XML.parse_element >> single |
21637 | 1064 |
|
1065 |
val tty_src = Source.set_prompt "" (Source.source Symbol.stopper xmlP NONE Source.tty) |
|
1066 |
||
1067 |
fun pgip_toplevel x = loop true x |
|
1068 |
end |
|
1069 |
||
1070 |
||
21972
1b68312c4cf0
Initialise parser at startup. Remove some obsolete ProofGeneral.XXX outer syntax, mapping PGIP commands directly to Isar.
aspinall
parents:
21970
diff
changeset
|
1071 |
(* Extra command for embedding prover-control inside document (obscure/debug usage). *) |
21637 | 1072 |
|
24867 | 1073 |
fun init_outer_syntax () = |
21972
1b68312c4cf0
Initialise parser at startup. Remove some obsolete ProofGeneral.XXX outer syntax, mapping PGIP commands directly to Isar.
aspinall
parents:
21970
diff
changeset
|
1074 |
OuterSyntax.improper_command "ProofGeneral.process_pgip" "(internal)" OuterKeyword.control |
1b68312c4cf0
Initialise parser at startup. Remove some obsolete ProofGeneral.XXX outer syntax, mapping PGIP commands directly to Isar.
aspinall
parents:
21970
diff
changeset
|
1075 |
(OuterParse.text >> (Toplevel.no_timing oo |
21649
40e6fdd26f82
Support PGIP communication for preferences in Emacs mode.
aspinall
parents:
21646
diff
changeset
|
1076 |
(fn txt => Toplevel.imperative (fn () => process_pgip_plain txt)))); |
21637 | 1077 |
|
1078 |
||
1079 |
(* init *) |
|
1080 |
||
1081 |
val initialized = ref false; |
|
1082 |
||
22699
938c1011ac94
removed unused Output.panic hook -- internal to PG wrapper;
wenzelm
parents:
22678
diff
changeset
|
1083 |
fun init_pgip false = panic "No Proof General interface support for Isabelle/classic mode." |
21969 | 1084 |
| init_pgip true = |
1085 |
(! initialized orelse |
|
25445
01f3686f4304
Init outer syntax after message setup to avoid spurious output.
aspinall
parents:
25275
diff
changeset
|
1086 |
(setup_preferences_tweak (); |
01f3686f4304
Init outer syntax after message setup to avoid spurious output.
aspinall
parents:
25275
diff
changeset
|
1087 |
setup_proofgeneral_output (); |
01f3686f4304
Init outer syntax after message setup to avoid spurious output.
aspinall
parents:
25275
diff
changeset
|
1088 |
setup_messages (); |
01f3686f4304
Init outer syntax after message setup to avoid spurious output.
aspinall
parents:
25275
diff
changeset
|
1089 |
Output.no_warnings init_outer_syntax (); |
01f3686f4304
Init outer syntax after message setup to avoid spurious output.
aspinall
parents:
25275
diff
changeset
|
1090 |
setup_thy_loader (); |
01f3686f4304
Init outer syntax after message setup to avoid spurious output.
aspinall
parents:
25275
diff
changeset
|
1091 |
setup_present_hook (); |
01f3686f4304
Init outer syntax after message setup to avoid spurious output.
aspinall
parents:
25275
diff
changeset
|
1092 |
init_pgip_session_id (); |
01f3686f4304
Init outer syntax after message setup to avoid spurious output.
aspinall
parents:
25275
diff
changeset
|
1093 |
welcome (); |
01f3686f4304
Init outer syntax after message setup to avoid spurious output.
aspinall
parents:
25275
diff
changeset
|
1094 |
set initialized); |
21969 | 1095 |
sync_thy_loader (); |
1096 |
change print_mode (cons proof_generalN o remove (op =) proof_generalN); |
|
1097 |
pgip_toplevel tty_src); |
|
21637 | 1098 |
|
21649
40e6fdd26f82
Support PGIP communication for preferences in Emacs mode.
aspinall
parents:
21646
diff
changeset
|
1099 |
|
40e6fdd26f82
Support PGIP communication for preferences in Emacs mode.
aspinall
parents:
21646
diff
changeset
|
1100 |
|
40e6fdd26f82
Support PGIP communication for preferences in Emacs mode.
aspinall
parents:
21646
diff
changeset
|
1101 |
(** Out-of-loop PGIP commands (for Emacs hybrid mode) **) |
40e6fdd26f82
Support PGIP communication for preferences in Emacs mode.
aspinall
parents:
21646
diff
changeset
|
1102 |
|
40e6fdd26f82
Support PGIP communication for preferences in Emacs mode.
aspinall
parents:
21646
diff
changeset
|
1103 |
local |
22590 | 1104 |
val pgip_output_channel = ref Output.writeln_default |
21649
40e6fdd26f82
Support PGIP communication for preferences in Emacs mode.
aspinall
parents:
21646
diff
changeset
|
1105 |
in |
40e6fdd26f82
Support PGIP communication for preferences in Emacs mode.
aspinall
parents:
21646
diff
changeset
|
1106 |
|
40e6fdd26f82
Support PGIP communication for preferences in Emacs mode.
aspinall
parents:
21646
diff
changeset
|
1107 |
(* Set recipient for PGIP results *) |
40e6fdd26f82
Support PGIP communication for preferences in Emacs mode.
aspinall
parents:
21646
diff
changeset
|
1108 |
fun init_pgip_channel writefn = |
21940 | 1109 |
(init_pgip_session_id(); |
1110 |
pgip_output_channel := writefn) |
|
21649
40e6fdd26f82
Support PGIP communication for preferences in Emacs mode.
aspinall
parents:
21646
diff
changeset
|
1111 |
|
21940 | 1112 |
(* Process a PGIP command. |
1113 |
This works for preferences but not generally guaranteed |
|
21649
40e6fdd26f82
Support PGIP communication for preferences in Emacs mode.
aspinall
parents:
21646
diff
changeset
|
1114 |
because we haven't done full setup here (e.g., no pgml mode) *) |
40e6fdd26f82
Support PGIP communication for preferences in Emacs mode.
aspinall
parents:
21646
diff
changeset
|
1115 |
fun process_pgip str = |
40e6fdd26f82
Support PGIP communication for preferences in Emacs mode.
aspinall
parents:
21646
diff
changeset
|
1116 |
setmp output_xml_fn (!pgip_output_channel) process_pgip_plain str |
40e6fdd26f82
Support PGIP communication for preferences in Emacs mode.
aspinall
parents:
21646
diff
changeset
|
1117 |
|
40e6fdd26f82
Support PGIP communication for preferences in Emacs mode.
aspinall
parents:
21646
diff
changeset
|
1118 |
end |
21637 | 1119 |
|
1120 |
end; |
|
26706 | 1121 |