src/Pure/PIDE/protocol.ML
author wenzelm
Mon Apr 09 17:22:23 2012 +0200 (2012-04-09 ago)
changeset 47404 e6e5750f1311
parent 47388 fe4b245af74c
child 47420 0dbe6c69eda2
permissions -rw-r--r--
simplified Future.cancel/cancel_group (again) -- running threads only;
more robust update/cancel_execution: full join_tasks of group before exec state assignment;
tuned signature;
     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 [] => 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 _ = Document.cancel_execution state;
    28 
    29         val old_id = Document.parse_id old_id_string;
    30         val new_id = Document.parse_id new_id_string;
    31         val edits =
    32           YXML.parse_body edits_yxml |>
    33             let open XML.Decode in
    34               list (pair string
    35                 (variant
    36                  [fn ([], []) => Document.Clear,
    37                   fn ([], a) => Document.Edits (list (pair (option int) (option int)) a),
    38                   fn ([], a) =>
    39                     let
    40                       val ((((master, name), imports), keywords), uses) =
    41                         pair (pair (pair (pair string string) (list string))
    42                           (list (pair string (option (pair string (list string))))))
    43                           (list (pair string bool)) a;
    44                       val res =
    45                         Exn.capture (fn () =>
    46                           (master, Thy_Header.make name imports keywords
    47                             (map (apfst Path.explode) uses))) ();
    48                     in Document.Header res end,
    49                   fn ([a], []) => Document.Header (Exn.Exn (ERROR a)),
    50                   fn (a, []) => Document.Perspective (map int_atom a)]))
    51             end;
    52 
    53         val (assignment, state1) = Document.update old_id new_id edits state;
    54         val _ =
    55           Output.protocol_message Isabelle_Markup.assign_execs
    56             ((new_id, assignment) |>
    57               let open XML.Encode
    58               in pair int (list (pair int (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