src/Pure/PIDE/protocol.ML
author wenzelm
Fri Apr 06 11:49:08 2012 +0200 (2012-04-06 ago)
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;
     1 (*  Title:      Pure/PIDE/protocol.ML
     2     Author:     Makarius
     3 
     4 Protocol message formats for interactive proof documents.
     5 *)
     6 
     7 structure Protocol: sig end =
     8 struct
     9 
    10 val _ =
    11   Isabelle_Process.protocol_command "Document.define_command"
    12     (fn [id, name, text] =>
    13       Document.change_state (Document.define_command (Document.parse_id id) name text));
    14 
    15 val _ =
    16   Isabelle_Process.protocol_command "Document.discontinue_execution"
    17     (fn [] => Document.discontinue_execution (Document.state ()));
    18 
    19 val _ =
    20   Isabelle_Process.protocol_command "Document.cancel_execution"
    21     (fn [] => ignore (Document.cancel_execution (Document.state ())));
    22 
    23 val _ =
    24   Isabelle_Process.protocol_command "Document.update"
    25     (fn [old_id_string, new_id_string, edits_yxml] => Document.change_state (fn state =>
    26       let
    27         val old_id = Document.parse_id old_id_string;
    28         val new_id = Document.parse_id new_id_string;
    29         val edits =
    30           YXML.parse_body edits_yxml |>
    31             let open XML.Decode in
    32               list (pair string
    33                 (variant
    34                  [fn ([], []) => Document.Clear,
    35                   fn ([], a) => Document.Edits (list (pair (option int) (option int)) a),
    36                   fn ([], a) =>
    37                     let
    38                       val ((((master, name), imports), keywords), uses) =
    39                         pair (pair (pair (pair string string) (list string))
    40                           (list (pair string (option (pair string (list string))))))
    41                           (list (pair string bool)) a;
    42                       val res =
    43                         Exn.capture (fn () =>
    44                           (master, Thy_Header.make name imports keywords
    45                             (map (apfst Path.explode) uses))) ();
    46                     in Document.Header res end,
    47                   fn ([a], []) => Document.Header (Exn.Exn (ERROR a)),
    48                   fn (a, []) => Document.Perspective (map int_atom a)]))
    49             end;
    50 
    51         val running = Document.cancel_execution state;
    52         val (assignment, state1) = Document.update old_id new_id edits state;
    53         val _ = Future.join_tasks running;
    54         val _ =
    55           Output.protocol_message Isabelle_Markup.assign_execs
    56             ((new_id, assignment) |>
    57               let open XML.Encode
    58               in pair int (pair (list (pair int (option int))) (list (pair string (option int)))) end
    59               |> YXML.string_of_body);
    60         val state2 = Document.execute new_id state1;
    61       in state2 end));
    62 
    63 val _ =
    64   Isabelle_Process.protocol_command "Document.remove_versions"
    65     (fn [versions_yxml] => Document.change_state (fn state =>
    66       let
    67         val versions =
    68           YXML.parse_body versions_yxml |>
    69             let open XML.Decode in list int end;
    70         val state1 = Document.remove_versions versions state;
    71         val _ = Output.protocol_message Isabelle_Markup.removed_versions versions_yxml;
    72       in state1 end));
    73 
    74 val _ =
    75   Isabelle_Process.protocol_command "Document.invoke_scala"
    76     (fn [id, tag, res] => Invoke_Scala.fulfill_method id tag res);
    77 
    78 end;
    79