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