src/Pure/PIDE/isar_document.ML
author wenzelm
Sat Aug 13 15:59:26 2011 +0200 (2011-08-13)
changeset 44182 ecb51b457064
parent 44157 a21d3e1e64fd
child 44185 05641edb5d30
permissions -rw-r--r--
clarified node header -- exclude master_dir;
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@44157
    16
    (fn [old_id_string, new_id_string, edits_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@44157
    20
        val edits =
wenzelm@44157
    21
          YXML.parse_body edits_yxml |>
wenzelm@44157
    22
            let open XML.Decode in
wenzelm@44157
    23
              list (pair string
wenzelm@44157
    24
                (variant
wenzelm@44157
    25
                 [fn ([], []) => Document.Remove,
wenzelm@44157
    26
                  fn ([], a) => Document.Edits (list (pair (option int) (option int)) a),
wenzelm@44157
    27
                  fn ([], a) =>
wenzelm@44182
    28
                    Document.Header (Exn.Res (triple string (list string) (list string) a)),
wenzelm@44182
    29
                  fn ([a], []) => Document.Header (Exn.Exn (ERROR a))]))
wenzelm@44157
    30
            end;
wenzelm@38412
    31
wenzelm@43666
    32
      val await_cancellation = Document.cancel_execution state;
wenzelm@44157
    33
      val (updates, state') = Document.edit old_id new_id edits state;
wenzelm@43666
    34
      val _ = await_cancellation ();
wenzelm@38418
    35
      val _ =
wenzelm@43665
    36
        Output.status (Markup.markup (Markup.assign new_id)
wenzelm@43665
    37
          (implode (map (Markup.markup_only o Markup.edit) updates)));
wenzelm@38418
    38
      val state'' = Document.execute new_id state';
wenzelm@38418
    39
    in state'' end));
wenzelm@38412
    40
wenzelm@43748
    41
val _ =
wenzelm@43748
    42
  Isabelle_Process.add_command "Isar_Document.invoke_scala"
wenzelm@43748
    43
    (fn [id, tag, res] => Invoke_Scala.fulfill_method id tag res);
wenzelm@43748
    44
wenzelm@38412
    45
end;
wenzelm@38412
    46