src/Pure/PIDE/protocol.ML
author wenzelm
Fri Jul 05 15:38:03 2013 +0200 (2013-07-05 ago)
changeset 52530 99dd8b4ef3fe
parent 52527 dbac84eab3bc
child 52563 f9a20c2c3b70
permissions -rw-r--r--
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm@45709
     1
(*  Title:      Pure/PIDE/protocol.ML
wenzelm@38412
     2
    Author:     Makarius
wenzelm@38412
     3
wenzelm@45709
     4
Protocol message formats for interactive proof documents.
wenzelm@38412
     5
*)
wenzelm@38412
     6
wenzelm@45709
     7
structure Protocol: sig end =
wenzelm@38412
     8
struct
wenzelm@38412
     9
wenzelm@38418
    10
val _ =
wenzelm@46119
    11
  Isabelle_Process.protocol_command "Document.define_command"
wenzelm@44644
    12
    (fn [id, name, text] =>
wenzelm@52530
    13
      Document.change_state (Document.define_command (Document_ID.parse id) name text));
wenzelm@38412
    14
wenzelm@38418
    15
val _ =
wenzelm@47343
    16
  Isabelle_Process.protocol_command "Document.discontinue_execution"
wenzelm@47343
    17
    (fn [] => Document.discontinue_execution (Document.state ()));
wenzelm@47343
    18
wenzelm@47343
    19
val _ =
wenzelm@46119
    20
  Isabelle_Process.protocol_command "Document.cancel_execution"
wenzelm@47404
    21
    (fn [] => Document.cancel_execution (Document.state ()));
wenzelm@44612
    22
wenzelm@44612
    23
val _ =
wenzelm@46119
    24
  Isabelle_Process.protocol_command "Document.update"
wenzelm@44157
    25
    (fn [old_id_string, new_id_string, edits_yxml] => Document.change_state (fn state =>
wenzelm@38418
    26
      let
wenzelm@47404
    27
        val _ = Document.cancel_execution state;
wenzelm@47404
    28
wenzelm@52530
    29
        val old_id = Document_ID.parse old_id_string;
wenzelm@52530
    30
        val new_id = Document_ID.parse new_id_string;
wenzelm@44157
    31
        val edits =
wenzelm@44157
    32
          YXML.parse_body edits_yxml |>
wenzelm@44157
    33
            let open XML.Decode in
wenzelm@44157
    34
              list (pair string
wenzelm@44157
    35
                (variant
wenzelm@48755
    36
                 [fn ([], []) => Document.Clear,  (* FIXME unused !? *)
wenzelm@44157
    37
                  fn ([], a) => Document.Edits (list (pair (option int) (option int)) a),
wenzelm@44157
    38
                  fn ([], a) =>
wenzelm@46938
    39
                    let
wenzelm@51294
    40
                      val (master, (name, (imports, (keywords, errors)))) =
wenzelm@48707
    41
                        pair string (pair string (pair (list string)
wenzelm@48864
    42
                          (pair (list (pair string
wenzelm@48864
    43
                            (option (pair (pair string (list string)) (list string)))))
wenzelm@51294
    44
                            (list string)))) a;
wenzelm@48927
    45
                      val imports' = map (rpair Position.none) imports;
wenzelm@51294
    46
                      val header = Thy_Header.make (name, Position.none) imports' keywords;
wenzelm@51294
    47
                    in Document.Deps (master, header, errors) end,
wenzelm@44384
    48
                  fn (a, []) => Document.Perspective (map int_atom a)]))
wenzelm@44157
    49
            end;
wenzelm@38412
    50
wenzelm@47420
    51
        val (assignment, state') = Document.update old_id new_id edits state;
wenzelm@44436
    52
        val _ =
wenzelm@50201
    53
          Output.protocol_message Markup.assign_execs
wenzelm@44661
    54
            ((new_id, assignment) |>
wenzelm@44476
    55
              let open XML.Encode
wenzelm@52527
    56
              in pair int (list (pair int (list int))) end
wenzelm@44661
    57
              |> YXML.string_of_body);
wenzelm@47420
    58
wenzelm@49931
    59
        val _ = List.app Future.cancel_group (Goal.reset_futures ());
wenzelm@50505
    60
        val _ = Isabelle_Process.reset_tracing ();
wenzelm@47420
    61
        val _ = Document.start_execution state';
wenzelm@47420
    62
      in state' end));
wenzelm@38412
    63
wenzelm@43748
    64
val _ =
wenzelm@46119
    65
  Isabelle_Process.protocol_command "Document.remove_versions"
wenzelm@44673
    66
    (fn [versions_yxml] => Document.change_state (fn state =>
wenzelm@44673
    67
      let
wenzelm@44673
    68
        val versions =
wenzelm@44673
    69
          YXML.parse_body versions_yxml |>
wenzelm@44673
    70
            let open XML.Decode in list int end;
wenzelm@44676
    71
        val state1 = Document.remove_versions versions state;
wenzelm@50201
    72
        val _ = Output.protocol_message Markup.removed_versions versions_yxml;
wenzelm@44676
    73
      in state1 end));
wenzelm@44673
    74
wenzelm@44673
    75
val _ =
wenzelm@50498
    76
  Isabelle_Process.protocol_command "Document.dialog_result"
wenzelm@50500
    77
    (fn [serial, result] =>
wenzelm@50500
    78
      Active.dialog_result (Markup.parse_int serial) result
wenzelm@50498
    79
        handle exn => if Exn.is_interrupt exn then () else reraise exn);
wenzelm@50498
    80
wenzelm@38412
    81
end;
wenzelm@38412
    82