src/Pure/PIDE/yxml.ML
author wenzelm
Fri, 24 Jun 2022 23:31:28 +0200
changeset 75615 4494cd69f97f
parent 74231 b3c65c984210
child 75626 4879d0021185
permissions -rw-r--r--
clarified modules;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
44698
0385292321a0 moved XML/YXML to src/Pure/PIDE;
wenzelm
parents: 43782
diff changeset
     1
(*  Title:      Pure/PIDE/yxml.ML
26528
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
     3
26540
173d548ce9d2 replaced ETX/EOT by ENQ/ACK, which are less likely to be interpreted by tty etc.;
wenzelm
parents: 26528
diff changeset
     4
Efficient text representation of XML trees using extra characters X
44698
0385292321a0 moved XML/YXML to src/Pure/PIDE;
wenzelm
parents: 43782
diff changeset
     5
and Y -- no escaping, may nest marked text verbatim.  Suitable for
0385292321a0 moved XML/YXML to src/Pure/PIDE;
wenzelm
parents: 43782
diff changeset
     6
direct inlining into plain text.
26528
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
     7
26540
173d548ce9d2 replaced ETX/EOT by ENQ/ACK, which are less likely to be interpreted by tty etc.;
wenzelm
parents: 26528
diff changeset
     8
Markup <elem att="val" ...>...body...</elem> is encoded as:
173d548ce9d2 replaced ETX/EOT by ENQ/ACK, which are less likely to be interpreted by tty etc.;
wenzelm
parents: 26528
diff changeset
     9
173d548ce9d2 replaced ETX/EOT by ENQ/ACK, which are less likely to be interpreted by tty etc.;
wenzelm
parents: 26528
diff changeset
    10
  X Y name Y att=val ... X
26528
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
    11
  ...
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
    12
  body
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
    13
  ...
26540
173d548ce9d2 replaced ETX/EOT by ENQ/ACK, which are less likely to be interpreted by tty etc.;
wenzelm
parents: 26528
diff changeset
    14
  X Y X
26528
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
    15
*)
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
    16
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
    17
signature YXML =
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
    18
sig
43777
22c87ff1b8a9 tuned signature -- less cryptic ASCII names;
wenzelm
parents: 43772
diff changeset
    19
  val X: Symbol.symbol
22c87ff1b8a9 tuned signature -- less cryptic ASCII names;
wenzelm
parents: 43772
diff changeset
    20
  val Y: Symbol.symbol
43772
c825594fd0c1 clarified YXML.embed_controls -- this is idempotent and cannot be nested;
wenzelm
parents: 43731
diff changeset
    21
  val embed_controls: string -> string
43731
70072780e095 inner syntax supports inlined YXML according to Term_XML (particularly useful for producing text under program control);
wenzelm
parents: 43728
diff changeset
    22
  val detect: string -> bool
70990
e5e34bd28257 clarified signature;
wenzelm
parents: 70989
diff changeset
    23
  val traverse: (string -> 'a -> 'a) -> XML.tree -> 'a -> 'a
73557
225486d9c960 tuned signature;
wenzelm
parents: 73556
diff changeset
    24
  val tree_size: XML.tree -> int
225486d9c960 tuned signature;
wenzelm
parents: 73556
diff changeset
    25
  val body_size: XML.body -> int
43728
152ce7114396 YXML.string_of_body convenience;
wenzelm
parents: 43615
diff changeset
    26
  val string_of_body: XML.body -> string
26528
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
    27
  val string_of: XML.tree -> string
70991
f9f7c34b7dd4 more scalable protocol_message: use XML.body directly (Output.output hook is not required);
wenzelm
parents: 70990
diff changeset
    28
  val write_body: Path.T -> XML.body -> unit
70989
wenzelm
parents: 69845
diff changeset
    29
  val output_markup: Markup.T -> string * string
49656
7ff712de5747 treat wrapped markup elements as raw markup delimiters;
wenzelm
parents: 46832
diff changeset
    30
  val output_markup_elem: Markup.T -> (string * string) * string
38266
492d377ecfe2 type XML.body as basic data representation language;
wenzelm
parents: 38265
diff changeset
    31
  val parse_body: string -> XML.body
26528
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
    32
  val parse: string -> XML.tree
59433
9da5b2c61049 tuned signature;
wenzelm
parents: 49656
diff changeset
    33
  val content_of: string -> string
