src/Pure/PIDE/isar_document.ML
author wenzelm
Mon Aug 22 21:42:02 2011 +0200 (2011-08-22 ago)
changeset 44384 8f6054a63f96
parent 44301 65f60d9ac4bf
child 44436 546adfa8a6fc
permissions -rw-r--r--
some support for editor perspective;
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@44157
    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@44157
    20
        val edits =
wenzelm@44157
    21
          YXML.parse_body edits_yxml |>
wenzelm@44157
    22
            let open XML.Decode in
wenzelm@44157
    23
              list (pair string
wenzelm@44157
    24
                (variant
wenzelm@44185
    25
                 [fn ([], []) => Document.Clear,
wenzelm@44157
    26
                  fn ([], a) => Document.Edits (list (pair (option int) (option int)) a),
wenzelm@44157
    27
                  fn ([], a) =>
wenzelm@44185
    28
                    Document.Header
wenzelm@44185
    29
                      (Exn.Res (triple string (list string) (list (pair string bool)) a)),
wenzelm@44384
    30
                  fn ([a], []) => Document.Header (Exn.Exn (ERROR a)),
wenzelm@44384
    31
                  fn (a, []) => Document.Perspective (map int_atom a)]))
wenzelm@44157
    32
            end;
wenzelm@38412
    33
wenzelm@44301
    34
      val running = Document.cancel_execution state;
wenzelm@44157
    35
      val (updates, state') = Document.edit old_id new_id edits state;
wenzelm@44301
    36
      val _ = Future.join_tasks running;
wenzelm@44197
    37
      val _ = Document.join_commands state';
wenzelm@38418
    38
      val _ =
wenzelm@43665
    39
        Output.status (Markup.markup (Markup.assign new_id)
wenzelm@43665
    40
          (implode (map (Markup.markup_only o Markup.edit) updates)));
wenzelm@38418
    41
      val state'' = Document.execute new_id state';
wenzelm@38418
    42
    in state'' end));
wenzelm@38412
    43
wenzelm@43748
    44
val _ =
wenzelm@43748
    45
  Isabelle_Process.add_command "Isar_Document.invoke_scala"
wenzelm@43748
    46
    (fn [id, tag, res] => Invoke_Scala.fulfill_method id tag res);
wenzelm@43748
    47
wenzelm@38412
    48
end;
wenzelm@38412
    49