From 6e25ca2831dc61ba61642ad3f80711d0aa2802f2 Mon Sep 17 00:00:00 2001 From: Son Ho Date: Thu, 18 Nov 2021 14:42:34 +0100 Subject: Factorize the deserialization code a bit --- src/CfimOfJson.ml | 3 +-- src/Identifiers.ml | 22 ++-------------------- 2 files changed, 3 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/CfimOfJson.ml b/src/CfimOfJson.ml index cfe408f7..75d4483e 100644 --- a/src/CfimOfJson.ml +++ b/src/CfimOfJson.ml @@ -11,8 +11,7 @@ open Yojson.Basic open Identifiers open Types - -type json = t +open OfJsonBasic let ( let* ) o f = match o with Error e -> Error e | Ok x -> f x diff --git a/src/Identifiers.ml b/src/Identifiers.ml index 75773312..28ed1909 100644 --- a/src/Identifiers.ml +++ b/src/Identifiers.ml @@ -54,27 +54,9 @@ module IdGen () : Id = struct | `Int i -> Ok i | _ -> Error ("id_of_json: failed on " ^ Yojson.Basic.show js) - let ( let* ) o f = match o with Error e -> Error e | Ok x -> f x - - (* TODO: this duplicates code from CfimToJson *) - let rec of_json_list (a_of_json : Yojson.Basic.t -> ('a, string) result) - (jsl : Yojson.Basic.t list) : ('a list, string) result = - match jsl with - | [] -> Ok [] - | x :: jsl' -> - let* x = a_of_json x in - let* jsl' = of_json_list a_of_json jsl' in - Ok (x :: jsl') - let vector_of_json a_of_json js = - match js with - | `List jsl -> ( - match of_json_list a_of_json jsl with - | Error msg -> - Error - ("vector_of_json failed on: " ^ Yojson.Basic.show js ^ ":\n" ^ msg) - | Ok x -> Ok x) - | _ -> Error ("not a list: " ^ Yojson.Basic.show js) + OfJsonBasic.combine_error_msgs js "vector_of_json" + (OfJsonBasic.list_of_json a_of_json js) end type name = string list [@@deriving yojson] -- cgit v1.2.3