71456
09c850e82258 more robust pretty printing of broken YXML, e.g. single "\^E";
wenzelm
parents: 70996
diff changeset
    34
  val is_wellformed: string -> bool
26528
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
    35
end;
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
    36
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
    37
structure YXML: YXML =
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
    38
struct
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
    39
26540
173d548ce9d2 replaced ETX/EOT by ENQ/ACK, which are less likely to be interpreted by tty etc.;
wenzelm
parents: 26528
diff changeset
    40
(** string representation **)
26528
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
    41
38265
cc9fde54311f renamed YXML.binary_text to YXML.escape_controls to emphasize what it actually does;
wenzelm
parents: 38228
diff changeset
    42
(* idempotent recoding of certain low ASCII control characters *)
34095
c2f176a38448 robust representation of low ASCII control characters within XML/YXML text;
wenzelm
parents: 31469
diff changeset
    43
c2f176a38448 robust representation of low ASCII control characters within XML/YXML text;
wenzelm
parents: 31469
diff changeset
    44
fun pseudo_utf8 c =
c2f176a38448 robust representation of low ASCII control characters within XML/YXML text;
wenzelm
parents: 31469
diff changeset
    45
  if Symbol.is_ascii_control c
c2f176a38448 robust representation of low ASCII control characters within XML/YXML text;
wenzelm
parents: 31469
diff changeset
    46
  then chr 192 ^ chr (128 + ord c)
c2f176a38448 robust representation of low ASCII control characters within XML/YXML text;
wenzelm
parents: 31469
diff changeset
    47
  else c;
c2f176a38448 robust representation of low ASCII control characters within XML/YXML text;
wenzelm
parents: 31469
diff changeset
    48
43772
c825594fd0c1 clarified YXML.embed_controls -- this is idempotent and cannot be nested;
wenzelm
parents: 43731
diff changeset
    49
fun embed_controls str =
34095
c2f176a38448 robust representation of low ASCII control characters within XML/YXML text;
wenzelm
parents: 31469
diff changeset
    50
  if exists_string Symbol.is_ascii_control str
c2f176a38448 robust representation of low ASCII control characters within XML/YXML text;
wenzelm
parents: 31469
diff changeset
    51
  then translate_string pseudo_utf8 str
c2f176a38448 robust representation of low ASCII control characters within XML/YXML text;
wenzelm
parents: 31469
diff changeset
    52
  else str;
c2f176a38448 robust representation of low ASCII control characters within XML/YXML text;
wenzelm
parents: 31469
diff changeset
    53
c2f176a38448 robust representation of low ASCII control characters within XML/YXML text;
wenzelm
parents: 31469
diff changeset
    54
26547
1112375f6a69 tuned comments;
wenzelm
parents: 26540
diff changeset
    55
(* markers *)
1112375f6a69 tuned comments;
wenzelm
parents: 26540
diff changeset
    56
64275
ac2abc987cf9 accomodate Poly/ML repository version, which treats singleton strings as boxed;
wenzelm
parents: 59433
diff changeset
    57
val X_char = Char.chr 5;
ac2abc987cf9 accomodate Poly/ML repository version, which treats singleton strings as boxed;
wenzelm
parents: 59433
diff changeset
    58
val Y_char = Char.chr 6;
ac2abc987cf9 accomodate Poly/ML repository version, which treats singleton strings as boxed;
wenzelm
parents: 59433
diff changeset
    59
ac2abc987cf9 accomodate Poly/ML repository version, which treats singleton strings as boxed;
wenzelm
parents: 59433
diff changeset
    60
val X = String.str X_char;
ac2abc987cf9 accomodate Poly/ML repository version, which treats singleton strings as boxed;
wenzelm
parents: 59433
diff changeset
    61
val Y = String.str Y_char;
26540
173d548ce9d2 replaced ETX/EOT by ENQ/ACK, which are less likely to be interpreted by tty etc.;
wenzelm
parents: 26528
diff changeset
    62
val XY = X ^ Y;
173d548ce9d2 replaced ETX/EOT by ENQ/ACK, which are less likely to be interpreted by tty etc.;
wenzelm
parents: 26528
diff changeset
    63
val XYX = XY ^ X;
26528
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
    64
64275
ac2abc987cf9 accomodate Poly/ML repository version, which treats singleton strings as boxed;
wenzelm
parents: 59433
diff changeset
    65
