(*--------------------------------------------------------------------------- Copyright (c) 2026 Thomas Gazagnaire. All rights reserved. SPDX-License-Identifier: ISC ---------------------------------------------------------------------------*) type t = | Null | True | False | Int of string | Int5 of string | Float of string | Float5 of string | Text of string | Textj of string | Text5 of string | Textraw of string | Array of t list | Object of (t * t) list let sort : t -> Jsonb_sort.t = function | Null -> Null | True -> True | False -> False | Int _ -> Int | Int5 _ -> Int5 | Float _ -> Float | Float5 _ -> Float5 | Text _ -> Text | Textj _ -> Textj | Text5 _ -> Text5 | Textraw _ -> Textraw | Array _ -> Array | Object _ -> Object let rec equal a b = match (a, b) with | Null, Null | True, True | False, False -> true | Int a, Int b | Int5 a, Int5 b | Float a, Float b | Float5 a, Float5 b | Text a, Text b | Textj a, Textj b | Text5 a, Text5 b | Textraw a, Textraw b -> String.equal a b | Array a, Array b -> List.equal equal a b | Object a, Object b -> List.equal (fun (k, v) (k', v') -> equal k k' && equal v v') a b | ( ( Null | True | False | Int _ | Int5 _ | Float _ | Float5 _ | Text _ | Textj _ | Text5 _ | Textraw _ | Array _ | Object _ ), _ ) -> false let rec pp ppf = function | Null -> Fmt.string ppf "null" | True -> Fmt.string ppf "true" | False -> Fmt.string ppf "false" | Int s | Int5 s | Float s | Float5 s -> Fmt.string ppf s | Text s | Textj s | Text5 s -> Fmt.pf ppf "\"%s\"" s | Textraw s -> Fmt.pf ppf "%S" s | Array vs -> Fmt.pf ppf "@[[%a]@]" Fmt.(list ~sep:comma pp) vs | Object ms -> let pp_mem ppf (k, v) = Fmt.pf ppf "@[%a:@ %a@]" pp k pp v in Fmt.pf ppf "@[{%a}@]" Fmt.(list ~sep:comma pp_mem) ms