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