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