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