src/Pure/PIDE/protocol.ML
author wenzelm
Thu Oct 18 19:58:30 2012 +0200 (2012-10-18)
changeset 49931 85780e6f8fd2
parent 49647 21ae8500d261
child 50201 c26369c9eda6
permissions -rw-r--r--
more basic Goal.reset_futures as snapshot of implicit state;
more robust Session.finish_futures: do not cancel here, to allow later Future.map of persistent futures (notably proof terms);
     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,  (* FIXME unused !? *)
    37                   fn ([], a) => Document.Edits (list (pair (option int) (option int)) a),
    38                   fn ([], a) =>
    39                     let
    40                       val (master, (name, (imports, (keywords, (uses, errors))))) =
    41                         pair string (pair string (pair (list string)
    42                           (pair (list (pair string
    43                             (option (pair (pair string (list string)) (list string)))))
    44                             (pair (list (pair string bool)) (list string))))) a;
    45                       val imports' = map (rpair Position.none) imports;
    46                       val (uses', errors') =
    47                         (map (apfst Path.explode) uses, errors)
    48                           handle ERROR msg => ([], errors @ [msg]);
    49                       val header = Thy_Header.make (name, Position.none) imports' keywords uses';
    50                     in Document.Deps (master, header, errors') end,
    51                   fn (a, []) => Document.Perspective (map int_atom a)]))
    52             end;
    53 
    54         val (assignment, state') = Document.update old_id new_id edits state;
    55         val _ =
    56           Output.protocol_message Isabelle_Markup.assign_execs
    57             ((new_id, assignment) |>
    58               let open XML.Encode
    59               in pair int (list (pair int (option int))) end
    60               |> YXML.string_of_body);
    61 
    62         val _ = List.app Future.cancel_group (Goal.reset_futures ());
    63         val _ = Isabelle_Process.reset_tracing_limits ();
    64         val _ = Document.start_execution state';
    65       in state' end));
    66 
    67 val _ =
    68   Isabelle_Process.protocol_command "Document.remove_versions"
    69     (fn [versions_yxml] => Document.change_state (fn state =>
    70       let
    71         val versions =
    72           YXML.parse_body versions_yxml |>
    73             let open XML.Decode in list int end;
    74         val state1 = Document.remove_versions versions state;
    75         val _ = Output.protocol_message Isabelle_Markup.removed_versions versions_yxml;
    76       in state1 end));
    77 
    78 val _ =
    79   Isabelle_Process.protocol_command "Document.invoke_scala"
    80     (fn [id, tag, res] =>
    81       Invoke_Scala.fulfill_method id tag res
    82         handle exn => if Exn.is_interrupt exn then () else reraise exn);
    83 
    84 end;
    85