src/Pure/PIDE/protocol.ML
author wenzelm
Tue Aug 07 15:01:48 2012 +0200 (2012-08-07 ago)
changeset 48707 ba531af91148
parent 47420 0dbe6c69eda2
child 48755 393a37003851
permissions -rw-r--r--
simplified Document.Node.Header -- internalized errors;
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@48707
    40
                      val (master, (name, (imports, (keywords, (uses, errors))))) =
wenzelm@48707
    41
                        pair string (pair string (pair (list string)
wenzelm@48707
    42
                          (pair (list (pair string (option (pair string (list string)))))
wenzelm@48707
    43
                            (pair (list (pair string bool)) (list string))))) a;
wenzelm@48707
    44
                      val (uses', errors') =
wenzelm@48707
    45
                        (map (apfst Path.explode) uses, errors)
wenzelm@48707
    46
                          handle ERROR msg => ([], errors @ [msg]);
wenzelm@48707
    47
                      val header = Thy_Header.make name imports keywords uses';
wenzelm@48707
    48
                    in Document.Deps (master, header, errors') end,
wenzelm@44384
    49
                  fn (a, []) => Document.Perspective (map int_atom a)]))
wenzelm@44157
    50
            end;
wenzelm@38412
    51
wenzelm@47420
    52
        val (assignment, state') = Document.update old_id new_id edits state;
wenzelm@44436
    53
        val _ =
wenzelm@46774
    54
          Output.protocol_message Isabelle_Markup.assign_execs
wenzelm@44661
    55
            ((new_id, assignment) |>
wenzelm@44476
    56
              let open XML.Encode
wenzelm@47388
    57
              in pair int (list (pair int (option int))) end
wenzelm@44661
    58
              |> YXML.string_of_body);
wenzelm@47420
    59
wenzelm@47420
    60
        val _ = Document.start_execution state';
wenzelm@47420
    61
      in state' 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