summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSon Ho2021-11-18 14:42:34 +0100
committerSon Ho2021-11-18 14:42:34 +0100
commit6e25ca2831dc61ba61642ad3f80711d0aa2802f2 (patch)
treef8df0fecd6d2a481c3bc0272b98fa75b0a03e61f /src
parent04127f7cd76e22f0f807077144ffbc5bd416e049 (diff)
Factorize the deserialization code a bit
Diffstat (limited to 'src')
-rw-r--r--src/CfimOfJson.ml3
-rw-r--r--src/Identifiers.ml22
2 files changed, 3 insertions, 22 deletions
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]