fun detect s = Char.contains s X_char orelse Char.contains s Y_char;
43731
70072780e095 inner syntax supports inlined YXML according to Term_XML (particularly useful for producing text under program control);
wenzelm
parents: 43728
diff changeset
    66
26528
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
    67
73557
225486d9c960 tuned signature;
wenzelm
parents: 73556
diff changeset
    68
(* traverse *)
26540
173d548ce9d2 replaced ETX/EOT by ENQ/ACK, which are less likely to be interpreted by tty etc.;
wenzelm
parents: 26528
diff changeset
    69
70990
e5e34bd28257 clarified signature;
wenzelm
parents: 70989
diff changeset
    70
fun traverse string =
e5e34bd28257 clarified signature;
wenzelm
parents: 70989
diff changeset
    71
  let
e5e34bd28257 clarified signature;
wenzelm
parents: 70989
diff changeset
    72
    fun attrib (a, x) = string Y #> string a #> string "=" #> string x;
73556
192bcee4f8b8 more robust treatment of empty markup: it allows to produce formal chunks;
wenzelm
parents: 71456
diff changeset
    73
    fun tree (XML.Elem (markup as (name, atts), ts)) =
192bcee4f8b8 more robust treatment of empty markup: it allows to produce formal chunks;
wenzelm
parents: 71456
diff changeset
    74
          if Markup.is_empty markup then fold tree ts
192bcee4f8b8 more robust treatment of empty markup: it allows to produce formal chunks;
wenzelm
parents: 71456
diff changeset
    75
          else
192bcee4f8b8 more robust treatment of empty markup: it allows to produce formal chunks;
wenzelm
parents: 71456
diff changeset
    76
            string XY #> string name #> fold attrib atts #> string X #>
192bcee4f8b8 more robust treatment of empty markup: it allows to produce formal chunks;
wenzelm
parents: 71456
diff changeset
    77
            fold tree ts #>
192bcee4f8b8 more robust treatment of empty markup: it allows to produce formal chunks;
wenzelm
parents: 71456
diff changeset
    78
            string XYX
70990
e5e34bd28257 clarified signature;
wenzelm
parents: 70989
diff changeset
    79
      | tree (XML.Text s) = string s;
e5e34bd28257 clarified signature;
wenzelm
parents: 70989
diff changeset
    80
  in tree end;
43728
152ce7114396 YXML.string_of_body convenience;
wenzelm
parents: 43615
diff changeset
    81
73557
225486d9c960 tuned signature;
wenzelm
parents: 73556
diff changeset
    82
fun tree_size tree = traverse (Integer.add o size) tree 0;
225486d9c960 tuned signature;
wenzelm
parents: 73556
diff changeset
    83
fun body_size body = fold (Integer.add o tree_size) body 0;
225486d9c960 tuned signature;
wenzelm
parents: 73556
diff changeset
    84
225486d9c960 tuned signature;
wenzelm
parents: 73556
diff changeset
    85
225486d9c960 tuned signature;
wenzelm
parents: 73556
diff changeset
    86
(* output *)
225486d9c960 tuned signature;
wenzelm
parents: 73556
diff changeset
    87
74231
b3c65c984210 tuned signature;
wenzelm
parents: 73557
diff changeset
    88
val string_of_body = Buffer.build_content o fold (traverse Buffer.add);
43728
152ce7114396 YXML.string_of_body convenience;
wenzelm
parents: 43615
diff changeset
    89
val string_of = string_of_body o single;
26528
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
    90
70991
f9f7c34b7dd4 more scalable protocol_message: use XML.body directly (Output.output hook is not required);
wenzelm
parents: 70990
diff changeset
    91
fun write_body path body =
75615
4494cd69f97f clarified modules;
wenzelm
parents: 74231
diff changeset
    92
  path |> File_Stream.open_output (fn file =>
4494cd69f97f clarified modules;
wenzelm
parents: 74231
diff changeset
    93
    fold (traverse (fn s => fn () => File_Stream.output file s)) body ());
70991
f9f7c34b7dd4 more scalable protocol_message: use XML.body directly (Output.output hook is not required);
wenzelm
parents: 70990
diff changeset
    94
26528
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
    95
70989
wenzelm
parents: 69845
diff changeset
    96
(* markup elements *)
49656
7ff712de5747 treat wrapped markup elements as raw markup delimiters;
wenzelm
parents: 46832
diff changeset
    97
