src/Pure/PIDE/isar_document.ML
author wenzelm
Mon Jul 11 16:48:02 2011 +0200 (2011-07-11)
changeset 43748 c70bd78ec83c
parent 43731 70072780e095
child 43767 e0219ef7f84c
permissions -rw-r--r--
JVM method invocation service via Scala layer;
     1 (*  Title:      Pure/PIDE/isar_document.ML
     2     Author:     Makarius
     3 
     4 Protocol message formats for interactive Isar documents.
     5 *)
     6 
     7 structure Isar_Document: sig end =
     8 struct
     9 
    10 val _ =
    11   Isabelle_Process.add_command "Isar_Document.define_command"
    12     (fn [id, text] => Document.change_state (Document.define_command (Document.parse_id id) text));
    13 
    14 val _ =
    15   Isabelle_Process.add_command "Isar_Document.edit_version"
    16     (fn [old_id_string, new_id_string, edits_yxml, headers_yxml] => Document.change_state (fn state =>
    17       let
    18         val old_id = Document.parse_id old_id_string;
    19         val new_id = Document.parse_id new_id_string;
    20         val edits = YXML.parse_body edits_yxml |>
    21           let open XML_Data.Decode
    22           in list (pair string (option (list (pair (option int) (option int))))) end;
    23         val headers = YXML.parse_body headers_yxml |>
    24           let open XML_Data.Decode
    25           in list (pair string (triple string (list string) (list string))) end;
    26 
    27       val await_cancellation = Document.cancel_execution state;
    28       val (updates, state') = Document.edit old_id new_id edits headers state;
    29       val _ = await_cancellation ();
    30       val _ =
    31         Output.status (Markup.markup (Markup.assign new_id)
    32           (implode (map (Markup.markup_only o Markup.edit) updates)));
    33       val state'' = Document.execute new_id state';
    34     in state'' end));
    35 
    36 val _ =
    37   Isabelle_Process.add_command "Isar_Document.invoke_scala"
    38     (fn [id, tag, res] => Invoke_Scala.fulfill_method id tag res);
    39 
    40 end;
    41