src/Pure/PIDE/protocol.ML
author wenzelm
Thu Dec 01 14:29:14 2011 +0100 (2011-12-01)
changeset 45709 87017fcbad83
parent 45672 src/Pure/PIDE/isabelle_document.ML@a497c5d4a523
child 46119 0d7172a7672c
permissions -rw-r--r--
clarified modules (again) -- NB: both Document and Protocol are specific to this particular prover;
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@45709
    11
  Isabelle_Process.add_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@45709
    16
  Isabelle_Process.add_command "Document.cancel_execution"
wenzelm@44612
    17
    (fn [] => ignore (Document.cancel_execution (Document.state ())));
wenzelm@44612
    18
wenzelm@44612
    19
val _ =
wenzelm@45709
    20
  Isabelle_Process.add_command "Document.update_perspective"
wenzelm@44436
    21
    (fn [old_id_string, new_id_string, name, ids_yxml] => Document.change_state (fn state =>
wenzelm@44436
    22
      let
wenzelm@44436
    23
        val old_id = Document.parse_id old_id_string;
wenzelm@44436
    24
        val new_id = Document.parse_id new_id_string;
wenzelm@44436
    25
        val ids = YXML.parse_body ids_yxml
wenzelm@44436
    26
          |> let open XML.Decode in list int end;
wenzelm@44436
    27
wenzelm@44436
    28
        val _ = Future.join_tasks (Document.cancel_execution state);
wenzelm@44436
    29
      in
wenzelm@44436
    30
        state
wenzelm@44436
    31
        |> Document.update_perspective old_id new_id name ids
wenzelm@44436
    32
        |> Document.execute new_id
wenzelm@44436
    33
      end));
wenzelm@44436
    34
wenzelm@44436
    35
val _ =
wenzelm@45709
    36
  Isabelle_Process.add_command "Document.update"
wenzelm@44157
    37
    (fn [old_id_string, new_id_string, edits_yxml] => Document.change_state (fn state =>
wenzelm@38418
    38
      let
wenzelm@38418
    39
        val old_id = Document.parse_id old_id_string;
wenzelm@38418
    40
        val new_id = Document.parse_id new_id_string;
wenzelm@44157
    41
        val edits =
wenzelm@44157
    42
          YXML.parse_body edits_yxml |>
wenzelm@44157
    43
            let open XML.Decode in
wenzelm@44157
    44
              list (pair string
wenzelm@44157
    45
                (variant
wenzelm@44185
    46
                 [fn ([], []) => Document.Clear,
wenzelm@44157
    47
                  fn ([], a) => Document.Edits (list (pair (option int) (option int)) a),
wenzelm@44157
    48
                  fn ([], a) =>
wenzelm@44185
    49
                    Document.Header
wenzelm@44979
    50
                      (Exn.Res
wenzelm@44979
    51
                        (triple (pair string string) (list string) (list (pair string bool)) a)),
wenzelm@44384
    52
                  fn ([a], []) => Document.Header (Exn.Exn (ERROR a)),
wenzelm@44384
    53
                  fn (a, []) => Document.Perspective (map int_atom a)]))
wenzelm@44157
    54
            end;
wenzelm@38412
    55
wenzelm@44436
    56
        val running = Document.cancel_execution state;
wenzelm@44610
    57
        val (assignment, state1) = Document.update old_id new_id edits state;
wenzelm@44436
    58
        val _ = Future.join_tasks running;
wenzelm@44436
    59
        val _ =
wenzelm@45666
    60
          Output.raw_message Isabelle_Markup.assign_execs
wenzelm@44661
    61
            ((new_id, assignment) |>
wenzelm@44476
    62
              let open XML.Encode
wenzelm@44661
    63
              in pair int (pair (list (pair int (option int))) (list (pair string (option int)))) end
wenzelm@44661
    64
              |> YXML.string_of_body);
wenzelm@44660
    65
        val state2 = Document.execute new_id state1;
wenzelm@44660
    66
      in state2 end));
wenzelm@38412
    67
wenzelm@43748
    68
val _ =
wenzelm@45709
    69
  Isabelle_Process.add_command "Document.remove_versions"
wenzelm@44673
    70
    (fn [versions_yxml] => Document.change_state (fn state =>
wenzelm@44673
    71
      let
wenzelm@44673
    72
        val versions =
wenzelm@44673
    73
          YXML.parse_body versions_yxml |>
wenzelm@44673
    74
            let open XML.Decode in list int end;
wenzelm@44676
    75
        val state1 = Document.remove_versions versions state;
wenzelm@45666
    76
        val _ = Output.raw_message Isabelle_Markup.removed_versions versions_yxml;
wenzelm@44676
    77
      in state1 end));
wenzelm@44673
    78
wenzelm@44673
    79
val _ =
wenzelm@45709
    80
  Isabelle_Process.add_command "Document.invoke_scala"
wenzelm@43748
    81
    (fn [id, tag, res] => Invoke_Scala.fulfill_method id tag res);
wenzelm@43748
    82
wenzelm@38412
    83
end;
wenzelm@38412
    84