src/Pure/PIDE/isar_document.ML
author wenzelm
Thu, 11 Aug 2011 20:32:44 +0200
changeset 44157 a21d3e1e64fd
parent 44156 6aa25b80e1a5
child 44182 ecb51b457064
permissions -rw-r--r--
uniform treatment of header edits as document edits;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
38483
3d16bebee1d3 moved Isar_Document to Pure/PIDE;
wenzelm
parents: 38448
diff changeset
     1
(*  Title:      Pure/PIDE/isar_document.ML
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
     3
38567
b670faa807c9 concentrate protocol message formats in Isar_Document;
wenzelm
parents: 38483
diff changeset
     4
Protocol message formats for interactive Isar documents.
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
     5
*)
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
     6
43713
1ba5331b4623 moved global state to structure Document (again);
wenzelm
parents: 43668
diff changeset
     7
structure Isar_Document: sig end =
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
     8
struct
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
     9
38418
9a7af64d71bb more explicit / functional ML version of document model;
wenzelm
parents: 38417
diff changeset
    10
val _ =
9a7af64d71bb more explicit / functional ML version of document model;
wenzelm
parents: 38417
diff changeset
    11
  Isabelle_Process.add_command "Isar_Document.define_command"
43713
1ba5331b4623 moved global state to structure Document (again);
wenzelm
parents: 43668
diff changeset
    12
    (fn [id, text] => Document.change_state (Document.define_command (Document.parse_id id) text));
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
    13
38418
9a7af64d71bb more explicit / functional ML version of document model;
wenzelm
parents: 38417
diff changeset
    14
val _ =
9a7af64d71bb more explicit / functional ML version of document model;
wenzelm
parents: 38417
diff changeset
    15
  Isabelle_Process.add_command "Isar_Document.edit_version"
44157
a21d3e1e64fd uniform treatment of header edits as document edits;
wenzelm
parents: 44156
diff changeset
    16
    (fn [old_id_string, new_id_string, edits_yxml] => Document.change_state (fn state =>
38418
9a7af64d71bb more explicit / functional ML version of document model;
wenzelm
parents: 38417
diff changeset
    17
      let
9a7af64d71bb more explicit / functional ML version of document model;
wenzelm
parents: 38417
diff changeset
    18
        val old_id = Document.parse_id old_id_string;
9a7af64d71bb more explicit / functional ML version of document model;
wenzelm
parents: 38417
diff changeset
    19
        val new_id = Document.parse_id new_id_string;
44157
a21d3e1e64fd uniform treatment of header edits as document edits;
wenzelm
parents: 44156
diff changeset
    20
        val edits =
a21d3e1e64fd uniform treatment of header edits as document edits;
wenzelm
parents: 44156
diff changeset
    21
          YXML.parse_body edits_yxml |>
a21d3e1e64fd uniform treatment of header edits as document edits;
wenzelm
parents: 44156
diff changeset
    22
            let open XML.Decode in
a21d3e1e64fd uniform treatment of header edits as document edits;
wenzelm
parents: 44156
diff changeset
    23
              list (pair string
a21d3e1e64fd uniform treatment of header edits as document edits;
wenzelm
parents: 44156
diff changeset
    24
                (variant
a21d3e1e64fd uniform treatment of header edits as document edits;
wenzelm
parents: 44156
diff changeset
    25
                 [fn ([], []) => Document.Remove,
a21d3e1e64fd uniform treatment of header edits as document edits;
wenzelm
parents: 44156
diff changeset
    26
                  fn ([], a) => Document.Edits (list (pair (option int) (option int)) a),
a21d3e1e64fd uniform treatment of header edits as document edits;
wenzelm
parents: 44156
diff changeset
    27
                  fn ([], a) =>
a21d3e1e64fd uniform treatment of header edits as document edits;
wenzelm
parents: 44156
diff changeset
    28
                    Document.Update_Header (Exn.Res (triple string (list string) (list string) a)),
a21d3e1e64fd uniform treatment of header edits as document edits;
wenzelm
parents: 44156
diff changeset
    29
                  fn ([a], []) => Document.Update_Header (Exn.Exn (ERROR a))]))
a21d3e1e64fd uniform treatment of header edits as document edits;
wenzelm
parents: 44156
diff changeset
    30
            end;
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
    31
43666
7be2e51928cb clarified cancel_execution/await_cancellation;
wenzelm
parents: 43665
diff changeset
    32
      val await_cancellation = Document.cancel_execution state;
44157
a21d3e1e64fd uniform treatment of header edits as document edits;
wenzelm
parents: 44156
diff changeset
    33
      val (updates, state') = Document.edit old_id new_id edits state;
43666
7be2e51928cb clarified cancel_execution/await_cancellation;
wenzelm
parents: 43665
diff changeset
    34
      val _ = await_cancellation ();
38418
9a7af64d71bb more explicit / functional ML version of document model;
wenzelm
parents: 38417
diff changeset
    35
      val _ =
43665
573d1272f36d tuned signature;
wenzelm
parents: 41634
diff changeset
    36
        Output.status (Markup.markup (Markup.assign new_id)
573d1272f36d tuned signature;
wenzelm
parents: 41634
diff changeset
    37
          (implode (map (Markup.markup_only o Markup.edit) updates)));
38418
9a7af64d71bb more explicit / functional ML version of document model;
wenzelm
parents: 38417
diff changeset
    38
      val state'' = Document.execute new_id state';
9a7af64d71bb more explicit / functional ML version of document model;
wenzelm
parents: 38417
diff changeset
    39
    in state'' end));
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
    40
43748
c70bd78ec83c JVM method invocation service via Scala layer;
wenzelm
parents: 43731
diff changeset
    41
val _ =
c70bd78ec83c JVM method invocation service via Scala layer;
wenzelm
parents: 43731
diff changeset
    42
  Isabelle_Process.add_command "Isar_Document.invoke_scala"
c70bd78ec83c JVM method invocation service via Scala layer;
wenzelm
parents: 43731
diff changeset
    43
    (fn [id, tag, res] => Invoke_Scala.fulfill_method id tag res);
c70bd78ec83c JVM method invocation service via Scala layer;
wenzelm
parents: 43731
diff changeset
    44
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
    45
end;
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
    46