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