src/Pure/PIDE/isar_document.ML
author wenzelm
Fri, 08 Jul 2011 22:00:53 +0200
changeset 43713 1ba5331b4623
parent 43668 aad4f1956098
child 43722 9b5dadb0c28d
permissions -rw-r--r--
moved global state to structure Document (again);

(*  Title:      Pure/PIDE/isar_document.ML
    Author:     Makarius

Protocol message formats for interactive Isar documents.
*)

structure Isar_Document: sig end =
struct

val _ =
  Isabelle_Process.add_command "Isar_Document.define_command"
    (fn [id, text] => Document.change_state (Document.define_command (Document.parse_id id) text));

val _ =
  Isabelle_Process.add_command "Isar_Document.edit_version"
    (fn [old_id_string, new_id_string, edits_yxml] => Document.change_state (fn state =>
      let
        val old_id = Document.parse_id old_id_string;
        val new_id = Document.parse_id new_id_string;
        val edits =
          XML_Data.dest_list
            (XML_Data.dest_pair
              XML_Data.dest_string
              (XML_Data.dest_option
                (XML_Data.dest_list
                  (XML_Data.dest_pair
                    (XML_Data.dest_option XML_Data.dest_int)
                    (XML_Data.dest_option XML_Data.dest_int))))) (YXML.parse_body edits_yxml);

      val await_cancellation = Document.cancel_execution state;
      val (updates, state') = Document.edit old_id new_id edits state;
      val _ = await_cancellation ();
      val _ =
        Output.status (Markup.markup (Markup.assign new_id)
          (implode (map (Markup.markup_only o Markup.edit) updates)));
      val state'' = Document.execute new_id state';
    in state'' end));

end;