src/Pure/PIDE/protocol.ML
author wenzelm
Mon Aug 20 14:09:09 2012 +0200 (2012-08-20 ago)
changeset 48864 3ee314ae1e0a
parent 48755 393a37003851
child 48927 ef462b5558eb
permissions -rw-r--r--
added keyword kind "thy_load" (with optional list of file extensions);
     1 (*  Title:      Pure/PIDE/protocol.ML
     2     Author:     Makarius
     3 
     4 Protocol message formats for interactive proof documents.
     5 *)
     6 
     7 structure Protocol: sig end =
     8 struct
     9 
    10 val _ =
    11   Isabelle_Process.protocol_command "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.protocol_command "Document.discontinue_execution"
    17     (fn [] => Document.discontinue_execution (Document.state ()));
    18 
    19 val _ =
    20   Isabelle_Process.protocol_command "Document.cancel_execution"
    21     (fn [] => Document.cancel_execution (Document.state ()));
    22 
    23 val _ =
    24   Isabelle_Process.protocol_command "Document.update"
    25     (fn [old_id_string, new_id_string, edits_yxml] => Document.change_state (fn state =>
    26       let
    27         val _ = Document.cancel_execution state;
    28 
    29         val old_id = Document.parse_id old_id_string;
    30         val new_id = Document.parse_id new_id_string;
    31         val edits =
    32           YXML.parse_body edits_yxml |>
    33             let open XML.Decode in
    34               list (pair string
    35                 (variant
    36                  [fn ([], []) => Document.Clear,  (* FIXME unused !? *)
    37                   fn ([], a) => Document.Edits (list (pair (option int) (option int)) a),
    38                   fn ([], a) =>
    39                     let
    40                       val (master, (name, (imports, (keywords, (uses, errors))))) =
    41                         pair string (pair string (pair (list string)
    42                           (pair (list (pair string
    43                             (option (pair (pair string (list string)) (list string)))))
    44                             (pair (list (pair string bool)) (list string))))) a;
    45                       val (uses', errors') =
    46                         (map (apfst Path.explode) uses, errors)
    47                           handle ERROR msg => ([], errors @ [msg]);
    48                       val header = Thy_Header.make name imports keywords uses';
    49                     in Document.Deps (master, header, errors') end,
    50                   fn (a, []) => Document.Perspective (map int_atom a)]))
    51             end;
    52 
    53         val (assignment, state') = Document.update old_id new_id edits state;
    54         val _ =
    55           Output.protocol_message Isabelle_Markup.assign_execs
    56             ((new_id, assignment) |>
    57               let open XML.Encode
    58               in pair int (list (pair int (option int))) end
    59               |> YXML.string_of_body);
    60 
    61         val _ = Document.start_execution state';
    62       in state' end));
    63 
    64 val _ =
    65   Isabelle_Process.protocol_command "Document.remove_versions"
    66     (fn [versions_yxml] => Document.change_state (fn state =>
    67       let
    68         val versions =
    69           YXML.parse_body versions_yxml |>
    70             let open XML.Decode in list int end;
    71         val state1 = Document.remove_versions versions state;
    72         val _ = Output.protocol_message Isabelle_Markup.removed_versions versions_yxml;
    73       in state1 end));
    74 
    75 val _ =
    76   Isabelle_Process.protocol_command "Document.invoke_scala"
    77     (fn [id, tag, res] => Invoke_Scala.fulfill_method id tag res);
    78 
    79 end;
    80