src/Pure/PIDE/protocol.ML
author wenzelm
Fri Aug 10 15:14:45 2012 +0200 (2012-08-10 ago)
changeset 48755 393a37003851
parent 48707 ba531af91148
child 48864 3ee314ae1e0a
permissions -rw-r--r--
apply all text edits to each node, before determining the resulting doc_edits -- allow several iterations to consolidate spans etc.;
expand Clear edit before sending to prover;
at most one full reparse of each node;
     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 (option (pair string (list string)))))
    43                             (pair (list (pair string bool)) (list string))))) a;
    44                       val (uses', errors') =
    45                         (map (apfst Path.explode) uses, errors)
    46                           handle ERROR msg => ([], errors @ [msg]);
    47                       val header = Thy_Header.make name imports keywords uses';
    48                     in Document.Deps (master, header, errors') end,
    49                   fn (a, []) => Document.Perspective (map int_atom a)]))
    50             end;
    51 
    52         val (assignment, state') = Document.update old_id new_id edits state;
    53         val _ =
    54           Output.protocol_message Isabelle_Markup.assign_execs
    55             ((new_id, assignment) |>
    56               let open XML.Encode
    57               in pair int (list (pair int (option int))) end
    58               |> YXML.string_of_body);
    59 
    60         val _ = Document.start_execution state';
    61       in state' end));
    62 
    63 val _ =
    64   Isabelle_Process.protocol_command "Document.remove_versions"
    65     (fn [versions_yxml] => Document.change_state (fn state =>
    66       let
    67         val versions =
    68           YXML.parse_body versions_yxml |>
    69             let open XML.Decode in list int end;
    70         val state1 = Document.remove_versions versions state;
    71         val _ = Output.protocol_message Isabelle_Markup.removed_versions versions_yxml;
    72       in state1 end));
    73 
    74 val _ =
    75   Isabelle_Process.protocol_command "Document.invoke_scala"
    76     (fn [id, tag, res] => Invoke_Scala.fulfill_method id tag res);
    77 
    78 end;
    79