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