src/Pure/PIDE/protocol.ML
author wenzelm
Fri Apr 06 11:49:08 2012 +0200 (2012-04-06)
changeset 47346 cd3ab7625519
parent 47343 b8aeab386414
child 47388 fe4b245af74c
permissions -rw-r--r--
discontinued Document.update_perspective side-entry (cf. 546adfa8a6fc) -- NB: re-assignment is always necessary due to non-monotonic cancel_execution;
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@44644
    13
      Document.change_state (Document.define_command (Document.parse_id 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@44612
    21
    (fn [] => ignore (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@38418
    27
        val old_id = Document.parse_id old_id_string;
wenzelm@38418
    28
        val new_id = Document.parse_id new_id_string;
wenzelm@44157
    29
        val edits =
wenzelm@44157
    30
          YXML.parse_body edits_yxml |>
wenzelm@44157
    31
            let open XML.Decode in
wenzelm@44157
    32
              list (pair string
wenzelm@44157
    33
                (variant
wenzelm@44185
    34
                 [fn ([], []) => Document.Clear,
wenzelm@44157
    35
                  fn ([], a) => Document.Edits (list (pair (option int) (option int)) a),
wenzelm@44157
    36
                  fn ([], a) =>
wenzelm@46938
    37
                    let
wenzelm@46938
    38
                      val ((((master, name), imports), keywords), uses) =
wenzelm@46938
    39
                        pair (pair (pair (pair string string) (list string))
wenzelm@46938
    40
                          (list (pair string (option (pair string (list string))))))
wenzelm@46938
    41
                          (list (pair string bool)) a;
wenzelm@46938
    42
                      val res =
wenzelm@46938
    43
                        Exn.capture (fn () =>
wenzelm@46938
    44
                          (master, Thy_Header.make name imports keywords
wenzelm@46938
    45
                            (map (apfst Path.explode) uses))) ();
wenzelm@46938
    46
                    in Document.Header res end,
wenzelm@44384
    47
                  fn ([a], []) => Document.Header (Exn.Exn (ERROR a)),
wenzelm@44384
    48
                  fn (a, []) => Document.Perspective (map int_atom a)]))
wenzelm@44157
    49
            end;
wenzelm@38412
    50
wenzelm@44436
    51
        val running = Document.cancel_execution state;
wenzelm@44610
    52
        val (assignment, state1) = Document.update old_id new_id edits state;
wenzelm@44436
    53
        val _ = Future.join_tasks running;
wenzelm@44436
    54
        val _ =
wenzelm@46774
    55
          Output.protocol_message Isabelle_Markup.assign_execs
wenzelm@44661
    56
            ((new_id, assignment) |>
wenzelm@44476
    57
              let open XML.Encode
wenzelm@44661
    58
              in pair int (pair (list (pair int (option int))) (list (pair string (option int)))) end
wenzelm@44661
    59
              |> YXML.string_of_body);
wenzelm@44660
    60
        val state2 = Document.execute new_id state1;
wenzelm@44660
    61
      in state2 end));
wenzelm@38412
    62
wenzelm@43748
    63
val _ =
wenzelm@46119
    64
  Isabelle_Process.protocol_command "Document.remove_versions"
wenzelm@44673
    65
    (fn [versions_yxml] => Document.change_state (fn state =>
wenzelm@44673
    66
      let
wenzelm@44673
    67
        val versions =
wenzelm@44673
    68
          YXML.parse_body versions_yxml |>
wenzelm@44673
    69
            let open XML.Decode in list int end;
wenzelm@44676
    70
        val state1 = Document.remove_versions versions state;
wenzelm@46774
    71
        val _ = Output.protocol_message Isabelle_Markup.removed_versions versions_yxml;
wenzelm@44676
    72
      in state1 end));
wenzelm@44673
    73
wenzelm@44673
    74
val _ =
wenzelm@46119
    75
  Isabelle_Process.protocol_command "Document.invoke_scala"
wenzelm@43748
    76
    (fn [id, tag, res] => Invoke_Scala.fulfill_method id tag res);
wenzelm@43748
    77
wenzelm@38412
    78
end;
wenzelm@38412
    79