-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyaml.ml
37 lines (31 loc) · 961 Bytes
/
yaml.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
type value = [
| `Mapping of (value * value) list
| `Sequence of value list
| `Scalar of string
]
type elem = [ value | `Comment of string ]
type doc = Doc of elem
open Core.Std
let rec output_value outc = function
| `Mapping obj -> print_map outc obj
| `Sequence l -> print_seq outc l
| `Scalar s -> printf "\"%s\"" s
and print_map outc obj =
output_string outc "{ ";
let sep = ref "" in
List.iter obj ~f:(fun (k, v) ->
printf "%s%a : %a" !sep output_value k output_value v;
sep := ",\n ");
output_string outc " }"
and print_seq outc arr =
output_string outc "[";
List.iteri arr ~f:(fun i v ->
if i > 0 then
output_string outc ", ";
output_value outc v);
output_string outc "]"
let output_elem outc = function
| `Mapping obj -> print_map outc obj
| `Sequence l -> print_seq outc l
| `Scalar s -> printf "\"%s\"" s
| `Comment c -> printf "#%s" c