src/Pure/ProofGeneral/proof_general_pgip.ML
author aspinall
Sun, 31 Dec 2006 14:55:35 +0100
changeset 21972 1b68312c4cf0
parent 21970 1845e43aee93
child 21983 9fb029d1189b
permissions -rw-r--r--
Initialise parser at startup. Remove some obsolete ProofGeneral.XXX outer syntax, mapping PGIP commands directly to Isar.
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
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    16
end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    17
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    18
structure ProofGeneralPgip : PROOF_GENERAL_PGIP  =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    19
struct
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    20
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    21
open Pgip;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    22
21949
046e0482f0a1 removed obsolete context_thy etc.;
wenzelm
parents: 21940
diff changeset
    23
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    24
(* print modes *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    25
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    26
val proof_generalN = "ProofGeneral";  (*token markup (colouring vars, etc.)*)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    27
val pgmlN = "PGML";                   (*XML escapes and PGML symbol elements*)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    28
val pgmlatomsN = "PGMLatoms";         (*variable kind decorations*)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    29
val thm_depsN = "thm_deps";           (*meta-information about theorem deps*)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    30
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    31
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    32
(* text output: print modes for xsymbol and PGML *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    33
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    34
local
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    35
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    36
fun xsym_output "\\" = "\\\\"
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    37
  | xsym_output s = if Symbol.is_raw s then Symbol.decode_raw s else s;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    38
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    39
fun xsymbols_output s =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
    40
  if Output.has_mode Symbol.xsymbolsN andalso exists_string (equal "\\") s then
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    41
    let val syms = Symbol.explode s
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    42
    in (implode (map xsym_output syms), real (Symbol.length syms)) end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    43
  else Symbol.default_output s;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    44
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    45
(* XML immediately rendered pretty printer. Take care not to double escape *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    46
fun pgml_sym s =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    47
  (case Symbol.decode s of
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    48
    Symbol.Char s => XML.text s
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
    49
  | Symbol.Sym sn => XML.element "sym" [("name", sn)] [XML.text s]
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    50
  | Symbol.Ctrl sn => XML.element "ctrl" [("name", sn)] [XML.text s] (* FIXME: no such PGML! *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    51
  | Symbol.Raw s => s);
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    52
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    53
fun pgml_output str =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    54
  let val syms = Symbol.explode str
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    55
  in (implode (map pgml_sym syms), real (Symbol.length syms)) end;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    56
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    57
in
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    58
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    59
fun setup_xsymbols_output () =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
    60
  Output.add_mode Symbol.xsymbolsN
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    61
    (xsymbols_output, K xsymbols_output, Symbol.default_indent, Symbol.encode_raw);
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    62
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    63
fun setup_pgml_output () =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    64
  Output.add_mode pgmlN
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    65
    (pgml_output, K pgml_output, Symbol.default_indent, Symbol.encode_raw);
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    66
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    67
end;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    68
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    69
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    70
(* token translations *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    71
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    72
local
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    73
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    74
val class_tag = "class"
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    75
val tfree_tag = "tfree"
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    76
val tvar_tag = "tvar"
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    77
val free_tag = "free"
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    78
val bound_tag = "bound"
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    79
val var_tag = "var"
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    80
val skolem_tag = "skolem"
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    81
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    82
fun xml_atom kind x = XML.element "atom" [("kind", kind)] [XML.text x];
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    83
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
    84
fun tagit kind x =
21949
046e0482f0a1 removed obsolete context_thy etc.;
wenzelm
parents: 21940
diff changeset
    85
  (xml_atom kind x, real (Symbol.length (Symbol.explode x)));
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    86
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    87
fun free_or_skolem x =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    88
  (case try Name.dest_skolem x of
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    89
    NONE => tagit free_tag x
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    90
  | SOME x' => tagit skolem_tag x');
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    91
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    92
fun var_or_skolem s =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    93
  (case Syntax.read_variable s of
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    94
    SOME (x, i) =>
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    95
      (case try Name.dest_skolem x of
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    96
        NONE => tagit var_tag s
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    97
      | SOME x' => tagit skolem_tag
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    98
          (setmp show_question_marks true Syntax.string_of_vname (x', i)))
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    99
  | NONE => tagit var_tag s);
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   100
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   101
val proof_general_trans =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   102
 Syntax.tokentrans_mode proof_generalN
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   103
  [("class", tagit class_tag),
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   104
   ("tfree", tagit tfree_tag),
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   105
   ("tvar", tagit tvar_tag),
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   106
   ("free", free_or_skolem),
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   107
   ("bound", tagit bound_tag),
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   108
   ("var", var_or_skolem)];
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   109
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   110
in
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   111
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   112
val _ = Context.add_setup (Theory.add_tokentrfuns proof_general_trans);
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   113
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   114
end;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   115
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   116
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   117
(** assembling and issuing PGIP packets **)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   118
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   119
val pgip_refid  = ref NONE: string option ref;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   120
val pgip_refseq = ref NONE: int option ref;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   121
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   122
local
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   123
  val pgip_class  = "pg"
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   124
  val pgip_tag = "Isabelle/Isar"
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   125
  val pgip_id = ref ""
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   126
  val pgip_seq = ref 0
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   127
  fun pgip_serial () = inc pgip_seq
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   128
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   129
  fun assemble_pgips pgips =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   130
    Pgip { tag = SOME pgip_tag,
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   131
           class = pgip_class,
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   132
           seq = pgip_serial(),
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   133
           id = !pgip_id,
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   134
           destid = !pgip_refid,
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   135
           (* destid=refid since Isabelle only communicates back to sender *)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   136
           refid  = !pgip_refid,
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   137
           refseq = !pgip_refseq,
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   138
           content = pgips }
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   139
in
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   140
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   141
fun init_pgip_session_id () =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   142
    pgip_id := getenv "HOSTNAME" ^ "/" ^ getenv "USER" ^ "/" ^
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   143
               getenv "ISABELLE_PID" ^ "/" ^ Time.toString (Time.now ())
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   144
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   145
fun matching_pgip_id id = (id = !pgip_id)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   146
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   147
val output_xml_fn = ref writeln_default
21649
40e6fdd26f82 Support PGIP communication for preferences in Emacs mode.
aspinall
parents: 21646
diff changeset
   148
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
   149
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   150
fun issue_pgip_rawtext str =
21649
40e6fdd26f82 Support PGIP communication for preferences in Emacs mode.
aspinall
parents: 21646
diff changeset
   151
    output_xml (PgipOutput.output (assemble_pgips [XML.Rawtext str]))
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   152
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   153
fun issue_pgips pgipops =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   154
    output_xml (PgipOutput.output (assemble_pgips (map PgipOutput.output pgipops)));
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   155
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   156
fun issue_pgip pgipop =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   157
    output_xml (PgipOutput.output (assemble_pgips [PgipOutput.output pgipop]));
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   158
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   159
end;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   160
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   161
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   162
(** messages and notification **)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   163
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   164
local
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   165
    val delay_msgs = ref false   (*true: accumulate messages*)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   166
    val delayed_msgs = ref []
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   167
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   168
    fun queue_or_issue pgip =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   169
        if ! delay_msgs then
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   170
            delayed_msgs := pgip :: ! delayed_msgs
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   171
        else issue_pgip pgip
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   172
in
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   173
    fun normalmsg area cat urgent s =
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   174
        let
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   175
            val content = XML.Elem("pgmltext",[],[XML.Rawtext s])
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   176
            val pgip = Normalresponse {area=area,messagecategory=cat,
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   177
                                       urgent=urgent,content=[content] }
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   178
        in
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   179
            queue_or_issue pgip
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   180
        end
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   181
21885
5a11263bd8cf Remove obsolete prefixes from error and warning messages.
aspinall
parents: 21867
diff changeset
   182
    fun errormsg fatality s =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   183
        let
21885
5a11263bd8cf Remove obsolete prefixes from error and warning messages.
aspinall
parents: 21867
diff changeset
   184
              val content = XML.Elem("pgmltext",[],[XML.Rawtext s])
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   185
              val pgip = Errorresponse {area=NONE,fatality=fatality,
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   186
                                        content=[content],
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   187
                                        (* FIXME: pass in locations *)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   188
                                        location=NONE}
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   189
        in
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   190
            queue_or_issue pgip
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   191
        end
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   192
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   193
    fun start_delay_msgs () = (set delay_msgs; delayed_msgs := [])
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   194
    fun end_delayed_msgs () = (reset delay_msgs; ! delayed_msgs)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   195
end;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   196
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   197
(* NB: all of the standard error/message functions now expect already-escaped text.
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   198
   FIXME: this may cause us problems now we're generating trees; on the other
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   199
   hand the output functions were tuned some time ago, so it ought to be
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   200
   enough to use Rawtext always above. *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   201
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   202
fun setup_messages () =
21885
5a11263bd8cf Remove obsolete prefixes from error and warning messages.
aspinall
parents: 21867
diff changeset
   203
 (writeln_fn := (fn s => normalmsg Message Normal false s);
5a11263bd8cf Remove obsolete prefixes from error and warning messages.
aspinall
parents: 21867
diff changeset
   204
  priority_fn := (fn s => normalmsg Message Normal true s);
5a11263bd8cf Remove obsolete prefixes from error and warning messages.
aspinall
parents: 21867
diff changeset
   205
  tracing_fn := (fn s => normalmsg  Message Tracing false s);
5a11263bd8cf Remove obsolete prefixes from error and warning messages.
aspinall
parents: 21867
diff changeset
   206
  info_fn := (fn s => normalmsg Message Information false s);
5a11263bd8cf Remove obsolete prefixes from error and warning messages.
aspinall
parents: 21867
diff changeset
   207
  debug_fn := (fn s => normalmsg Message Internal false s);
5a11263bd8cf Remove obsolete prefixes from error and warning messages.
aspinall
parents: 21867
diff changeset
   208
  warning_fn := (fn s => errormsg Nonfatal s);
5a11263bd8cf Remove obsolete prefixes from error and warning messages.
aspinall
parents: 21867
diff changeset
   209
  error_fn := (fn s => errormsg Fatal s);
5a11263bd8cf Remove obsolete prefixes from error and warning messages.
aspinall
parents: 21867
diff changeset
   210
  panic_fn := (fn s => errormsg Panic s))
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   211
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   212
(* immediate messages *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   213
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   214
fun tell_clear_goals ()      = issue_pgip (Cleardisplay {area=Display})
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   215
fun tell_clear_response ()   = issue_pgip (Cleardisplay {area=Message})
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   216
fun tell_file_loaded path    = issue_pgip (Informfileloaded {url=PgipTypes.pgipurl_of_path path})
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   217
fun tell_file_retracted path = issue_pgip (Informfileretracted {url=PgipTypes.pgipurl_of_path path})
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   218
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   219
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   220
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   221
(** theory / proof state output **)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   222
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   223
local
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   224
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   225
fun statedisplay prts =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   226
    let
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   227
        val display = Pretty.output (Pretty.chunks prts)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   228
        val statedisplay = XML.Elem("statedisplay",[], [XML.Rawtext display])
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   229
    in
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   230
        issue_pgip (Proofstate {pgml=[XML.Elem("pgml",[],[statedisplay])]})
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   231
    end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   232
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   233
fun print_current_goals n m st =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   234
  statedisplay (Display.pretty_current_goals n m st)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   235
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   236
fun print_state b st =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   237
  statedisplay (Toplevel.pretty_state b st)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   238
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   239
in
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   240
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   241
fun setup_state () =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   242
  (Display.print_current_goals_fn := print_current_goals;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   243
   Toplevel.print_state_fn := print_state);
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   244
      (*    Toplevel.prompt_state_fn := (fn s => suffix (special "372")
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   245
                                        (Toplevel.prompt_state_default s))); *)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   246
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   247
end;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   248
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   249
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   250
(* theory loader actions *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   251
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   252
local
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   253
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   254
fun trace_action action name =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   255
  if action = ThyInfo.Update then
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   256
    List.app tell_file_loaded (ThyInfo.loaded_files name)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   257
  else if action = ThyInfo.Outdate orelse action = ThyInfo.Remove then
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   258
    List.app tell_file_retracted (ThyInfo.loaded_files name)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   259
  else ();
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   260
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   261
in
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   262
  fun setup_thy_loader () = ThyInfo.add_hook trace_action;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   263
  fun sync_thy_loader () = List.app (trace_action ThyInfo.Update) (ThyInfo.names ());
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   264
end;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   265
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   266
21949
046e0482f0a1 removed obsolete context_thy etc.;
wenzelm
parents: 21940
diff changeset
   267
(* get informed about files *)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   268
21858
05f57309170c avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
wenzelm
parents: 21655
diff changeset
   269
val thy_name = Path.implode o #1 o Path.split_ext o Path.base o Path.explode;
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   270
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   271
val inform_file_retracted = ThyInfo.if_known_thy ThyInfo.remove_thy o thy_name;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   272
val inform_file_processed = ThyInfo.if_known_thy ThyInfo.touch_child_thys o thy_name;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   273
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   274
fun proper_inform_file_processed file state =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   275
  let val name = thy_name file in
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   276
    if Toplevel.is_toplevel state andalso ThyInfo.known_thy name then
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   277
     (ThyInfo.touch_child_thys name;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   278
      ThyInfo.pretend_use_thy_only name handle ERROR msg =>
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   279
       (warning msg; warning ("Failed to register theory: " ^ quote name);
21858
05f57309170c avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
wenzelm
parents: 21655
diff changeset
   280
        tell_file_retracted (Path.base (Path.explode file))))
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   281
    else raise Toplevel.UNDEF
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   282
  end;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   283
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   284
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   285
(* restart top-level loop (keeps most state information) *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   286
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   287
val welcome = priority o Session.welcome;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   288
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   289
fun restart () =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   290
    (sync_thy_loader ();
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   291
     tell_clear_goals ();
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   292
     tell_clear_response ();
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   293
     welcome ();
21655
01b2d13153c8 Document structure in pgip_markup.ML. Minor fixes.
aspinall
parents: 21649
diff changeset
   294
     priority "Running new version of PGIP code.  In testing.";
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   295
     raise Toplevel.RESTART)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   296
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   297
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   298
(* theorem dependency output *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   299
local
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   300
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   301
val spaces_quote = space_implode " " o map quote;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   302
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   303
fun thm_deps_message (thms, deps) =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   304
    let
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   305
        val valuethms = XML.Elem("value",[("name", "thms")],[XML.Text thms])
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   306
        val valuedeps = XML.Elem("value",[("name", "deps")],[XML.Text deps])
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   307
    in
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   308
        issue_pgip (Metainforesponse {attrs=[("infotype", "isabelle_theorem_dependencies")],
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   309
                                      content=[valuethms,valuedeps]})
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   310
    end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   311
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   312
(* FIXME: check this uses non-transitive closure function here *)
21969
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   313
fun tell_thm_deps ths =
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   314
  if Output.has_mode thm_depsN then
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   315
    let
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   316
      val names = filter_out (equal "") (map PureThy.get_name_hint ths);
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   317
      val deps = filter_out (equal "")
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   318
        (Symtab.keys (fold Proofterm.thms_of_proof
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   319
          (map Thm.proof_of ths) Symtab.empty));
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   320
    in
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   321
      if null names orelse null deps then ()
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   322
      else thm_deps_message (spaces_quote names, spaces_quote deps)
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   323
    end
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   324
  else ();
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   325
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   326
in
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   327
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   328
fun setup_present_hook () =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   329
  Present.add_hook (fn _ => fn res => tell_thm_deps (maps #2 res));
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   330
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   331
end;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   332
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   333
(** lexicalstructure element with keywords (PGIP version of elisp keywords file) **)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   334
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   335
fun lexicalstructure_keywords () =
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   336
    let val commands = OuterSyntax.dest_keywords ()
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   337
        fun category_of k = if k mem commands then "major" else "minor"
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   338
         (* NB: we might filter to only include words like elisp case (OuterSyntax.is_keyword). *)
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   339
        fun keyword_elt (keyword,help,kind,_) =
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   340
            XML.Elem("keyword", [("word", keyword), ("category", category_of kind)],
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   341
                     [XML.Elem("shorthelp", [], [XML.Text help])])
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   342
        in
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   343
            (* Also, note we don't call init_outer_syntax here to add interface commands,
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   344
            but they should never appear in scripts anyway so it shouldn't matter *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   345
            Lexicalstructure {content = map keyword_elt (OuterSyntax.dest_parsers()) }
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   346
        end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   347
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   348
(* TODO: we can issue a lexicalstructure/keyword when the syntax gets extended dynamically;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   349
   hooks needed in outer_syntax.ML to do that. *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   350
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   351
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   352
(* Configuration: GUI config, proverinfo messages *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   353
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   354
local
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   355
    val isabellewww = "http://isabelle.in.tum.de/"
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   356
    val staticconfig = "~~/lib/ProofGeneral/pgip_isar.xml"
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   357
    fun orenv v d = case getenv v of "" => d  | s => s
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   358
    fun config_file()  = orenv "ISABELLE_PGIPCONFIG" staticconfig
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   359
    fun isabelle_www() = orenv "ISABELLE_HOMEPAGE" isabellewww
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   360
in
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   361
fun send_pgip_config () =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   362
    let
21858
05f57309170c avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
wenzelm
parents: 21655
diff changeset
   363
        val path = Path.explode (config_file())
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   364
        val ex = File.exists path
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   365
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   366
        val wwwpage =
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   367
            (Url.explode (isabelle_www()))
21969
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   368
            handle ERROR _ =>
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   369
                   (Output.panic
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   370
                        ("Error in URL in environment variable ISABELLE_HOMEPAGE.");
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   371
                        Url.explode isabellewww)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   372
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   373
        val proverinfo =
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   374
            Proverinfo { name = "Isabelle",
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   375
                         version = version,
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   376
                         instance = Session.name(),
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   377
                         descr = "The Isabelle/Isar theorem prover",
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   378
                         url = wwwpage,
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   379
                         filenameextns = ".thy;" }
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   380
    in
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   381
        if ex then
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   382
            (issue_pgip proverinfo;
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   383
             issue_pgip_rawtext (File.read path);
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   384
             issue_pgip (lexicalstructure_keywords()))
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   385
        else Output.panic ("PGIP configuration file \"" ^ config_file() ^ "\" not found")
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   386
    end;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   387
end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   388
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   389
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   390
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   391
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   392
(* Sending commands to Isar *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   393
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   394
fun isarcmd s =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   395
    s |> OuterSyntax.scan |> OuterSyntax.read
21885
5a11263bd8cf Remove obsolete prefixes from error and warning messages.
aspinall
parents: 21867
diff changeset
   396
      (*|> map (Toplevel.position (Position.name "PGIP message") o #3)*)
5a11263bd8cf Remove obsolete prefixes from error and warning messages.
aspinall
parents: 21867
diff changeset
   397
      |> map #3
5a11263bd8cf Remove obsolete prefixes from error and warning messages.
aspinall
parents: 21867
diff changeset
   398
      |> Toplevel.>>>;
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   399
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   400
(* TODO:
21885
5a11263bd8cf Remove obsolete prefixes from error and warning messages.
aspinall
parents: 21867
diff changeset
   401
    - 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
   402
    - 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
   403
*)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   404
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   405
(* load an arbitrary file (must be .thy or .ML) *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   406
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   407
fun use_thy_or_ml_file file =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   408
    let
21858
05f57309170c avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
wenzelm
parents: 21655
diff changeset
   409
        val (path,extn) = Path.split_ext (Path.explode file)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   410
    in
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   411
        case extn of
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   412
            "" => isarcmd ("use_thy " ^ quote (Path.implode path))
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   413
          | "thy" => isarcmd ("use_thy " ^ quote (Path.implode path))
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   414
          | "ML" => isarcmd ("use " ^ quote file)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   415
          | other => error ("Don't know how to read a file with extension " ^ other)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   416
    end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   417
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   418
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   419
(******* PGIP actions *******)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   420
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   421
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   422
(* Responses to each of the PGIP input commands.
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   423
   These are programmed uniformly for extensibility. *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   424
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   425
fun askpgip (Askpgip vs) =
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   426
    issue_pgip
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   427
        (Usespgip { version = PgipIsabelle.isabelle_pgip_version_supported,
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   428
                    pgipelems = PgipIsabelle.accepted_inputs })
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   429
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   430
fun askpgml (Askpgml vs) =
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   431
    issue_pgip
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   432
        (Usespgml { version = PgipIsabelle.isabelle_pgml_version_supported })
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   433
21902
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   434
fun askprefs (Askprefs vs) =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   435
    let
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   436
        fun preference_of {name, descr, default, pgiptype, get, set } =
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   437
            { name = name, descr = SOME descr, default = SOME default,
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   438
              pgiptype = pgiptype }
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   439
    in
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   440
        List.app (fn (prefcat, prefs) =>
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   441
                     issue_pgip (Hasprefs {prefcategory=SOME prefcat,
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   442
                                           prefs=map preference_of prefs}))
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   443
                 Preferences.preferences
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   444
    end
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   445
21902
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   446
fun askconfig (Askconfig vs) = () (* TODO: add config response *)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   447
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   448
local
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   449
    fun lookuppref pref =
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   450
        case AList.lookup (op =)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   451
                          (map (fn p => (#name p,p))
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   452
                               (maps snd Preferences.preferences)) pref of
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   453
            NONE => error ("Unknown prover preference: " ^ quote pref)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   454
          | SOME p => p
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   455
in
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   456
fun setpref (Setpref vs) =
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   457
    let
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   458
        val name = #name vs
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   459
        val value = #value vs
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   460
        val set = #set (lookuppref name)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   461
    in
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   462
        set value
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   463
    end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   464
21902
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   465
fun getpref (Getpref vs) =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   466
    let
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   467
        val name = #name vs
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   468
        val get = #get (lookuppref name)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   469
    in
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   470
        issue_pgip (Prefval {name=name, value=get ()})
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   471
    end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   472
end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   473
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   474
fun proverinit vs = restart ()
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   475
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   476
fun proverexit vs = isarcmd "quit"
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   477
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   478
fun startquiet vs = isarcmd "disable_pr"
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   479
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   480
fun stopquiet vs = isarcmd "enable_pr"
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   481
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   482
fun pgmlsymbolson vs =
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   483
    change print_mode (fn mode =>
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   484
                          remove (op =) Symbol.xsymbolsN mode @ [Symbol.xsymbolsN])
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   485
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   486
fun pgmlsymbolsoff vs =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   487
    change print_mode (remove (op =) Symbol.xsymbolsN)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   488
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   489
fun dostep (Dostep vs) =
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   490
    let
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   491
        val text = #text vs
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   492
    in
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   493
        isarcmd text
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   494
    end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   495
21902
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   496
fun undostep (Undostep vs) =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   497
    let
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   498
        val times = #times vs
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   499
    in
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   500
        isarcmd ("undos_proof " ^ Int.toString times)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   501
    end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   502
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   503
fun redostep vs = isarcmd "redo"
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   504
21972
1b68312c4cf0 Initialise parser at startup. Remove some obsolete ProofGeneral.XXX outer syntax, mapping PGIP commands directly to Isar.
aspinall
parents: 21970
diff changeset
   505
fun abortgoal vs = isarcmd "kill" (* was: ProofGeneral.kill_proof *)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   506
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   507
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   508
(*** PGIP identifier tables ***)
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   509
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   510
fun setids t = issue_pgip (Setids {idtables = [t]})
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   511
fun addids t = issue_pgip (Addids {idtables = [t]})
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   512
fun delids t = issue_pgip (Delids {idtables = [t]})
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   513
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   514
(*
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   515
 fun delallids ty =
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   516
     issue_pgip (Setids {idtables =
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   517
                        [{context=NONE,objtype=ty,ids=[]}]}) *)
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   518
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   519
fun askids (Askids vs) =
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   520
    let
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   521
        val url = #url vs            (* ask for identifiers within a file *)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   522
        val thyname = #thyname vs    (* ask for identifiers within a theory *)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   523
        val objtype = #objtype vs    (* ask for identifiers of a particular type *)
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   524
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   525
        fun idtable ty ctx ids = {objtype=ty,context=ctx,ids=ids}
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   526
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   527
        val thms_of_thy = map fst o PureThy.thms_of o ThyInfo.get_theory
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   528
    in
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   529
(*      case (url_attr,thyname,objtype) of
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   530
            (NONE,NONE,NONE) =>
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   531
*)          (* top-level: return *)
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   532
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   533
        (* TODO: add askids for "file" here, which returns single theory with same name *)
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   534
        (* FIXME: objtypes on both sides *)
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   535
        case (thyname,objtype) of
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   536
           (* only files known in top context *)
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   537
           (NONE, NONE)               => setids (idtable ObjFile NONE (ThyInfo.names())) (*FIXME: uris?*)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   538
         | (NONE, SOME ObjFile)        => setids (idtable ObjFile NONE (ThyInfo.names())) (* ditto *)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   539
         | (SOME fi, SOME ObjFile)     => setids (idtable ObjTheory (SOME fi) [fi]) (* FIXME: lookup file *)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   540
         | (NONE, SOME ObjTheory)      => setids (idtable ObjTheory NONE (ThyInfo.names()))
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   541
         | (SOME thy, SOME ObjTheory)  => setids (idtable ObjTheory (SOME thy) (ThyInfo.get_preds thy))
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   542
         | (SOME thy, SOME ObjTheorem) => setids (idtable ObjTheorem (SOME thy) (thms_of_thy thy))
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   543
         (* next case is both of above.  FIXME: cleanup this *)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   544
         | (SOME thy, NONE) => (setids (idtable ObjTheory (SOME thy) (ThyInfo.get_preds thy));
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   545
                                setids (idtable ObjTheorem (SOME thy) (thms_of_thy thy)))
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   546
         | (_, SOME ot) => error ("No objects of type "^(PgipTypes.name_of_objtype ot)^" are available here.")
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   547
    end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   548
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   549
local
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   550
  (* accumulate printed output in a single PGIP response (inside <pgmltext>) *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   551
  fun with_displaywrap pgipfn dispfn =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   552
      let
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   553
          val lines = ref ([]: string list);
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   554
          fun wlgrablines s = lines := s :: ! lines;
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   555
      in
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   556
          setmp writeln_fn wlgrablines dispfn ();
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   557
          issue_pgip (pgipfn (!lines))
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   558
      end;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   559
in
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   560
fun showid (Showid vs) =
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   561
    let
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   562
        val thyname = #thyname vs
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   563
        val objtype = #objtype vs
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   564
        val name = #name vs
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   565
        val topthy = Toplevel.theory_of o Toplevel.get_state
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   566
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   567
        fun idvalue objtype name strings =
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   568
            Idvalue { name=name, objtype=objtype,
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   569
                      text=[XML.Elem("pgmltext",[],map XML.Text strings)] }
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   570
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   571
        fun pthm thy name = print_thm (get_thm thy (Name name))
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   572
    in
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   573
        case (thyname, objtype) of
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   574
            (_,ObjTheory) =>
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   575
            with_displaywrap (idvalue ObjTheory name)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   576
                             (fn ()=>(print_theory (ThyInfo.get_theory name)))
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   577
          | (SOME thy, ObjTheorem) =>
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   578
            with_displaywrap (idvalue ObjTheorem name)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   579
                             (fn ()=>(pthm (ThyInfo.get_theory thy) name))
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   580
          | (NONE, ObjTheorem) =>
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   581
            with_displaywrap (idvalue ObjTheorem name)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   582
                             (fn ()=>pthm (topthy()) name)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   583
          | (_, ot) => error ("Cannot show objects of type "^(PgipTypes.name_of_objtype ot))
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   584
    end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   585
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   586
(*** Inspecting state ***)
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   587
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   588
(* The file which is currently being processed interactively.
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   589
   In the pre-PGIP code, this was informed to Isabelle and the theory loader
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   590
   on completion, but that allows for circularity in case we read
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   591
   ourselves.  So PGIP opens the filename at the start of a script.
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   592
   We ought to prevent problems by modifying the theory loader to know
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   593
   about this special status, but for now we just keep a local reference.
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   594
*)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   595
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   596
val currently_open_file = ref (NONE : pgipurl option)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   597
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   598
fun askguise vs =
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   599
    (* The "guise" is the PGIP abstraction of the prover's state.
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   600
       The <informguise> message is merely used for consistency checking. *)
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   601
    let
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   602
        val openfile = !currently_open_file
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   603
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   604
        val topthy = Toplevel.theory_of o Toplevel.get_state
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   605
        val topthy_name = Context.theory_name o topthy
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   606
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   607
        val opentheory = SOME (topthy_name()) handle Toplevel.UNDEF => NONE
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   608
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   609
        fun topproofpos () = try Toplevel.proof_position_of (Isar.state ());
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   610
        val openproofpos = topproofpos()
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   611
    in
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   612
        issue_pgip (Informguise { file = openfile,
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   613
                                  theory = opentheory,
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   614
                                  (* would be nice to get thm name... *)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   615
                                  theorem = NONE,
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   616
                                  proofpos = openproofpos })
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   617
    end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   618
21902
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   619
fun parsescript (Parsescript vs) =
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   620
    let
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   621
        val text = #text vs
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   622
        val systemdata = #systemdata vs
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   623
        val location = #location vs   (* TODO: extract position *)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   624
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   625
        val _ = start_delay_msgs ()   (* gather parsing errs/warns *)
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   626
        val doc = PgipParser.pgip_parser text
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   627
        val errs = end_delayed_msgs ()
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   628
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   629
        val sysattrs = PgipTypes.opt_attr "systemdata" systemdata
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   630
        val locattrs = PgipTypes.attrs_of_location location
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   631
     in
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   632
        issue_pgip (Parseresult { attrs= sysattrs@locattrs,
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   633
                                  doc = doc,
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   634
                                  errs = map PgipOutput.output errs })
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   635
    end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   636
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   637
fun showproofstate vs = isarcmd "pr"
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   638
21969
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   639
fun showctxt vs = isarcmd "print_context"
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   640
21902
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   641
fun searchtheorems (Searchtheorems vs) =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   642
    let
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   643
        val arg = #arg vs
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   644
    in
21969
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   645
        isarcmd ("find_theorems " ^ arg)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   646
    end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   647
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   648
fun setlinewidth (Setlinewidth vs) =
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   649
    let
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   650
        val width = #width vs
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   651
    in
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   652
        isarcmd ("pretty_setmargin " ^ Int.toString width) (* FIXME: conversion back/forth! *)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   653
    end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   654
21902
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   655
fun viewdoc (Viewdoc vs) =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   656
    let
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   657
        val arg = #arg vs
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   658
    in
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   659
        isarcmd ("print_" ^ arg)   (* FIXME: isatool doc?.  Return URLs, maybe? *)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   660
    end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   661
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   662
(*** Theory ***)
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   663
21902
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   664
fun doitem (Doitem vs) =
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   665
    let
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   666
        val text = #text vs
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   667
    in
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   668
        isarcmd text
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   669
    end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   670
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   671
fun undoitem vs =
21972
1b68312c4cf0 Initialise parser at startup. Remove some obsolete ProofGeneral.XXX outer syntax, mapping PGIP commands directly to Isar.
aspinall
parents: 21970
diff changeset
   672
    isarcmd "undo"
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   673
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   674
fun redoitem vs =
21972
1b68312c4cf0 Initialise parser at startup. Remove some obsolete ProofGeneral.XXX outer syntax, mapping PGIP commands directly to Isar.
aspinall
parents: 21970
diff changeset
   675
    isarcmd "redo"
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   676
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   677
fun aborttheory vs =
21972
1b68312c4cf0 Initialise parser at startup. Remove some obsolete ProofGeneral.XXX outer syntax, mapping PGIP commands directly to Isar.
aspinall
parents: 21970
diff changeset
   678
    isarcmd "kill"  (* was: "init_toplevel" *)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   679
21902
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   680
fun retracttheory (Retracttheory vs) =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   681
    let
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   682
        val thyname = #thyname vs
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   683
    in
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   684
        isarcmd ("kill_thy " ^ quote thyname)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   685
    end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   686
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   687
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   688
(*** Files ***)
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   689
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   690
(* Path management: we allow theory files to have dependencies in
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   691
   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
   692
   remove the path.  Leaving it there can cause confusion with
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   693
   difference in batch mode.
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   694
   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
   695
*)
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   696
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   697
local
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   698
    val current_working_dir = ref (NONE : string option)
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   699
in
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   700
fun changecwd_dir newdirpath =
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   701
   let
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   702
       val newdir = File.platform_path newdirpath
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   703
   in
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   704
       (case (!current_working_dir) of
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   705
            NONE => ()
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   706
          | SOME dir => ThyLoad.del_path dir;
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   707
        ThyLoad.add_path newdir;
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   708
        current_working_dir := SOME newdir)
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   709
   end
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   710
end
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   711
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   712
fun changecwd (Changecwd vs) =
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   713
    let
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   714
        val url = #url vs
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   715
        val newdir = PgipTypes.path_of_pgipurl url
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   716
    in
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   717
        changecwd_dir url
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   718
    end
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   719
21902
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   720
fun openfile (Openfile vs) =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   721
  let
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   722
      val url = #url vs
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   723
      val filepath = PgipTypes.path_of_pgipurl url
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   724
      val filedir = Path.dir filepath
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   725
      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
   726
      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
   727
  in
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   728
      case !currently_open_file of
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   729
          SOME f => raise PGIP ("<openfile> when a file is already open! ")
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   730
        | NONE => (openfile_retract filepath;
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   731
                   changecwd_dir filedir;
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   732
                   currently_open_file := SOME url)
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   733
  end
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   734
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   735
fun closefile vs =
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   736
    case !currently_open_file of
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   737
        SOME f => (proper_inform_file_processed (File.platform_path f)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   738
                                                (Isar.state());
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   739
                   currently_open_file := NONE)
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   740
      | NONE => raise PGIP ("<closefile> when no file is open!")
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   741
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   742
fun loadfile (Loadfile vs) =
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   743
    let
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   744
        val url = #url vs
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   745
    in
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   746
        case !currently_open_file of
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   747
            SOME f => raise PGIP ("<loadfile> when a file is open!")
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   748
          | NONE => use_thy_or_ml_file (File.platform_path url)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   749
    end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   750
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   751
fun abortfile vs =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   752
    case !currently_open_file of
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   753
        SOME f => (isarcmd "init_toplevel";
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   754
                   currently_open_file := NONE)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   755
      | NONE => raise PGIP ("<abortfile> when no file is open!")
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   756
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   757
fun retractfile (Retractfile vs) =
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   758
    let
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   759
        val url = #url vs
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   760
    in
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   761
        case !currently_open_file of
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   762
            SOME f => raise PGIP ("<retractfile> when a file is open!")
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   763
          | NONE => inform_file_retracted (File.platform_path url)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   764
    end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   765
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   766
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   767
(*** System ***)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   768
21902
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   769
fun systemcmd (Systemcmd vs) =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   770
  let
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   771
      val arg = #arg vs
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   772
  in
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   773
      isarcmd arg
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   774
  end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   775
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   776
exception PGIP_QUIT;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   777
fun quitpgip vs = raise PGIP_QUIT
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   778
21902
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   779
fun process_input inp = case inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   780
 of Pgip.Askpgip _          => askpgip inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   781
  | Pgip.Askpgml _          => askpgml inp
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   782
  | Pgip.Askprefs _         => askprefs inp
21902
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   783
  | Pgip.Askconfig _        => askconfig inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   784
  | Pgip.Getpref _          => getpref inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   785
  | Pgip.Setpref _          => setpref inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   786
  | Pgip.Proverinit _       => proverinit inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   787
  | Pgip.Proverexit _       => proverexit inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   788
  | Pgip.Startquiet _       => startquiet inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   789
  | Pgip.Stopquiet _        => stopquiet inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   790
  | Pgip.Pgmlsymbolson _    => pgmlsymbolson inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   791
  | Pgip.Pgmlsymbolsoff _   => pgmlsymbolsoff inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   792
  | Pgip.Dostep _           => dostep inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   793
  | Pgip.Undostep _         => undostep inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   794
  | Pgip.Redostep _         => redostep inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   795
  | Pgip.Forget _           => error "<forget> not implemented"
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   796
  | Pgip.Restoregoal _      => error "<restoregoal> not implemented"
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   797
  | Pgip.Abortgoal _        => abortgoal inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   798
  | Pgip.Askids _           => askids inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   799
  | Pgip.Showid _           => showid inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   800
  | Pgip.Askguise _         => askguise inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   801
  | Pgip.Parsescript _      => parsescript inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   802
  | Pgip.Showproofstate _   => showproofstate inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   803
  | Pgip.Showctxt _         => showctxt inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   804
  | Pgip.Searchtheorems _   => searchtheorems inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   805
  | Pgip.Setlinewidth _     => setlinewidth inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   806
  | Pgip.Viewdoc _          => viewdoc inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   807
  | Pgip.Doitem _           => doitem inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   808
  | Pgip.Undoitem _         => undoitem inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   809
  | Pgip.Redoitem _         => redoitem inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   810
  | Pgip.Aborttheory _      => aborttheory inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   811
  | Pgip.Retracttheory _    => retracttheory inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   812
  | Pgip.Loadfile _         => loadfile inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   813
  | Pgip.Openfile _         => openfile inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   814
  | Pgip.Closefile _        => closefile inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   815
  | Pgip.Abortfile _        => abortfile inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   816
  | Pgip.Retractfile _      => retractfile inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   817
  | Pgip.Changecwd _        => changecwd inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   818
  | Pgip.Systemcmd _        => systemcmd inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   819
  | Pgip.Quitpgip _         => quitpgip inp
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   820
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   821
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   822
fun process_pgip_element pgipxml =
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   823
    case pgipxml of
21969
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   824
        xml as (XML.Elem elem) =>
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   825
        (case Pgip.input elem of
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   826
             NONE => warning ("Unrecognized PGIP command, ignored: \n" ^
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   827
                              (XML.string_of_tree xml))
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   828
           | SOME inp => (process_input inp)) (* errors later; packet discarded *)
21969
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   829
      | XML.Text t => ignored_text_warning t
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   830
      | XML.Rawtext t => ignored_text_warning t
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   831
and ignored_text_warning t =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   832
    if size (Symbol.strip_blanks t) > 0 then
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   833
           warning ("Ignored text in PGIP packet: \n" ^ t)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   834
    else ()
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   835
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   836
fun process_pgip_tree xml =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   837
    (pgip_refid := NONE;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   838
     pgip_refseq := NONE;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   839
     (case xml of
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   840
          XML.Elem ("pgip", attrs, pgips) =>
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   841
          (let
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   842
               val class = PgipTypes.get_attr "class" attrs
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   843
               val dest  = PgipTypes.get_attr_opt "destid" attrs
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   844
               val seq = PgipTypes.read_pgipnat (PgipTypes.get_attr "seq" attrs)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   845
               (* Respond to prover broadcasts, or messages for us. Ignore rest *)
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   846
               val processit =
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   847
                   case dest of
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   848
                       NONE =>    class = "pa"
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   849
                     | SOME id => matching_pgip_id id
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   850
           in if processit then
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   851
                  (pgip_refid :=  PgipTypes.get_attr_opt "id" attrs;
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   852
                   pgip_refseq := SOME seq;
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   853
                   List.app process_pgip_element pgips;
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   854
                   (* return true to indicate <ready/> *)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   855
                   true)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   856
              else
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   857
                  (* no response to ignored messages. *)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   858
                  false
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   859
           end)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   860
        | _ => raise PGIP "Invalid PGIP packet received")
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   861
     handle PGIP msg =>
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   862
            (Output.error_msg ((msg ^ "\nPGIP error occured in XML text below:\n") ^
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   863
                               (XML.string_of_tree xml));
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   864
             true))
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   865
21649
40e6fdd26f82 Support PGIP communication for preferences in Emacs mode.
aspinall
parents: 21646
diff changeset
   866
(* External input *)
40e6fdd26f82 Support PGIP communication for preferences in Emacs mode.
aspinall
parents: 21646
diff changeset
   867
40e6fdd26f82 Support PGIP communication for preferences in Emacs mode.
aspinall
parents: 21646
diff changeset
   868
val process_pgip_plain = K () o process_pgip_tree o XML.tree_of_string
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   869
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   870
end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   871
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   872
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   873
(* PGIP loop: process PGIP input only *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   874
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   875
local
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   876
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   877
exception XML_PARSE
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   878
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   879
fun loop ready src =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   880
    let
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   881
        val _ = if ready then issue_pgip (Ready ()) else ()
21969
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   882
        val pgipo =
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   883
          (case try Source.get_single src of
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   884
            SOME pgipo => pgipo
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   885
          | NONE => raise XML_PARSE)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   886
    in
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   887
        case pgipo of
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   888
             NONE  => ()
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   889
           | SOME (pgip,src') =>
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   890
             let
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   891
                 val ready' = (process_pgip_tree pgip)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   892
                                handle e => (handler (e,SOME src'); true)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   893
             in
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   894
                 loop ready' src'
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   895
             end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   896
    end handle e => handler (e,SOME src)  (* error in XML parse or Ready issue *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   897
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   898
and handler (e,srco) =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   899
    case (e,srco) of
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   900
        (XML_PARSE,SOME src) =>
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   901
        Output.panic "Invalid XML input, aborting"
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   902
      | (PGIP_QUIT,_) => ()
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   903
      | (Interrupt,SOME src) =>
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   904
        (Output.error_msg "Interrupt during PGIP processing"; loop true src)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   905
      | (Toplevel.UNDEF,SOME src) =>
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   906
        (Output.error_msg "No working context defined"; loop true src)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   907
      | (e,SOME src) =>
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   908
        (Output.error_msg (Toplevel.exn_message e); loop true src)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   909
      | (_,NONE) => ()
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   910
in
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   911
  (* TODO: add socket interface *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   912
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   913
  val xmlP = XML.scan_comment_whspc |-- XML.parse_elem >> single
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   914
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   915
  val tty_src = Source.set_prompt "" (Source.source Symbol.stopper xmlP NONE Source.tty)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   916
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   917
  fun pgip_toplevel x = loop true x
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   918
end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   919
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   920
21972
1b68312c4cf0 Initialise parser at startup. Remove some obsolete ProofGeneral.XXX outer syntax, mapping PGIP commands directly to Isar.
aspinall
parents: 21970
diff changeset
   921
local
1b68312c4cf0 Initialise parser at startup. Remove some obsolete ProofGeneral.XXX outer syntax, mapping PGIP commands directly to Isar.
aspinall
parents: 21970
diff changeset
   922
(* Extra command for embedding prover-control inside document (obscure/debug usage). *)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   923
21972
1b68312c4cf0 Initialise parser at startup. Remove some obsolete ProofGeneral.XXX outer syntax, mapping PGIP commands directly to Isar.
aspinall
parents: 21970
diff changeset
   924
val process_pgipP = 
1b68312c4cf0 Initialise parser at startup. Remove some obsolete ProofGeneral.XXX outer syntax, mapping PGIP commands directly to Isar.
aspinall
parents: 21970
diff changeset
   925
  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
   926
    (OuterParse.text >> (Toplevel.no_timing oo
21649
40e6fdd26f82 Support PGIP communication for preferences in Emacs mode.
aspinall
parents: 21646
diff changeset
   927
      (fn txt => Toplevel.imperative (fn () => process_pgip_plain txt))));
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   928
21972
1b68312c4cf0 Initialise parser at startup. Remove some obsolete ProofGeneral.XXX outer syntax, mapping PGIP commands directly to Isar.
aspinall
parents: 21970
diff changeset
   929
in
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   930
21972
1b68312c4cf0 Initialise parser at startup. Remove some obsolete ProofGeneral.XXX outer syntax, mapping PGIP commands directly to Isar.
aspinall
parents: 21970
diff changeset
   931
 fun init_outer_syntax () = OuterSyntax.add_parsers [process_pgipP];
1b68312c4cf0 Initialise parser at startup. Remove some obsolete ProofGeneral.XXX outer syntax, mapping PGIP commands directly to Isar.
aspinall
parents: 21970
diff changeset
   932
1b68312c4cf0 Initialise parser at startup. Remove some obsolete ProofGeneral.XXX outer syntax, mapping PGIP commands directly to Isar.
aspinall
parents: 21970
diff changeset
   933
end
1b68312c4cf0 Initialise parser at startup. Remove some obsolete ProofGeneral.XXX outer syntax, mapping PGIP commands directly to Isar.
aspinall
parents: 21970
diff changeset
   934
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   935
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   936
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   937
(* init *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   938
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   939
val initialized = ref false;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   940
21969
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   941
fun init_pgip false =
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   942
      Output.panic "No Proof General interface support for Isabelle/classic mode."
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   943
  | init_pgip true =
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   944
      (! initialized orelse
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   945
        (setmp warning_fn (K ()) 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
   946
	  PgipParser.init ();
21969
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   947
          setup_xsymbols_output ();
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   948
          setup_pgml_output ();
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   949
          setup_messages ();
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   950
          setup_state ();
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   951
          setup_thy_loader ();
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   952
          setup_present_hook ();
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   953
          init_pgip_session_id ();
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   954
          welcome ();
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   955
          set initialized);
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   956
        sync_thy_loader ();
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   957
       change print_mode (cons proof_generalN o remove (op =) proof_generalN);
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   958
       change print_mode (append [pgmlN, pgmlatomsN] o subtract (op =) [pgmlN, pgmlatomsN]);
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   959
       pgip_toplevel tty_src);
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   960
21649
40e6fdd26f82 Support PGIP communication for preferences in Emacs mode.
aspinall
parents: 21646
diff changeset
   961
40e6fdd26f82 Support PGIP communication for preferences in Emacs mode.
aspinall
parents: 21646
diff changeset
   962
40e6fdd26f82 Support PGIP communication for preferences in Emacs mode.
aspinall
parents: 21646
diff changeset
   963
(** Out-of-loop PGIP commands (for Emacs hybrid mode) **)
40e6fdd26f82 Support PGIP communication for preferences in Emacs mode.
aspinall
parents: 21646
diff changeset
   964
40e6fdd26f82 Support PGIP communication for preferences in Emacs mode.
aspinall
parents: 21646
diff changeset
   965
local
40e6fdd26f82 Support PGIP communication for preferences in Emacs mode.
aspinall
parents: 21646
diff changeset
   966
    val pgip_output_channel = ref writeln_default
40e6fdd26f82 Support PGIP communication for preferences in Emacs mode.
aspinall
parents: 21646
diff changeset
   967
in
40e6fdd26f82 Support PGIP communication for preferences in Emacs mode.
aspinall
parents: 21646
diff changeset
   968
40e6fdd26f82 Support PGIP communication for preferences in Emacs mode.
aspinall
parents: 21646
diff changeset
   969
(* Set recipient for PGIP results *)
40e6fdd26f82 Support PGIP communication for preferences in Emacs mode.
aspinall
parents: 21646
diff changeset
   970
fun init_pgip_channel writefn =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   971
    (init_pgip_session_id();
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   972
     pgip_output_channel := writefn)
21649
40e6fdd26f82 Support PGIP communication for preferences in Emacs mode.
aspinall
parents: 21646
diff changeset
   973
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   974
(* Process a PGIP command.
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   975
   This works for preferences but not generally guaranteed
21649
40e6fdd26f82 Support PGIP communication for preferences in Emacs mode.
aspinall
parents: 21646
diff changeset
   976
   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
   977
fun process_pgip str =
40e6fdd26f82 Support PGIP communication for preferences in Emacs mode.
aspinall
parents: 21646
diff changeset
   978
     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
   979
40e6fdd26f82 Support PGIP communication for preferences in Emacs mode.
aspinall
parents: 21646
diff changeset
   980
end
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   981
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   982
end;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   983