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