src/Pure/PIDE/protocol_message.ML
author wenzelm
Sun, 29 Nov 2020 14:27:15 +0100
changeset 72771 72976a6bd2ba
parent 71622 ab5009192ebb
permissions -rw-r--r--
tuned comments;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
59714
ae322325adbb tuned protocol -- resolve command positions in ML;
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/PIDE/protocol_message.ML
ae322325adbb tuned protocol -- resolve command positions in ML;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
ae322325adbb tuned protocol -- resolve command positions in ML;
wenzelm
parents:
diff changeset
     3
ae322325adbb tuned protocol -- resolve command positions in ML;
wenzelm
parents:
diff changeset
     4
Auxiliary operations on protocol messages.
ae322325adbb tuned protocol -- resolve command positions in ML;
wenzelm
parents:
diff changeset
     5
*)
ae322325adbb tuned protocol -- resolve command positions in ML;
wenzelm
parents:
diff changeset
     6
ae322325adbb tuned protocol -- resolve command positions in ML;
wenzelm
parents:
diff changeset
     7
signature PROTOCOL_MESSAGE =
ae322325adbb tuned protocol -- resolve command positions in ML;
wenzelm
parents:
diff changeset
     8
sig
71622
ab5009192ebb tuned signature -- follow Scala;
wenzelm
parents: 71619
diff changeset
     9
  val marker_text: string -> string -> unit
ab5009192ebb tuned signature -- follow Scala;
wenzelm
parents: 71619
diff changeset
    10
  val marker: string -> Properties.T -> unit
59714
ae322325adbb tuned protocol -- resolve command positions in ML;
wenzelm
parents:
diff changeset
    11
  val command_positions: string -> XML.body -> XML.body
ae322325adbb tuned protocol -- resolve command positions in ML;
wenzelm
parents:
diff changeset
    12
  val command_positions_yxml: string -> string -> string
ae322325adbb tuned protocol -- resolve command positions in ML;
wenzelm
parents:
diff changeset
    13
end;
ae322325adbb tuned protocol -- resolve command positions in ML;
wenzelm
parents:
diff changeset
    14
ae322325adbb tuned protocol -- resolve command positions in ML;
wenzelm
parents:
diff changeset
    15
structure Protocol_Message: PROTOCOL_MESSAGE =
ae322325adbb tuned protocol -- resolve command positions in ML;
wenzelm
parents:
diff changeset
    16
struct
ae322325adbb tuned protocol -- resolve command positions in ML;
wenzelm
parents:
diff changeset
    17
72771
72976a6bd2ba tuned comments;
wenzelm
parents: 71622
diff changeset
    18
(* message markers *)
72976a6bd2ba tuned comments;
wenzelm
parents: 71622
diff changeset
    19
71622
ab5009192ebb tuned signature -- follow Scala;
wenzelm
parents: 71619
diff changeset
    20
fun marker_text a text =
71619
e33f6e5f86b6 clarified protocol messages: explicitly use physical_writeln, always encode_lines;
wenzelm
parents: 70907
diff changeset
    21
  Output.physical_writeln ("\f" ^ a ^ " = " ^ encode_lines text);
e33f6e5f86b6 clarified protocol messages: explicitly use physical_writeln, always encode_lines;
wenzelm
parents: 70907
diff changeset
    22
71622
ab5009192ebb tuned signature -- follow Scala;
wenzelm
parents: 71619
diff changeset
    23
fun marker a props =
ab5009192ebb tuned signature -- follow Scala;
wenzelm
parents: 71619
diff changeset
    24
  marker_text a (YXML.string_of_body (XML.Encode.properties props));
70907
7e3f25a0cee4 proper protocol_message for bootstrap proofs;
wenzelm
parents: 59714
diff changeset
    25
7e3f25a0cee4 proper protocol_message for bootstrap proofs;
wenzelm
parents: 59714
diff changeset
    26
72771
72976a6bd2ba tuned comments;
wenzelm
parents: 71622
diff changeset
    27
(* inlined messages *)
72976a6bd2ba tuned comments;
wenzelm
parents: 71622
diff changeset
    28
59714
ae322325adbb tuned protocol -- resolve command positions in ML;
wenzelm
parents:
diff changeset
    29
fun command_positions id =
ae322325adbb tuned protocol -- resolve command positions in ML;
wenzelm
parents:
diff changeset
    30
  let
ae322325adbb tuned protocol -- resolve command positions in ML;
wenzelm
parents:
diff changeset
    31
    fun attribute (a, b) =
ae322325adbb tuned protocol -- resolve command positions in ML;
wenzelm
parents:
diff changeset
    32
      if a = Markup.idN andalso b = Markup.commandN then (a, id) else (a, b);
ae322325adbb tuned protocol -- resolve command positions in ML;
wenzelm
parents:
diff changeset
    33
    fun tree (XML.Elem ((a, atts), ts)) = XML.Elem ((a, map attribute atts), map tree ts)
ae322325adbb tuned protocol -- resolve command positions in ML;
wenzelm
parents:
diff changeset
    34
      | tree text = text;
ae322325adbb tuned protocol -- resolve command positions in ML;
wenzelm
parents:
diff changeset
    35
  in map tree end;
ae322325adbb tuned protocol -- resolve command positions in ML;
wenzelm
parents:
diff changeset
    36
ae322325adbb tuned protocol -- resolve command positions in ML;
wenzelm
parents:
diff changeset
    37
fun command_positions_yxml id =
ae322325adbb tuned protocol -- resolve command positions in ML;
wenzelm
parents:
diff changeset
    38
  YXML.string_of_body o command_positions id o YXML.parse_body;
ae322325adbb tuned protocol -- resolve command positions in ML;
wenzelm
parents:
diff changeset
    39
ae322325adbb tuned protocol -- resolve command positions in ML;
wenzelm
parents:
diff changeset
    40
end;