src/Pure/PIDE/isar_document.ML
author wenzelm
Sat Sep 03 21:15:35 2011 +0200 (2011-09-03)
changeset 44676 7de87f1ae965
parent 44673 2fa51ac191bc
child 44979 68b990e950b1
permissions -rw-r--r--
Document.removed_versions on Scala side;
     1 (*  Title:      Pure/PIDE/isar_document.ML
     2     Author:     Makarius
     3 
     4 Protocol message formats for interactive Isar documents.
     5 *)
     6 
     7 structure Isar_Document: sig end =
     8 struct
     9 
    10 val _ =
    11   Isabelle_Process.add_command "Isar_Document.define_command"
    12     (fn [id, name, text] =>
    13       Document.change_state (Document.define_command (Document.parse_id id) name text));
    14 
    15 val _ =
    16   Isabelle_Process.add_command "Isar_Document.cancel_execution"
    17     (fn [] => ignore (Document.cancel_execution (Document.state ())));
    18 
    19 val _ =
    20   Isabelle_Process.add_command "Isar_Document.update_perspective"
    21     (fn [old_id_string, new_id_string, name, ids_yxml] => Document.change_state (fn state =>
    22       let
    23         val old_id = Document.parse_id old_id_string;
    24         val new_id = Document.parse_id new_id_string;
    25         val ids = YXML.parse_body ids_yxml
    26           |> let open XML.Decode in list int end;
    27 
    28         val _ = Future.join_tasks (Document.cancel_execution state);
    29       in
    30         state
    31         |> Document.update_perspective old_id new_id name ids
    32         |> Document.execute new_id
    33       end));
    34 
    35 val _ =
    36   Isabelle_Process.add_command "Isar_Document.update"
    37     (fn [old_id_string, new_id_string, edits_yxml] => Document.change_state (fn state =>
    38       let
    39         val old_id = Document.parse_id old_id_string;
    40         val new_id = Document.parse_id new_id_string;
    41         val edits =
    42           YXML.parse_body edits_yxml |>
    43             let open XML.Decode in
    44               list (pair string
    45                 (variant
    46                  [fn ([], []) => Document.Clear,
    47                   fn ([], a) => Document.Edits (list (pair (option int) (option int)) a),
    48                   fn ([], a) =>
    49                     Document.Header
    50                       (Exn.Res (triple string (list string) (list (pair string bool)) a)),
    51                   fn ([a], []) => Document.Header (Exn.Exn (ERROR a)),
    52                   fn (a, []) => Document.Perspective (map int_atom a)]))
    53             end;
    54 
    55         val running = Document.cancel_execution state;
    56         val (assignment, state1) = Document.update old_id new_id edits state;
    57         val _ = Future.join_tasks running;
    58         val _ =
    59           Output.raw_message Markup.assign_execs
    60             ((new_id, assignment) |>
    61               let open XML.Encode
    62               in pair int (pair (list (pair int (option int))) (list (pair string (option int)))) end
    63               |> YXML.string_of_body);
    64         val state2 = Document.execute new_id state1;
    65       in state2 end));
    66 
    67 val _ =
    68   Isabelle_Process.add_command "Isar_Document.remove_versions"
    69     (fn [versions_yxml] => Document.change_state (fn state =>
    70       let
    71         val versions =
    72           YXML.parse_body versions_yxml |>
    73             let open XML.Decode in list int end;
    74         val state1 = Document.remove_versions versions state;
    75         val _ = Output.raw_message Markup.removed_versions versions_yxml;
    76       in state1 end));
    77 
    78 val _ =
    79   Isabelle_Process.add_command "Isar_Document.invoke_scala"
    80     (fn [id, tag, res] => Invoke_Scala.fulfill_method id tag res);
    81 
    82 end;
    83