src/Pure/PIDE/protocol_message.ML
author wenzelm
Tue, 03 Dec 2019 16:40:04 +0100
changeset 71222 2bc39c80a95d
parent 70907 7e3f25a0cee4
child 71619 e33f6e5f86b6
permissions -rw-r--r--
clarified export of consts: recursion is accessible via spec_rules;

(*  Title:      Pure/PIDE/protocol_message.ML
    Author:     Makarius

Auxiliary operations on protocol messages.
*)

signature PROTOCOL_MESSAGE =
sig
  val inline: string -> Properties.T -> unit
  val command_positions: string -> XML.body -> XML.body
  val command_positions_yxml: string -> string -> string
end;

structure Protocol_Message: PROTOCOL_MESSAGE =
struct

fun inline a args =
  writeln ("\f" ^ a ^ " = " ^ YXML.string_of_body (XML.Encode.properties args));


fun command_positions id =
  let
    fun attribute (a, b) =
      if a = Markup.idN andalso b = Markup.commandN then (a, id) else (a, b);
    fun tree (XML.Elem ((a, atts), ts)) = XML.Elem ((a, map attribute atts), map tree ts)
      | tree text = text;
  in map tree end;

fun command_positions_yxml id =
  YXML.string_of_body o command_positions id o YXML.parse_body;

end;