src/Pure/PIDE/isar_document.ML
author wenzelm
Thu Aug 19 12:51:48 2010 +0200 (2010-08-19 ago)
changeset 38483 3d16bebee1d3
parent 38448 src/Pure/System/isar_document.ML@62d16c415019
child 38567 b670faa807c9
permissions -rw-r--r--
moved Isar_Document to Pure/PIDE;
wenzelm@38483
     1
(*  Title:      Pure/PIDE/isar_document.ML
wenzelm@38412
     2
    Author:     Makarius
wenzelm@38412
     3
wenzelm@38418
     4
Protocol commands for interactive Isar documents.
wenzelm@38412
     5
*)
wenzelm@38412
     6
wenzelm@38412
     7
structure Isar_Document: sig end =
wenzelm@38412
     8
struct
wenzelm@38412
     9
wenzelm@38420
    10
val global_state = Synchronized.var "Isar_Document" Document.init_state;
wenzelm@38420
    11
val change_state = Synchronized.change global_state;
wenzelm@38412
    12
wenzelm@38418
    13
val _ =
wenzelm@38418
    14
  Isabelle_Process.add_command "Isar_Document.define_command"
wenzelm@38418
    15
    (fn [id, text] => change_state (Document.define_command (Document.parse_id id) text));
wenzelm@38412
    16
wenzelm@38418
    17
val _ =
wenzelm@38418
    18
  Isabelle_Process.add_command "Isar_Document.edit_version"
wenzelm@38418
    19
    (fn [old_id_string, new_id_string, edits_yxml] => change_state (fn state =>
wenzelm@38418
    20
      let
wenzelm@38418
    21
        val old_id = Document.parse_id old_id_string;
wenzelm@38418
    22
        val new_id = Document.parse_id new_id_string;
wenzelm@38418
    23
        val edits =
wenzelm@38448
    24
          XML_Data.dest_list
wenzelm@38448
    25
            (XML_Data.dest_pair
wenzelm@38448
    26
              XML_Data.dest_string
wenzelm@38448
    27
              (XML_Data.dest_option
wenzelm@38448
    28
                (XML_Data.dest_list
wenzelm@38448
    29
                  (XML_Data.dest_pair
wenzelm@38448
    30
                    (XML_Data.dest_option XML_Data.dest_int)
wenzelm@38448
    31
                    (XML_Data.dest_option XML_Data.dest_int))))) (YXML.parse_body edits_yxml);
wenzelm@38412
    32
wenzelm@38418
    33
      val (updates, state') = Document.edit old_id new_id edits state;
wenzelm@38418
    34
      val _ =
wenzelm@38418
    35
        implode (map (fn (id, exec_id) => Markup.markup (Markup.edit id exec_id) "") updates)
wenzelm@38418
    36
        |> Markup.markup (Markup.assign new_id)
wenzelm@38418
    37
        |> Output.status;
wenzelm@38418
    38
      val state'' = Document.execute new_id state';
wenzelm@38418
    39
    in state'' end));
wenzelm@38412
    40
wenzelm@38412
    41
end;
wenzelm@38412
    42