OCaml HTML5 parser/serialiser based on Python's JustHTML
1type t =
2 | Nothing
3 | Text
4 | Transparent
5 | Categories of Content_category.t list
6 | Elements of string list
7 | Mixed of Content_category.t list
8 | One_or_more of t
9 | Zero_or_more of t
10 | Optional of t
11 | Sequence of t list
12 | Choice of t list
13 | Except of t * Content_category.t list
14
15let rec pp fmt = function
16 | Nothing -> Format.fprintf fmt "Nothing"
17 | Text -> Format.fprintf fmt "Text"
18 | Transparent -> Format.fprintf fmt "Transparent"
19 | Categories cats ->
20 Format.fprintf fmt "Categories [%a]"
21 (Format.pp_print_list
22 ~pp_sep:(fun fmt () -> Format.fprintf fmt "; ")
23 Content_category.pp)
24 cats
25 | Elements elems ->
26 Format.fprintf fmt "Elements [%a]"
27 (Format.pp_print_list
28 ~pp_sep:(fun fmt () -> Format.fprintf fmt "; ")
29 Format.pp_print_string)
30 elems
31 | Mixed cats ->
32 Format.fprintf fmt "Mixed [%a]"
33 (Format.pp_print_list
34 ~pp_sep:(fun fmt () -> Format.fprintf fmt "; ")
35 Content_category.pp)
36 cats
37 | One_or_more t -> Format.fprintf fmt "One_or_more (%a)" pp t
38 | Zero_or_more t -> Format.fprintf fmt "Zero_or_more (%a)" pp t
39 | Optional t -> Format.fprintf fmt "Optional (%a)" pp t
40 | Sequence ts ->
41 Format.fprintf fmt "Sequence [%a]"
42 (Format.pp_print_list ~pp_sep:(fun fmt () -> Format.fprintf fmt "; ") pp)
43 ts
44 | Choice ts ->
45 Format.fprintf fmt "Choice [%a]"
46 (Format.pp_print_list ~pp_sep:(fun fmt () -> Format.fprintf fmt "; ") pp)
47 ts
48 | Except (t, cats) ->
49 Format.fprintf fmt "Except (%a, [%a])" pp t
50 (Format.pp_print_list
51 ~pp_sep:(fun fmt () -> Format.fprintf fmt "; ")
52 Content_category.pp)
53 cats
54
55let to_string t =
56 let buf = Buffer.create 256 in
57 let fmt = Format.formatter_of_buffer buf in
58 pp fmt t;
59 Format.pp_print_flush fmt ();
60 Buffer.contents buf