7ff712de5747 treat wrapped markup elements as raw markup delimiters;
wenzelm
parents: 46832
diff changeset
    98
val Z = chr 0;
7ff712de5747 treat wrapped markup elements as raw markup delimiters;
wenzelm
parents: 46832
diff changeset
    99
val Z_text = [XML.Text Z];
7ff712de5747 treat wrapped markup elements as raw markup delimiters;
wenzelm
parents: 46832
diff changeset
   100
70989
wenzelm
parents: 69845
diff changeset
   101
fun output_markup (markup as (name, atts)) =
wenzelm
parents: 69845
diff changeset
   102
  if Markup.is_empty markup then Markup.no_output
wenzelm
parents: 69845
diff changeset
   103
  else (XY ^ name ^ implode (map (fn (a, x) => Y ^ a ^ "=" ^ x) atts) ^ X, XYX);
wenzelm
parents: 69845
diff changeset
   104
49656
7ff712de5747 treat wrapped markup elements as raw markup delimiters;
wenzelm
parents: 46832
diff changeset
   105
fun output_markup_elem markup =
7ff712de5747 treat wrapped markup elements as raw markup delimiters;
wenzelm
parents: 46832
diff changeset
   106
  let val [bg1, bg2, en] = space_explode Z (string_of (XML.wrap_elem ((markup, Z_text), Z_text)))
7ff712de5747 treat wrapped markup elements as raw markup delimiters;
wenzelm
parents: 46832
diff changeset
   107
  in ((bg1, bg2), en) end;
7ff712de5747 treat wrapped markup elements as raw markup delimiters;
wenzelm
parents: 46832
diff changeset
   108
7ff712de5747 treat wrapped markup elements as raw markup delimiters;
wenzelm
parents: 46832
diff changeset
   109
26540
173d548ce9d2 replaced ETX/EOT by ENQ/ACK, which are less likely to be interpreted by tty etc.;
wenzelm
parents: 26528
diff changeset
   110
173d548ce9d2 replaced ETX/EOT by ENQ/ACK, which are less likely to be interpreted by tty etc.;
wenzelm
parents: 26528
diff changeset
   111
(** efficient YXML parsing **)
26528
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
   112
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
   113
local
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
   114
26540
173d548ce9d2 replaced ETX/EOT by ENQ/ACK, which are less likely to be interpreted by tty etc.;
wenzelm
parents: 26528
diff changeset
   115
(* splitting *)
173d548ce9d2 replaced ETX/EOT by ENQ/ACK, which are less likely to be interpreted by tty etc.;
wenzelm
parents: 26528
diff changeset
   116
173d548ce9d2 replaced ETX/EOT by ENQ/ACK, which are less likely to be interpreted by tty etc.;
wenzelm
parents: 26528
diff changeset
   117
val split_string =
173d548ce9d2 replaced ETX/EOT by ENQ/ACK, which are less likely to be interpreted by tty etc.;
wenzelm
parents: 26528
diff changeset
   118
  Substring.full #>
64275
ac2abc987cf9 accomodate Poly/ML repository version, which treats singleton strings as boxed;
wenzelm
parents: 59433
diff changeset
   119
  Substring.tokens (fn c => c = X_char) #>
