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