src/Pure/PIDE/isar_document.ML
author wenzelm
Fri Jul 08 22:00:53 2011 +0200 (2011-07-08 ago)
changeset 43713 1ba5331b4623
parent 43668 aad4f1956098
child 43722 9b5dadb0c28d
permissions -rw-r--r--
moved global state to structure Document (again);
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@43713
    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@38418
    20
        val edits =
wenzelm@38448
    21
          XML_Data.dest_list
wenzelm@38448
    22
            (XML_Data.dest_pair
wenzelm@38448
    23
              XML_Data.dest_string
wenzelm@38448
    24
              (XML_Data.dest_option
wenzelm@38448
    25
                (XML_Data.dest_list
wenzelm@38448
    26
                  (XML_Data.dest_pair
wenzelm@38448
    27
                    (XML_Data.dest_option XML_Data.dest_int)
wenzelm@38448
    28
                    (XML_Data.dest_option XML_Data.dest_int))))) (YXML.parse_body edits_yxml);
wenzelm@38412
    29
wenzelm@43666
    30
      val await_cancellation = Document.cancel_execution state;
wenzelm@38418
    31
      val (updates, state') = Document.edit old_id new_id edits state;
wenzelm@43666
    32
      val _ = await_cancellation ();
wenzelm@38418
    33
      val _ =
wenzelm@43665
    34
        Output.status (Markup.markup (Markup.assign new_id)
wenzelm@43665
    35
          (implode (map (Markup.markup_only o Markup.edit) updates)));
wenzelm@38418
    36
      val state'' = Document.execute new_id state';
wenzelm@38418
    37
    in state'' end));
wenzelm@38412
    38
wenzelm@38412
    39
end;
wenzelm@38412
    40