ac2abc987cf9 accomodate Poly/ML repository version, which treats singleton strings as boxed;
wenzelm
parents: 59433
diff changeset
   120
  map (Substring.fields (fn c => c = Y_char) #> map Substring.string);
26540
173d548ce9d2 replaced ETX/EOT by ENQ/ACK, which are less likely to be interpreted by tty etc.;
wenzelm
parents: 26528
diff changeset
   121
173d548ce9d2 replaced ETX/EOT by ENQ/ACK, which are less likely to be interpreted by tty etc.;
wenzelm
parents: 26528
diff changeset
   122
173d548ce9d2 replaced ETX/EOT by ENQ/ACK, which are less likely to be interpreted by tty etc.;
wenzelm
parents: 26528
diff changeset
   123
(* structural errors *)
26528
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
   124
46832
050e344825c8 tuned message (cf. ML version);
wenzelm
parents: 46831
diff changeset
   125
fun err msg = raise Fail ("Malformed YXML: " ^ msg);
26528
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
   126
fun err_attribute () = err "bad attribute";
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
   127
fun err_element () = err "bad element";
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
   128
fun err_unbalanced "" = err "unbalanced element"
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
   129
  | err_unbalanced name = err ("unbalanced element " ^ quote name);
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
   130
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
   131
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
   132
(* stack operations *)
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
   133
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
   134
fun add x ((elem, body) :: pending) = (elem, x :: body) :: pending;
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
   135
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
   136
fun push "" _ _ = err_element ()
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
   137
  | push name atts pending = ((name, atts), []) :: pending;
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
   138
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
   139
fun pop ((("", _), _) :: _) = err_unbalanced ""
38228
ada3ab6b9085 simplified type XML.tree: embed Markup.T directly, avoid slightly odd triple;
wenzelm
parents: 34095
diff changeset
   140
  | pop ((markup, body) :: pending) = add (XML.Elem (markup, rev body)) pending;
26528
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
   141
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
   142
26540
173d548ce9d2 replaced ETX/EOT by ENQ/ACK, which are less likely to be interpreted by tty etc.;
wenzelm
parents: 26528
diff changeset
   143
(* parsing *)
26528
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
   144
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
   145
fun parse_attrib s =
28025
d9fcab768496 replaced find_substring by first_field;
wenzelm
parents: 28023
diff changeset
   146
  (case first_field "=" s of
28023
92dd3ad302b7 simplified parse_attrib (find_substring instead of space_explode);
wenzelm
parents: 27932
diff changeset
   147
    NONE => err_attribute ()
28025
d9fcab768496 replaced find_substring by first_field;
wenzelm
parents: 28023
diff changeset
   148
  | SOME ("", _) => err_attribute ()
d9fcab768496 replaced find_substring by first_field;
wenzelm
parents: 28023
diff changeset
   149
  | SOME att => att);
26528
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
   150
26540
173d548ce9d2 replaced ETX/EOT by ENQ/ACK, which are less likely to be interpreted by tty etc.;
wenzelm
parents: 26528
diff changeset
   151
fun parse_chunk ["", ""] = pop
173d548ce9d2 replaced ETX/EOT by ENQ/ACK, which are less likely to be interpreted by tty etc.;
wenzelm
parents: 26528
diff changeset
   152
  | parse_chunk ("" :: name :: atts) = push name (map parse_attrib atts)
173d548ce9d2 replaced ETX/EOT by ENQ/ACK, which are less likely to be interpreted by tty etc.;
wenzelm
parents: 26528
diff changeset
   153
  | parse_chunk txts = fold (add o XML.Text) txts;
26528
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
   154
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
   155
in
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
   156
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
   157
fun parse_body source =
43615
8e0f6cfa8eb2 reverted ce00462f,b3759dce, 7a165592: unwanted generalisation
noschinl
parents: 42355
diff changeset
   158
  (case fold parse_chunk (split_string source) [(("", []), [])] of
26528
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
   159
    [(("", _), result)] => rev result
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
   160
  | ((name, _), _) :: _ => err_unbalanced name);
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
   161
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
   162
fun parse source =
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
   163
  (case parse_body source of
27798
b96c73f11a23 YXML.parse: allow text without markup, potentially empty;
wenzelm
parents: 26684
diff changeset
   164
    [result] => result
b96c73f11a23 YXML.parse: allow text without markup, potentially empty;
wenzelm
parents: 26684
diff changeset
   165
  | [] => XML.Text ""
b96c73f11a23 YXML.parse: allow text without markup, potentially empty;
wenzelm
parents: 26684
diff changeset
   166
  | _ => err "multiple results");
26528
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
   167
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
   168
end;
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
   169
59433
9da5b2c61049 tuned signature;
wenzelm
parents: 49656
diff changeset
   170
val content_of = parse_body #> XML.content_of;
9da5b2c61049 tuned signature;
wenzelm
parents: 49656
diff changeset
   171
71456
09c850e82258 more robust pretty printing of broken YXML, e.g. single "\^E";
wenzelm
parents: 70996
diff changeset
   172
fun is_wellformed s = string_of_body (parse_body s) = s
09c850e82258 more robust pretty printing of broken YXML, e.g. single "\^E";
wenzelm
parents: 70996
diff changeset
   173
  handle Fail _ => false;
09c850e82258 more robust pretty printing of broken YXML, e.g. single "\^E";
wenzelm
parents: 70996
diff changeset
   174
26528
944f9bf26d2d Why XML notation?
wenzelm
parents:
diff changeset
   175
end;