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);
wenzelm@45709
     1
(*  Title:      Pure/PIDE/protocol.ML
wenzelm@38412
     2
    Author:     Makarius
wenzelm@38412
     3
wenzelm@45709
     4
Protocol message formats for interactive proof documents.
wenzelm@38412
     5
*)
wenzelm@38412
     6
wenzelm@45709
     7
structure Protocol: sig end =
wenzelm@38412
     8
struct
wenzelm@38412
     9
wenzelm@38418
    10
val _ =
wenzelm@46119
    11
  Isabelle_Process.protocol_command "Document.define_command"
wenzelm@44644
    12
    (fn [id, name, text] =>
wenzelm@44644
    13
      Document.change_state (Document.define_command (Document.parse_id id) name text));
wenzelm@38412
    14
wenzelm@38418
    15
val _ =
wenzelm@47343
    16
  Isabelle_Process.protocol_command "Document.discontinue_execution"
wenzelm@47343
    17
    (fn [] => Document.discontinue_execution (Document.state ()));
wenzelm@47343
    18
wenzelm@47343
    19
val _ =
wenzelm@46119
    20
  Isabelle_Process.protocol_command "Document.cancel_execution"
wenzelm@47404
    21
    (fn [] => Document.cancel_execution (Document.state ()));
wenzelm@44612
    22
wenzelm@44612
    23
val _ =
wenzelm@46119
    24
  Isabelle_Process.protocol_command "Document.update"
wenzelm@44157
    25
    (fn [old_id_string, new_id_string, edits_yxml] => Document.change_state (fn state =>
wenzelm@38418
    26
      let
wenzelm@47404
    27
        val _ = Document.cancel_execution state;
wenzelm@47404
    28
wenzelm@38418
    29
        val old_id = Document.parse_id old_id_string;
wenzelm@38418
    30
        val new_id = Document.parse_id new_id_string;
wenzelm@44157
    31
        val edits =
wenzelm@44157
    32
          YXML.parse_body edits_yxml |>
wenzelm@44157
    33
            let open XML.Decode in
wenzelm@44157
    34
              list (pair string
wenzelm@44157
    35
                (variant
wenzelm@48755
    36
                 [fn ([], []) => Document.Clear,  (* FIXME unused !? *)
wenzelm@44157
    37
                  fn ([], a) => Document.Edits (list (pair (option int) (option int)) a),
wenzelm@44157
    38
                  fn ([], a) =>
wenzelm@46938
    39
                    let
wenzelm@48707
    40
                      val (master, (name, (imports, (keywords, (uses, errors))))) =
wenzelm@48707
    41
                        pair string (pair string (pair (list string)
wenzelm@48864
    42
                          (pair (list (pair string
wenzelm@48864
    43
                            (option (pair (pair string (list string)) (list string)))))
wenzelm@48707
    44
                            (pair (list (pair string bool)) (list string))))) a;
wenzelm@48707
    45
                      val (uses', errors') =
wenzelm@48707
    46
                        (map (apfst Path.explode) uses, errors)
wenzelm@48707
    47
                          handle ERROR msg => ([], errors @ [msg]);
wenzelm@48707
    48
                      val header = Thy_Header.make name imports keywords uses';
wenzelm@48707
    49
                    in Document.Deps (master, header, errors') end,
wenzelm@44384
    50
                  fn (a, []) => Document.Perspective (map int_atom a)]))
wenzelm@44157
    51
            end;
wenzelm@38412
    52
wenzelm@47420
    53
        val (assignment, state') = Document.update old_id new_id edits state;
wenzelm@44436
    54
        val _ =
wenzelm@46774
    55
          Output.protocol_message Isabelle_Markup.assign_execs
wenzelm@44661
    56
            ((new_id, assignment) |>
wenzelm@44476
    57
              let open XML.Encode
wenzelm@47388
    58
              in pair int (list (pair int (option int))) end
wenzelm@44661
    59
              |> YXML.string_of_body);
wenzelm@47420
    60
wenzelm@47420
    61
        val _ = Document.start_execution state';
wenzelm@47420
    62
      in state' end));
wenzelm@38412
    63
wenzelm@43748
    64
val _ =
wenzelm@46119
    65
  Isabelle_Process.protocol_command "Document.remove_versions"
wenzelm@44673
    66
    (fn [versions_yxml] => Document.change_state (fn state =>
wenzelm@44673
    67
      let
wenzelm@44673
    68
        val versions =
wenzelm@44673
    69
          YXML.parse_body versions_yxml |>
wenzelm@44673
    70
            let open XML.Decode in list int end;
wenzelm@44676
    71
        val state1 = Document.remove_versions versions state;
wenzelm@46774
    72
        val _ = Output.protocol_message Isabelle_Markup.removed_versions versions_yxml;
wenzelm@44676
    73
      in state1 end));
wenzelm@44673
    74
wenzelm@44673
    75
val _ =
wenzelm@46119
    76
  Isabelle_Process.protocol_command "Document.invoke_scala"
wenzelm@43748
    77
    (fn [id, tag, res] => Invoke_Scala.fulfill_method id tag res);
wenzelm@43748
    78
wenzelm@38412
    79
end;
wenzelm@38412
    80