src/Pure/PIDE/isar_document.ML
author wenzelm
Fri Aug 19 17:39:37 2011 +0200 (2011-08-19 ago)
changeset 44301 65f60d9ac4bf
parent 44299 061599cb6eb0
child 44384 8f6054a63f96
permissions -rw-r--r--
tuned signature (again);
tuned;
     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.Clear,
    26                   fn ([], a) => Document.Edits (list (pair (option int) (option int)) a),
    27                   fn ([], a) =>
    28                     Document.Header
    29                       (Exn.Res (triple string (list string) (list (pair string bool)) a)),
    30                   fn ([a], []) => Document.Header (Exn.Exn (ERROR a))]))
    31             end;
    32 
    33       val running = Document.cancel_execution state;
    34       val (updates, state') = Document.edit old_id new_id edits state;
    35       val _ = Future.join_tasks running;
    36       val _ = Document.join_commands state';
    37       val _ =
    38         Output.status (Markup.markup (Markup.assign new_id)
    39           (implode (map (Markup.markup_only o Markup.edit) updates)));
    40       val state'' = Document.execute new_id state';
    41     in state'' end));
    42 
    43 val _ =
    44   Isabelle_Process.add_command "Isar_Document.invoke_scala"
    45     (fn [id, tag, res] => Invoke_Scala.fulfill_method id tag res);
    46 
    47 end;
    48