@@ -45,7 +45,7 @@ module P = struct
45
45
|> Seq_ext. intersperse (comma ^^ break)
46
46
|> concat
47
47
in
48
- (* maybe_flat *) (nest 2 (break ^^ body) ^^ break)
48
+ maybe_flat (nest 2 (break ^^ body) ^^ break)
49
49
50
50
let rec to_document = function
51
51
| JNull ->
@@ -67,65 +67,15 @@ module P = struct
67
67
fields)
68
68
end
69
69
70
- module Printing = struct
71
- let pp_comma fmt () = Format. pp_print_string fmt " ,"
72
-
73
- let rec to_string = function
74
- | JString str -> Printf. sprintf " %S" str
75
- | JBool b -> Printf. sprintf " %b" b
76
- | JInt i -> string_of_int i
77
- | JArray jsons ->
78
- " [" ^ String. concat " , " (List. map to_string jsons) ^ " ]"
79
- | JNull -> " null"
80
- | JObject obj ->
81
- let field_to_string (nm , json ) =
82
- Printf. sprintf " %S: %s" nm (to_string json)
83
- in
84
- " {" ^ String. concat " , " (List. map field_to_string obj) ^ " }"
85
-
86
- (* FIXME: move to a Utf8_string module *)
87
- let json_escape fmt s =
88
- let s = Utf8_string. of_string_unsafe s in
89
- (* FIXME *)
90
- let b = Buffer. create (Utf8_string. byte_length s + 4 ) in
91
- let escape_char c =
92
- if c = Uchar. of_char '"' then Buffer. add_char b '"'
93
- else if c = Uchar. of_char '\\' then Buffer. add_char b '\\'
94
- else if c = Uchar. of_char '\n' then Buffer. add_string b " \\ n"
95
- else if c = Uchar. of_char '\x0c' then Buffer. add_string b " \\ f"
96
- else if c = Uchar. of_char '\t' then Buffer. add_string b " \\ t"
97
- else if c = Uchar. of_char '\r' then Buffer. add_string b " \\ r"
98
- else if c = Uchar. of_char '\b' then Buffer. add_string b " \\ b"
99
- else Buffer. add_utf_8_uchar b c
100
- in
101
- Utf8_string. iter escape_char s;
102
- Format. pp_print_string fmt (Buffer. contents b)
103
-
104
- let pp_string fmt s =
105
- Format. fprintf fmt " \" %a\" " json_escape s
106
- let pp_delim =
107
- Format. pp_print_string
108
-
109
- let rec pp fmt = function
110
- | JString s -> pp_string fmt s
111
- | JBool true -> Format. pp_print_string fmt " true"
112
- | JBool false -> Format. pp_print_string fmt " false"
113
- | JInt i -> Format. pp_print_int fmt i
114
- (* | Float f -> Format.pp_print_float fmt f (* FIXME: proper format *) *)
115
- | JNull -> Format. pp_print_string fmt " null"
116
- | JArray [] ->
117
- Format. pp_print_string fmt " []"
118
- | JArray elems ->
119
- Format. fprintf fmt " %a@,@[<v2> %a@]@,%a"
120
- pp_delim " ["
121
- (Format. pp_print_list ~pp_sep: pp_comma pp) elems
122
- pp_delim " ]"
123
- | JObject [] ->
124
- Format. pp_print_string fmt " {}"
125
- | JObject fields ->
126
- Format. fprintf fmt " %a@,@[<v2> %a@]@,%a" pp_delim " {"
127
- (Format. pp_print_list ~pp_sep: pp_comma pp_field)
128
- fields pp_delim " }"
129
-
130
- and pp_field fmt (nm , json ) = Format. fprintf fmt " %a: %a" pp_string nm pp json
131
- end
70
+ let rec to_string = function
71
+ | JString str -> Printf. sprintf " %S" str
72
+ | JBool b -> Printf. sprintf " %b" b
73
+ | JInt i -> string_of_int i
74
+ | JArray jsons ->
75
+ " [" ^ String. concat " , " (List. map to_string jsons) ^ " ]"
76
+ | JNull -> " null"
77
+ | JObject obj ->
78
+ let field_to_string (nm , json ) =
79
+ Printf. sprintf " %S: %s" nm (to_string json)
80
+ in
81
+ " {" ^ String. concat " , " (List. map field_to_string obj) ^ " }"
0 commit comments