From b5aa8a5cab2c6de96e36f7241f1b6c856929e114 Mon Sep 17 00:00:00 2001 From: Antonio Nuno Monteiro Date: Wed, 14 Aug 2024 20:24:35 -0700 Subject: [PATCH] remove containers dependency --- dune-project | 6 +++--- melange-json.opam | 1 - ppx/browser/dune | 2 +- ppx/browser/ppx_deriving_json_browser.ml | 20 ++++++++++---------- ppx/native/dune | 2 +- ppx/native/ppx_deriving_json_native.ml | 20 ++++++++++---------- ppx/test/dune | 2 +- tools/ppx_deriving_tools.ml | 24 ++++++++++++------------ 8 files changed, 38 insertions(+), 39 deletions(-) diff --git a/dune-project b/dune-project index d750d4d..903487b 100644 --- a/dune-project +++ b/dune-project @@ -10,7 +10,7 @@ (maintainers "Antonio Nuno Monteiro " - "Javier Ch\195\161varri ") + "Javier Chávarri ") (license "LGPL-3.0-only" "MPL-2.0") @@ -23,7 +23,8 @@ (package (name melange-json) - (synopsis "Compositional JSON encode/decode library and PPX for Melange, with native compatibility") + (synopsis + "Compositional JSON encode/decode library and PPX for Melange, with native compatibility") (description "Provides encoders and decoders to convert JSON values into typed values. With the possibility to create custom encoders and decoders and automate them with a PPX.") (depends @@ -36,7 +37,6 @@ (>= "3.10.0") :with-test)) ppxlib - containers yojson ; only used for the native version (opam-check-npm-deps :with-test) ; todo: use with-dev-setup once opam 2.2 is out (ocaml-lsp-server :with-test) diff --git a/melange-json.opam b/melange-json.opam index f90c359..70b808f 100644 --- a/melange-json.opam +++ b/melange-json.opam @@ -19,7 +19,6 @@ depends: [ "melange-jest" {with-test} "reason" {>= "3.10.0" & with-test} "ppxlib" - "containers" "yojson" "opam-check-npm-deps" {with-test} "ocaml-lsp-server" {with-test} diff --git a/ppx/browser/dune b/ppx/browser/dune index bcabed0..dc2a9f1 100644 --- a/ppx/browser/dune +++ b/ppx/browser/dune @@ -6,7 +6,7 @@ \ ppx_deriving_json_runtime ppx_deriving_json_browser_test) - (libraries ppxlib containers) + (libraries ppxlib) (ppx_runtime_libraries melange-json.browser_runtime) (preprocess (pps ppxlib.metaquot)) diff --git a/ppx/browser/ppx_deriving_json_browser.ml b/ppx/browser/ppx_deriving_json_browser.ml index f055fb1..4be4695 100644 --- a/ppx/browser/ppx_deriving_json_browser.ml +++ b/ppx/browser/ppx_deriving_json_browser.ml @@ -1,5 +1,5 @@ open Printf -open ContainersLabels +open StdLabels open Ppxlib open Ast_builder.Default open Ppx_deriving_tools @@ -16,7 +16,7 @@ module Of_json = struct let build_js_type ~loc (fs : label_declaration list) = let f ld = let n = ld.pld_name in - let n = Option.get_or ~default:n (ld_attr_json_key ld) in + let n = Option.value ~default:n (ld_attr_json_key ld) in let pof_desc = Otag (n, [%type: Js.Json.t Js.undefined]) in { pof_loc = loc; pof_attributes = []; pof_desc } in @@ -27,7 +27,7 @@ module Of_json = struct let handle_field fs ld = ( map_loc lident ld.pld_name, let n = ld.pld_name in - let n = Option.get_or ~default:n (ld_attr_json_key ld) in + let n = Option.value ~default:n (ld_attr_json_key ld) in [%expr match Js.Undefined.toOption @@ -133,13 +133,13 @@ module Of_json = struct match c with | Vcs_enum (n, ctx) -> let loc = n.loc in - let n = Option.get_or ~default:n (vcs_attr_json_as ctx) in + let n = Option.value ~default:n (vcs_attr_json_as ctx) in [%expr if tag = [%e estring ~loc:n.loc n.txt] then [%e make None] else [%e next]] | Vcs_record (n, r) -> let loc = n.loc in - let n = Option.get_or ~default:n (vcs_attr_json_as r.rcd_ctx) in + let n = Option.value ~default:n (vcs_attr_json_as r.rcd_ctx) in [%expr if tag = [%e estring ~loc:n.loc n.txt] then ( [%e ensure_json_array_len ~loc 2 [%expr len]]; @@ -151,7 +151,7 @@ module Of_json = struct else [%e next]] | Vcs_tuple (n, t) -> let loc = n.loc in - let n = Option.get_or ~default:n (vcs_attr_json_as t.tpl_ctx) in + let n = Option.value ~default:n (vcs_attr_json_as t.tpl_ctx) in let arity = List.length t.tpl_types in [%expr if tag = [%e estring ~loc:n.loc n.txt] then ( @@ -185,7 +185,7 @@ module To_json = struct let fs = List.map2 t.rcd_fields es ~f:(fun ld x -> let n = ld.pld_name in - let n = Option.get_or ~default:n (ld_attr_json_key ld) in + let n = Option.value ~default:n (ld_attr_json_key ld) in let this = derive ld.pld_type x in map_loc lident n, this) in @@ -196,18 +196,18 @@ module To_json = struct match c with | Vcs_enum (n, ctx) -> let loc = n.loc in - let n = Option.get_or ~default:n (vcs_attr_json_as ctx) in + let n = Option.value ~default:n (vcs_attr_json_as ctx) in let tag = [%expr string_to_json [%e estring ~loc:n.loc n.txt]] in as_json ~loc tag | Vcs_record (n, r) -> let loc = n.loc in - let n = Option.get_or ~default:n (vcs_attr_json_as r.rcd_ctx) in + let n = Option.value ~default:n (vcs_attr_json_as r.rcd_ctx) in let tag = [%expr string_to_json [%e estring ~loc:n.loc n.txt]] in let es = [ derive_of_record derive r es ] in as_json ~loc (pexp_array ~loc (tag :: es)) | Vcs_tuple (n, t) -> let loc = n.loc in - let n = Option.get_or ~default:n (vcs_attr_json_as t.tpl_ctx) in + let n = Option.value ~default:n (vcs_attr_json_as t.tpl_ctx) in let tag = [%expr string_to_json [%e estring ~loc:n.loc n.txt]] in let es = List.map2 t.tpl_types es ~f:derive in as_json ~loc (pexp_array ~loc (tag :: es)) diff --git a/ppx/native/dune b/ppx/native/dune index 797cda5..0fafd3a 100644 --- a/ppx/native/dune +++ b/ppx/native/dune @@ -6,7 +6,7 @@ \ ppx_deriving_json_runtime ppx_deriving_json_native_test) - (libraries ppxlib containers) + (libraries ppxlib) (ppx_runtime_libraries melange-json.native_runtime) (preprocess (pps ppxlib.metaquot)) diff --git a/ppx/native/ppx_deriving_json_native.ml b/ppx/native/ppx_deriving_json_native.ml index 14147f1..44cd069 100644 --- a/ppx/native/ppx_deriving_json_native.ml +++ b/ppx/native/ppx_deriving_json_native.ml @@ -1,5 +1,5 @@ open Printf -open ContainersLabels +open StdLabels open Ppxlib open Ast_builder.Default open Ppx_deriving_tools @@ -54,7 +54,7 @@ module Of_json = struct List.fold_left (List.rev fs) ~init:[ fail_case ] ~f:(fun next ld -> let key = - Option.get_or ~default:ld.pld_name (ld_attr_json_key ld) + Option.value ~default:ld.pld_name (ld_attr_json_key ld) in pstring ~loc:key.loc key.txt --> [%expr @@ -68,7 +68,7 @@ module Of_json = struct let fields = List.map fs ~f:(fun ld -> let key = - Option.get_or ~default:ld.pld_name (ld_attr_json_key ld) + Option.value ~default:ld.pld_name (ld_attr_json_key ld) in let default = ld_attr_default ld in ( map_loc lident ld.pld_name, @@ -135,11 +135,11 @@ module Of_json = struct match vcs with | Vcs_enum (n, ctx) -> let loc = n.loc in - let n = Option.get_or ~default:n (vcs_attr_json_as ctx) in + let n = Option.value ~default:n (vcs_attr_json_as ctx) in [%pat? `String [%p pstring ~loc:n.loc n.txt]] --> make None | Vcs_tuple (n, t) -> let loc = n.loc in - let n = Option.get_or ~default:n (vcs_attr_json_as t.tpl_ctx) in + let n = Option.value ~default:n (vcs_attr_json_as t.tpl_ctx) in let arity = List.length t.tpl_types in if arity = 0 then [%pat? `List [ `String [%p pstring ~loc:n.loc n.txt] ]] @@ -151,7 +151,7 @@ module Of_json = struct --> make (Some (build_tuple ~loc derive xexprs t.tpl_types)) | Vcs_record (n, t) -> let loc = n.loc in - let n = Option.get_or ~default:n (vcs_attr_json_as t.rcd_ctx) in + let n = Option.value ~default:n (vcs_attr_json_as t.rcd_ctx) in let allow_extra_fields = match t.rcd_ctx with | Vcs_ctx_variant cd -> @@ -181,7 +181,7 @@ module To_json = struct let es = List.map2 t.rcd_fields es ~f:(fun ld x -> let key = - Option.get_or ~default:ld.pld_name (ld_attr_json_key ld) + Option.value ~default:ld.pld_name (ld_attr_json_key ld) in [%expr [%e estring ~loc:key.loc key.txt], [%e derive ld.pld_type x]]) @@ -192,18 +192,18 @@ module To_json = struct match vcs with | Vcs_enum (n, ctx) -> let loc = n.loc in - let n = Option.get_or ~default:n (vcs_attr_json_as ctx) in + let n = Option.value ~default:n (vcs_attr_json_as ctx) in [%expr `String [%e estring ~loc:n.loc n.txt]] | Vcs_tuple (n, t) -> let loc = n.loc in - let n = Option.get_or ~default:n (vcs_attr_json_as t.tpl_ctx) in + let n = Option.value ~default:n (vcs_attr_json_as t.tpl_ctx) in [%expr `List (`String [%e estring ~loc:n.loc n.txt] :: [%e elist ~loc (List.map2 t.tpl_types es ~f:derive)])] | Vcs_record (n, t) -> let loc = n.loc in - let n = Option.get_or ~default:n (vcs_attr_json_as t.rcd_ctx) in + let n = Option.value ~default:n (vcs_attr_json_as t.rcd_ctx) in [%expr `List (`String [%e estring ~loc:n.loc n.txt] diff --git a/ppx/test/dune b/ppx/test/dune index 875e696..ffada2c 100644 --- a/ppx/test/dune +++ b/ppx/test/dune @@ -1,6 +1,6 @@ (cram (deps - (package ppx_deriving_json) + (package melange-json) ./example.ml ../../.ocamlformat ../native/ppx_deriving_json_native_test.exe diff --git a/tools/ppx_deriving_tools.ml b/tools/ppx_deriving_tools.ml index 55567d6..50844f0 100644 --- a/tools/ppx_deriving_tools.ml +++ b/tools/ppx_deriving_tools.ml @@ -1,7 +1,7 @@ open Printf open Ppxlib open Ast_builder.Default -open ContainersLabels +open StdLabels open Expansion_helpers exception Error of location * string @@ -19,7 +19,7 @@ let map_loc f a_loc = { a_loc with txt = f a_loc.txt } let gen_bindings ~loc prefix n = List.split - (List.init n ~f:(fun i -> + (List.init ~len:n ~f:(fun i -> let id = sprintf "%s_%i" prefix i in let patt = ppat_var ~loc { loc; txt = id } in let expr = pexp_ident ~loc { loc; txt = lident id } in @@ -250,7 +250,7 @@ module Schema = struct fun ~ctxt (_rec_flag, type_decls) -> let loc = Expansion_context.Deriver.derived_item_loc ctxt in let bindings = - List.flat_map type_decls ~f:(fun decl -> + List.concat_map type_decls ~f:(fun decl -> self#derive_of_type_declaration decl) in [%str @@ -376,7 +376,7 @@ module Schema = struct fun ~ctxt (_rec_flag, tds) -> let loc = Expansion_context.Deriver.derived_item_loc ctxt in let bindings = - List.flat_map tds ~f:self#derive_of_type_declaration + List.concat_map tds ~f:self#derive_of_type_declaration in [%str [@@@ocaml.warning "-39-11-27"] @@ -689,17 +689,17 @@ module Conv = struct let loc = t.ptyp_loc in let is_enum, cases = repr_polyvariant_cases cs in let ctors, inherits = - List.partition_filter_map cases ~f:(fun (c, r) -> + List.partition_map cases ~f:(fun (c, r) -> let ctx = Vcs_ctx_polyvariant c in match r with | `Rtag (n, ts) -> - if is_enum then `Left (n, Vcs_enum (n, ctx)) + if is_enum then Left (n, Vcs_enum (n, ctx)) else let t = { tpl_loc = loc; tpl_types = ts; tpl_ctx = ctx } in - `Left (n, Vcs_tuple (n, t)) - | `Rinherit (n, ts) -> `Right (n, ts)) + Left (n, Vcs_tuple (n, t)) + | `Rinherit (n, ts) -> Right (n, ts)) in let catch_all = [%pat? x] @@ -785,17 +785,17 @@ module Conv = struct let loc = t.ptyp_loc in let is_enum, cases = repr_polyvariant_cases cs in let ctors, inherits = - List.partition_filter_map cases ~f:(fun (c, r) -> + List.partition_map cases ~f:(fun (c, r) -> let ctx = Vcs_ctx_polyvariant c in match r with | `Rtag (n, ts) -> - if is_enum then `Left (n, Vcs_enum (n, ctx)) + if is_enum then Left (n, Vcs_enum (n, ctx)) else let t = { tpl_loc = loc; tpl_types = ts; tpl_ctx = ctx } in - `Left (n, Vcs_tuple (n, t)) - | `Rinherit (n, ts) -> `Right (n, ts)) + Left (n, Vcs_tuple (n, t)) + | `Rinherit (n, ts) -> Right (n, ts)) in let catch_all = [%pat? x]