From adcb6233a3241e7855600e5a3a84173d7cc12949 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Mon, 19 Sep 2022 22:23:45 -0400 Subject: [PATCH] feat(ser_value): print --- src/util/ser_value.ml | 14 ++++++++++++++ src/util/ser_value.mli | 2 ++ 2 files changed, 16 insertions(+) diff --git a/src/util/ser_value.ml b/src/util/ser_value.ml index 55eb7060..edb14852 100644 --- a/src/util/ser_value.ml +++ b/src/util/ser_value.ml @@ -1,3 +1,5 @@ +module Fmt = CCFormat + type t = | Bool of bool | Str of string @@ -13,3 +15,15 @@ let bytes x : t = Bytes x let list x : t = List x let dict x : t = Dict x let dict_of_list l = dict (Util.Str_map.of_list l) + +let rec pp out (self : t) = + match self with + | Bool b -> Fmt.bool out b + | Int i -> Fmt.int out i + | Str s -> Fmt.Dump.string out s + | Bytes s -> Fmt.fprintf out "(bytes %S)" s + | List l -> Fmt.Dump.list pp out l + | Dict m -> + Fmt.fprintf out "{@[%a@]}" + (Util.pp_iter ~sep:", " Fmt.Dump.(pair string pp)) + (Util.Str_map.to_iter m) diff --git a/src/util/ser_value.mli b/src/util/ser_value.mli index da5a1aaf..567e4fef 100644 --- a/src/util/ser_value.mli +++ b/src/util/ser_value.mli @@ -21,3 +21,5 @@ val bytes : string -> t val list : t list -> t val dict : t Util.Str_map.t -> t val dict_of_list : (string * t) list -> t + +include Sidekick_sigs.PRINT with type t := t