aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Json.ml
blob: db2de5d46577237b4402b91f7684e6f9605501f3 (plain)
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
(* *********************************************************************)
(*                                                                     *)
(*              The Compcert verified compiler                         *)
(*                                                                     *)
(*          Bernhard Schommer, AbsInt Angewandte Informatik GmbH       *)
(*                                                                     *)
(*  AbsInt Angewandte Informatik GmbH. All rights reserved. This file  *)
(*  is distributed under the terms of the INRIA Non-Commercial         *)
(*  License Agreement.                                                 *)
(*                                                                     *)
(* *********************************************************************)

open Printf

(* Simple functions for JSON printing *)

(* Print a string as json string *)
let p_jstring oc s = fprintf oc "\"%s\"" s

(* Print a list as json array *)
let p_jarray elem oc l =
  match l with
  | [] -> fprintf oc "[]"
  | hd::tail ->
      output_string oc "["; elem oc hd;
      List.iter (fprintf oc ",%a" elem) tail;
      output_string oc "]"

(* Print a bool as json bool *)
let p_jbool oc = fprintf oc "%B"

(* Print a int as json int *)
let p_jint oc = fprintf oc "%d"