src/Pure/PIDE/protocol.ML
author wenzelm
Wed Apr 11 11:44:21 2012 +0200 (2012-04-11 ago)
changeset 47420 0dbe6c69eda2
parent 47404 e6e5750f1311
child 48707 ba531af91148
permissions -rw-r--r--
just one dedicated execution per document version -- NB: non-monotonicity of cancel always requires fresh update;
explicit terminate_execution;
tuned source structure;
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@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@38418
    29
        val old_id = Document.parse_id old_id_string;
wenzelm@38418
    30
        val new_id = Document.parse_id 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@44185
    36
                 [fn ([], []) => Document.Clear,
wenzelm@44157
    37
                  fn ([], a) => Document.Edits (list (pair (option int) (option int)) a),
wenzelm@44157
    38
                  fn ([], a) =>
wenzelm@46938
    39
                    let
wenzelm@46938
    40
                      val ((((master, name), imports), keywords), uses) =
wenzelm@46938
    41
                        pair (pair (pair (pair string string) (list string))
wenzelm@46938
    42
                          (list (pair string (option (pair string (list string))))))
wenzelm@46938
    43
                          (list (pair string bool)) a;
wenzelm@46938
    44
                      val res =
wenzelm@46938
    45
                        Exn.capture (fn () =>
wenzelm@46938
    46
                          (master, Thy_Header.make name imports keywords
wenzelm@46938
    47
                            (map (apfst Path.explode) uses))) ();
wenzelm@46938
    48
                    in Document.Header res end,
wenzelm@44384
    49
                  fn ([a], []) => Document.Header (Exn.Exn (ERROR a)),
wenzelm@44384
    50
                  fn (a, []) => Document.Perspective (map int_atom a)]))
wenzelm@44157
    51
            end;
wenzelm@38412
    52
wenzelm@47420
    53
        val (assignment, state') = Document.update old_id new_id edits state;
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@47388
    58
              in pair int (list (pair int (option int))) end
wenzelm@44661
    59
              |> YXML.string_of_body);
wenzelm@47420
    60
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@46774
    72
        val _ = Output.protocol_message Isabelle_Markup.removed_versions versions_yxml;
wenzelm@44676
    73
      in state1 end));
wenzelm@44673
    74
wenzelm@44673
    75
val _ =
wenzelm@46119
    76
  Isabelle_Process.protocol_command "Document.invoke_scala"
wenzelm@43748
    77
    (fn [id, tag, res] => Invoke_Scala.fulfill_method id tag res);
wenzelm@43748
    78
wenzelm@38412
    79
end;
wenzelm@38412
    80