pax_global_header00006660000000000000000000000064146164733610014525gustar00rootroot0000000000000052 comment=2df54d4a254d54750b8c4b851c78e39785a11cfc ppx_yojson_conv_lib-0.17.0/000077500000000000000000000000001461647336100156755ustar00rootroot00000000000000ppx_yojson_conv_lib-0.17.0/.gitignore000066400000000000000000000000411461647336100176600ustar00rootroot00000000000000_build *.install *.merlin _opam ppx_yojson_conv_lib-0.17.0/.ocamlformat000066400000000000000000000000231461647336100201750ustar00rootroot00000000000000profile=janestreet ppx_yojson_conv_lib-0.17.0/CONTRIBUTING.md000066400000000000000000000044101461647336100201250ustar00rootroot00000000000000This repository contains open source software that is developed and maintained by [Jane Street][js]. Contributions to this project are welcome and should be submitted via GitHub pull requests. Signing contributions --------------------- We require that you sign your contributions. Your signature certifies that you wrote the patch or otherwise have the right to pass it on as an open-source patch. The rules are pretty simple: if you can certify the below (from [developercertificate.org][dco]): ``` Developer Certificate of Origin Version 1.1 Copyright (C) 2004, 2006 The Linux Foundation and its contributors. 1 Letterman Drive Suite D4700 San Francisco, CA, 94129 Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Developer's Certificate of Origin 1.1 By making a contribution to this project, I certify that: (a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or (b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or (c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it. (d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved. ``` Then you just add a line to every git commit message: ``` Signed-off-by: Joe Smith ``` Use your real name (sorry, no pseudonyms or anonymous contributions.) If you set your `user.name` and `user.email` git configs, you can sign your commit automatically with git commit -s. [dco]: http://developercertificate.org/ [js]: https://opensource.janestreet.com/ ppx_yojson_conv_lib-0.17.0/LICENSE.md000066400000000000000000000021461461647336100173040ustar00rootroot00000000000000The MIT License Copyright (c) 2019--2024 Jane Street Group, LLC Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ppx_yojson_conv_lib-0.17.0/Makefile000066400000000000000000000004031461647336100173320ustar00rootroot00000000000000INSTALL_ARGS := $(if $(PREFIX),--prefix $(PREFIX),) default: dune build install: dune install $(INSTALL_ARGS) uninstall: dune uninstall $(INSTALL_ARGS) reinstall: uninstall install clean: dune clean .PHONY: default install uninstall reinstall clean ppx_yojson_conv_lib-0.17.0/dune000066400000000000000000000001741461647336100165550ustar00rootroot00000000000000(library (name ppx_yojson_conv_lib) (public_name ppx_yojson_conv_lib) (libraries yojson) (preprocess no_preprocessing)) ppx_yojson_conv_lib-0.17.0/dune-project000066400000000000000000000000211461647336100202100ustar00rootroot00000000000000(lang dune 3.11) ppx_yojson_conv_lib-0.17.0/ppx_yojson_conv_lib.ml000066400000000000000000000005361461647336100223160ustar00rootroot00000000000000module Yojson_conv_error = Yojson_conv_error module Yojson_conv = Yojson_conv module Yojsonable = Yojsonable_intf module Yojson = Yojson module Option = struct type 'a t = 'a option = | None | Some of 'a end external ignore : _ -> unit = "%ignore" external poly_equal : 'a -> 'a -> bool = "%equal" let ( ! ) : 'a ref -> 'a = fun x -> !x ppx_yojson_conv_lib-0.17.0/ppx_yojson_conv_lib.opam000066400000000000000000000013131461647336100226340ustar00rootroot00000000000000opam-version: "2.0" version: "v0.17.0" maintainer: "Jane Street developers" authors: ["Jane Street Group, LLC"] homepage: "https://github.com/janestreet/ppx_yojson_conv_lib" bug-reports: "https://github.com/janestreet/ppx_yojson_conv_lib/issues" dev-repo: "git+https://github.com/janestreet/ppx_yojson_conv_lib.git" doc: "https://ocaml.janestreet.com/ocaml-core/latest/doc/ppx_yojson_conv_lib/index.html" license: "MIT" build: [ ["dune" "build" "-p" name "-j" jobs] ] depends: [ "ocaml" {>= "5.1.0"} "dune" {>= "3.11.0"} "yojson" {>= "1.7.0"} ] available: arch != "arm32" & arch != "x86_32" synopsis: "Runtime lib for ppx_yojson_conv" description: " Part of the Jane Street's PPX rewriters collection. " ppx_yojson_conv_lib-0.17.0/yojson_conv.ml000066400000000000000000000157321461647336100206050ustar00rootroot00000000000000open StdLabels open MoreLabels open! Yojson type t = Yojson.Safe.t let yojson_of_unit () : t = `Null let yojson_of_bool b : t = `Bool b let yojson_of_string str : t = `String str let yojson_of_bytes bytes : t = `String (Bytes.to_string bytes) let yojson_of_char c : t = `String (String.make 1 c) let yojson_of_int n : t = `Int n let yojson_of_float n : t = `Float n let yojson_of_int32 (n : Int32.t) : t = `Intlit (Int32.to_string n) let yojson_of_int64 (n : Int64.t) : t = `Intlit (Int64.to_string n) let yojson_of_nativeint n : t = `Intlit (Nativeint.to_string n) let yojson_of_ref yojson_of__a rf = yojson_of__a !rf let yojson_of_lazy_t yojson_of__a lv = yojson_of__a (Lazy.force lv) let yojson_of_option yojson_of__a = function | Some x -> yojson_of__a x | None -> `Null ;; let yojson_of_pair yojson_of__a yojson_of__b (a, b) = `List [ yojson_of__a a; yojson_of__b b ] ;; let yojson_of_triple yojson_of__a yojson_of__b yojson_of__c (a, b, c) = `List [ yojson_of__a a; yojson_of__b b; yojson_of__c c ] ;; (* List.rev (List.rev_map ...) is tail recursive, the OCaml standard library List.map is NOT. *) let yojson_of_list yojson_of__a lst = `List (List.rev (List.rev_map ~f:yojson_of__a lst)) let yojson_of_array yojson_of__a ar = let lst_ref = ref [] in for i = Array.length ar - 1 downto 0 do lst_ref := yojson_of__a ar.(i) :: !lst_ref done; `List !lst_ref ;; let yojson_of_hashtbl yojson_of_key yojson_of_val htbl = let coll ~key:k ~data:v acc = `List [ yojson_of_key k; yojson_of_val v ] :: acc in `List (Hashtbl.fold htbl ~init:[] ~f:coll) ;; let yojson_of_opaque _ = `String "" let yojson_of_fun _ = `String "" exception Of_yojson_error of exn * t let record_check_extra_fields = ref true let of_yojson_error_exn exc yojson = raise (Of_yojson_error (exc, yojson)) let of_yojson_error what yojson = raise (Of_yojson_error (Failure what, yojson)) let unit_of_yojson yojson = match yojson with | `Null -> () | _ -> of_yojson_error "unit_of_yojson: `Null needed" yojson ;; let bool_of_yojson yojson = match yojson with | `Bool v -> v | _ -> of_yojson_error "bool_of_yojson: true/false needed" yojson ;; let string_of_yojson yojson = match yojson with | `String str -> str | _ -> of_yojson_error "string_of_yojson: string needed" yojson ;; let bytes_of_yojson yojson = match yojson with | `String str -> Bytes.of_string str | _ -> of_yojson_error "bytes_of_yojson: string needed" yojson ;; let char_of_yojson yojson = match yojson with | `String str -> if String.length str <> 1 then of_yojson_error "char_of_yojson: string must contain one character only" yojson; str.[0] | _ -> of_yojson_error "char_of_yojson: string of size one needed" yojson ;; let int_of_yojson yojson = match yojson with | `Int v -> v | _ -> of_yojson_error "int_of_yojson: integer needed" yojson ;; let float_of_yojson yojson = match yojson with | `Float v -> v | `Int i -> float_of_int i | `Intlit str -> float_of_string str | _ -> of_yojson_error "float_of_yojson: float needed" yojson ;; let int32_of_yojson yojson = match yojson with | `Intlit str -> Int32.of_string str | `Int v -> Int32.of_int v | _ -> of_yojson_error "int32_of_yojson: integer needed" yojson ;; let int64_of_yojson yojson = match yojson with | `Intlit str -> Int64.of_string str | `Int v -> Int64.of_int v | _ -> of_yojson_error "int64_of_yojson: integer needed" yojson ;; let nativeint_of_yojson yojson = match yojson with | `Intlit str -> Nativeint.of_string str | `Int v -> Nativeint.of_int v | _ -> of_yojson_error "nativeint_of_yojson: integer needed" yojson ;; let ref_of_yojson a__of_yojson yojson = ref (a__of_yojson yojson) let lazy_t_of_yojson a__of_yojson yojson = Lazy.from_val (a__of_yojson yojson) let option_of_yojson a__of_yojson yojson = match yojson with | `Null -> None | el -> Some (a__of_yojson el) ;; let pair_of_yojson a__of_yojson b__of_yojson yojson = match yojson with | `List [ a_yojson; b_yojson ] -> let a = a__of_yojson a_yojson in let b = b__of_yojson b_yojson in a, b | _ -> of_yojson_error "pair_of_yojson: invalid format" yojson ;; let triple_of_yojson a__of_yojson b__of_yojson c__of_yojson yojson = match yojson with | `List [ a_yojson; b_yojson; c_yojson ] -> let a = a__of_yojson a_yojson in let b = b__of_yojson b_yojson in let c = c__of_yojson c_yojson in a, b, c | _ -> of_yojson_error "triple_of_yojson: invalid format" yojson ;; let list_of_yojson a__of_yojson yojson = match yojson with | `List lst -> let rev_lst = List.rev_map lst ~f:a__of_yojson in List.rev rev_lst | _ -> of_yojson_error "list_of_yojson: list needed" yojson ;; let array_of_yojson a__of_yojson yojson = match yojson with | `List [] -> [||] | `List (h :: t) -> let len = List.length t + 1 in let res = Array.make len (a__of_yojson h) in let rec loop i = function | [] -> res | h :: t -> res.(i) <- a__of_yojson h; loop (i + 1) t in loop 1 t | _ -> of_yojson_error "array_of_yojson: list needed" yojson ;; let hashtbl_of_yojson key_of_yojson val_of_yojson yojson = match yojson with | `List lst -> let htbl = Hashtbl.create 0 in let act = function | `List [ k_yojson; v_yojson ] -> Hashtbl.add htbl ~key:(key_of_yojson k_yojson) ~data:(val_of_yojson v_yojson) | _ -> of_yojson_error "hashtbl_of_yojson: tuple list needed" yojson in List.iter lst ~f:act; htbl | _ -> of_yojson_error "hashtbl_of_yojson: list needed" yojson ;; let opaque_of_yojson yojson = of_yojson_error "opaque_of_yojson: cannot convert opaque values" yojson ;; let fun_of_yojson yojson = of_yojson_error "fun_of_yojson: cannot convert function values" yojson ;; module Primitives = struct let yojson_of_array = yojson_of_array let array_of_yojson = array_of_yojson let yojson_of_bool = yojson_of_bool let bool_of_yojson = bool_of_yojson let yojson_of_char = yojson_of_char let char_of_yojson = char_of_yojson let yojson_of_float = yojson_of_float let float_of_yojson = float_of_yojson let yojson_of_int = yojson_of_int let int_of_yojson = int_of_yojson let yojson_of_int32 = yojson_of_int32 let int32_of_yojson = int32_of_yojson let yojson_of_int64 = yojson_of_int64 let int64_of_yojson = int64_of_yojson let yojson_of_list = yojson_of_list let list_of_yojson = list_of_yojson let yojson_of_nativeint = yojson_of_nativeint let nativeint_of_yojson = nativeint_of_yojson let yojson_of_option = yojson_of_option let option_of_yojson = option_of_yojson let yojson_of_ref = yojson_of_ref let ref_of_yojson = ref_of_yojson let yojson_of_string = yojson_of_string let string_of_yojson = string_of_yojson let yojson_of_bytes = yojson_of_bytes let bytes_of_yojson = bytes_of_yojson let yojson_of_unit = yojson_of_unit let unit_of_yojson = unit_of_yojson let yojson_of_lazy_t = yojson_of_lazy_t let lazy_t_of_yojson = lazy_t_of_yojson let yojson_of_hashtbl = yojson_of_hashtbl let hashtbl_of_yojson = hashtbl_of_yojson end ppx_yojson_conv_lib-0.17.0/yojson_conv.mli000066400000000000000000000247541461647336100207620ustar00rootroot00000000000000(** Utility Module for Yojson Conversions *) (** {6 Conversion of OCaml-values to Yojsons} *) (** [yojson_of_unit ()] converts a value of type [unit] to an Yojson. *) val yojson_of_unit : unit -> Yojson.Safe.t (** [yojson_of_bool b] converts the value [b] of type [bool] to an Yojson. *) val yojson_of_bool : bool -> Yojson.Safe.t (** [yojson_of_string str] converts the value [str] of type [string] to an Yojson. *) val yojson_of_string : string -> Yojson.Safe.t (** [yojson_of_bytes str] converts the value [str] of type [bytes] to an Yojson. *) val yojson_of_bytes : bytes -> Yojson.Safe.t (** [yojson_of_char c] converts the value [c] of type [char] to an Yojson. *) val yojson_of_char : char -> Yojson.Safe.t (** [yojson_of_int n] converts the value [n] of type [int] to an Yojson. *) val yojson_of_int : int -> Yojson.Safe.t (** [yojson_of_float n] converts the value [n] of type [float] to an Yojson. *) val yojson_of_float : float -> Yojson.Safe.t (** [yojson_of_int32 n] converts the value [n] of type [int32] to an Yojson. *) val yojson_of_int32 : int32 -> Yojson.Safe.t (** [yojson_of_int64 n] converts the value [n] of type [int64] to an Yojson. *) val yojson_of_int64 : int64 -> Yojson.Safe.t (** [yojson_of_nativeint n] converts the value [n] of type [nativeint] to an Yojson. *) val yojson_of_nativeint : nativeint -> Yojson.Safe.t (** [yojson_of_ref conv r] converts the value [r] of type ['a ref] to an Yojson. Uses [conv] to convert values of type ['a] to an Yojson. *) val yojson_of_ref : ('a -> Yojson.Safe.t) -> 'a ref -> Yojson.Safe.t (** [yojson_of_lazy_t conv l] converts the value [l] of type ['a lazy_t] to an Yojson. Uses [conv] to convert values of type ['a] to an Yojson. *) val yojson_of_lazy_t : ('a -> Yojson.Safe.t) -> 'a lazy_t -> Yojson.Safe.t (** [yojson_of_option conv opt] converts the value [opt] of type ['a option] to an Yojson. Uses [conv] to convert values of type ['a] to an Yojson. *) val yojson_of_option : ('a -> Yojson.Safe.t) -> 'a option -> Yojson.Safe.t (** [yojson_of_pair conv1 conv2 pair] converts a pair to an Yojson. It uses its first argument to convert the first element of the pair, and its second argument to convert the second element of the pair. *) val yojson_of_pair : ('a -> Yojson.Safe.t) -> ('b -> Yojson.Safe.t) -> 'a * 'b -> Yojson.Safe.t (** [yojson_of_triple conv1 conv2 conv3 triple] converts a triple to an Yojson using [conv1], [conv2], and [conv3] to convert its elements. *) val yojson_of_triple : ('a -> Yojson.Safe.t) -> ('b -> Yojson.Safe.t) -> ('c -> Yojson.Safe.t) -> 'a * 'b * 'c -> Yojson.Safe.t (** [yojson_of_list conv lst] converts the value [lst] of type ['a list] to an Yojson. Uses [conv] to convert values of type ['a] to an Yojson. *) val yojson_of_list : ('a -> Yojson.Safe.t) -> 'a list -> Yojson.Safe.t (** [yojson_of_array conv ar] converts the value [ar] of type ['a array] to an Yojson. Uses [conv] to convert values of type ['a] to an Yojson. *) val yojson_of_array : ('a -> Yojson.Safe.t) -> 'a array -> Yojson.Safe.t (** [yojson_of_hashtbl conv_key conv_value htbl] converts the value [htbl] of type [('a, 'b) Hashtbl.t] to an Yojson. Uses [conv_key] to convert the hashtable keys of type ['a], and [conv_value] to convert hashtable values of type ['b] to Yojsons. *) val yojson_of_hashtbl : ('a -> Yojson.Safe.t) -> ('b -> Yojson.Safe.t) -> ('a, 'b) Hashtbl.t -> Yojson.Safe.t (** [yojson_of_opaque x] converts the value [x] of opaque type to an Yojson. This means the user need not provide converters, but the result cannot be interpreted. *) val yojson_of_opaque : 'a -> Yojson.Safe.t (** [yojson_of_fun f] converts the value [f] of function type to a dummy Yojson. Functions cannot be serialized as Yojsons, but at least a placeholder can be generated for pretty-printing. *) val yojson_of_fun : ('a -> 'b) -> Yojson.Safe.t (** {6 Conversion of Yojsons to OCaml-values} *) (** [Of_yojson_error (exn, yojson)] the exception raised when an Yojson could not be successfully converted to an OCaml-value. *) exception Of_yojson_error of exn * Yojson.Safe.t (** [record_check_extra_fields] checks for extra (= unknown) fields in record Yojsons. *) val record_check_extra_fields : bool ref (** [of_yojson_error reason yojson] @raise Of_yojson_error (Failure reason, yojson). *) val of_yojson_error : string -> Yojson.Safe.t -> 'a (** [of_yojson_error_exn exc yojson] @raise Of_yojson_error (exc, yojson). *) val of_yojson_error_exn : exn -> Yojson.Safe.t -> 'a (** [unit_of_yojson yojson] converts Yojson [yojson] to a value of type [unit]. *) val unit_of_yojson : Yojson.Safe.t -> unit (** [bool_of_yojson yojson] converts Yojson [yojson] to a value of type [bool]. *) val bool_of_yojson : Yojson.Safe.t -> bool (** [string_of_yojson yojson] converts Yojson [yojson] to a value of type [string]. *) val string_of_yojson : Yojson.Safe.t -> string (** [bytes_of_yojson yojson] converts Yojson [yojson] to a value of type [bytes]. *) val bytes_of_yojson : Yojson.Safe.t -> bytes (** [char_of_yojson yojson] converts Yojson [yojson] to a value of type [char]. *) val char_of_yojson : Yojson.Safe.t -> char (** [int_of_yojson yojson] converts Yojson [yojson] to a value of type [int]. *) val int_of_yojson : Yojson.Safe.t -> int (** [float_of_yojson yojson] converts Yojson [yojson] to a value of type [float]. *) val float_of_yojson : Yojson.Safe.t -> float (** [int32_of_yojson yojson] converts Yojson [yojson] to a value of type [int32]. *) val int32_of_yojson : Yojson.Safe.t -> int32 (** [int64_of_yojson yojson] converts Yojson [yojson] to a value of type [int64]. *) val int64_of_yojson : Yojson.Safe.t -> int64 (** [nativeint_of_yojson yojson] converts Yojson [yojson] to a value of type [nativeint]. *) val nativeint_of_yojson : Yojson.Safe.t -> nativeint (** [ref_of_yojson conv yojson] converts Yojson [yojson] to a value of type ['a ref] using conversion function [conv], which converts an Yojson to a value of type ['a]. *) val ref_of_yojson : (Yojson.Safe.t -> 'a) -> Yojson.Safe.t -> 'a ref (** [lazy_t_of_yojson conv yojson] converts Yojson [yojson] to a value of type ['a lazy_t] using conversion function [conv], which converts an Yojson to a value of type ['a]. *) val lazy_t_of_yojson : (Yojson.Safe.t -> 'a) -> Yojson.Safe.t -> 'a lazy_t (** [option_of_yojson conv yojson] converts Yojson [yojson] to a value of type ['a option] using conversion function [conv], which converts an Yojson to a value of type ['a]. *) val option_of_yojson : (Yojson.Safe.t -> 'a) -> Yojson.Safe.t -> 'a option (** [pair_of_yojson conv1 conv2 yojson] converts Yojson [yojson] to a pair of type ['a * 'b] using conversion functions [conv1] and [conv2], which convert Yojsons to values of type ['a] and ['b] respectively. *) val pair_of_yojson : (Yojson.Safe.t -> 'a) -> (Yojson.Safe.t -> 'b) -> Yojson.Safe.t -> 'a * 'b (** [triple_of_yojson conv1 conv2 conv3 yojson] converts Yojson [yojson] to a triple of type ['a * 'b * 'c] using conversion functions [conv1], [conv2], and [conv3], which convert Yojsons to values of type ['a], ['b], and ['c] respectively. *) val triple_of_yojson : (Yojson.Safe.t -> 'a) -> (Yojson.Safe.t -> 'b) -> (Yojson.Safe.t -> 'c) -> Yojson.Safe.t -> 'a * 'b * 'c (** [list_of_yojson conv yojson] converts Yojson [yojson] to a value of type ['a list] using conversion function [conv], which converts an Yojson to a value of type ['a]. *) val list_of_yojson : (Yojson.Safe.t -> 'a) -> Yojson.Safe.t -> 'a list (** [array_of_yojson conv yojson] converts Yojson [yojson] to a value of type ['a array] using conversion function [conv], which converts an Yojson to a value of type ['a]. *) val array_of_yojson : (Yojson.Safe.t -> 'a) -> Yojson.Safe.t -> 'a array (** [hashtbl_of_yojson conv_key conv_value yojson] converts Yojson [yojson] to a value of type [('a, 'b) Hashtbl.t] using conversion function [conv_key], which converts an Yojson to hashtable key of type ['a], and function [conv_value], which converts an Yojson to hashtable value of type ['b]. *) val hashtbl_of_yojson : (Yojson.Safe.t -> 'a) -> (Yojson.Safe.t -> 'b) -> Yojson.Safe.t -> ('a, 'b) Hashtbl.t (** [opaque_of_yojson yojson] @raise Of_yojson_error when attempting to convert an Yojson to an opaque value. *) val opaque_of_yojson : Yojson.Safe.t -> 'a (** [fun_of_yojson yojson] @raise Of_yojson_error when attempting to convert an Yojson to a function. *) val fun_of_yojson : Yojson.Safe.t -> 'a module Primitives : sig val yojson_of_unit : unit -> Yojson.Safe.t val yojson_of_bool : bool -> Yojson.Safe.t val yojson_of_string : string -> Yojson.Safe.t val yojson_of_bytes : bytes -> Yojson.Safe.t val yojson_of_char : char -> Yojson.Safe.t val yojson_of_int : int -> Yojson.Safe.t val yojson_of_float : float -> Yojson.Safe.t val yojson_of_int32 : int32 -> Yojson.Safe.t val yojson_of_int64 : int64 -> Yojson.Safe.t val yojson_of_nativeint : nativeint -> Yojson.Safe.t val yojson_of_ref : ('a -> Yojson.Safe.t) -> 'a ref -> Yojson.Safe.t val yojson_of_lazy_t : ('a -> Yojson.Safe.t) -> 'a lazy_t -> Yojson.Safe.t val yojson_of_option : ('a -> Yojson.Safe.t) -> 'a option -> Yojson.Safe.t val yojson_of_list : ('a -> Yojson.Safe.t) -> 'a list -> Yojson.Safe.t val yojson_of_array : ('a -> Yojson.Safe.t) -> 'a array -> Yojson.Safe.t val yojson_of_hashtbl : ('a -> Yojson.Safe.t) -> ('b -> Yojson.Safe.t) -> ('a, 'b) Hashtbl.t -> Yojson.Safe.t val unit_of_yojson : Yojson.Safe.t -> unit val bool_of_yojson : Yojson.Safe.t -> bool val string_of_yojson : Yojson.Safe.t -> string val bytes_of_yojson : Yojson.Safe.t -> bytes val char_of_yojson : Yojson.Safe.t -> char val int_of_yojson : Yojson.Safe.t -> int val float_of_yojson : Yojson.Safe.t -> float val int32_of_yojson : Yojson.Safe.t -> int32 val int64_of_yojson : Yojson.Safe.t -> int64 val nativeint_of_yojson : Yojson.Safe.t -> nativeint val ref_of_yojson : (Yojson.Safe.t -> 'a) -> Yojson.Safe.t -> 'a ref val lazy_t_of_yojson : (Yojson.Safe.t -> 'a) -> Yojson.Safe.t -> 'a lazy_t val option_of_yojson : (Yojson.Safe.t -> 'a) -> Yojson.Safe.t -> 'a option val list_of_yojson : (Yojson.Safe.t -> 'a) -> Yojson.Safe.t -> 'a list val array_of_yojson : (Yojson.Safe.t -> 'a) -> Yojson.Safe.t -> 'a array val hashtbl_of_yojson : (Yojson.Safe.t -> 'a) -> (Yojson.Safe.t -> 'b) -> Yojson.Safe.t -> ('a, 'b) Hashtbl.t end ppx_yojson_conv_lib-0.17.0/yojson_conv_error.ml000066400000000000000000000070731461647336100220150ustar00rootroot00000000000000(* Conv_error: Module for Handling Errors during Automated Yojson Conversions *) open! StdLabels open Yojson_conv let sprintf = Printf.sprintf (* Errors concerning tuples *) let tuple_of_size_n_expected loc n yojson = of_yojson_error (sprintf "%s_of_yojson: tuple of size %d expected" loc n) yojson ;; (* Errors concerning sum types *) let stag_no_args loc yojson = of_yojson_error (loc ^ "_of_yojson: this constructor does not take arguments") yojson ;; let stag_incorrect_n_args loc tag yojson = let msg = sprintf "%s_of_yojson: sum tag %S has incorrect number of arguments" loc tag in of_yojson_error msg yojson ;; let stag_takes_args loc yojson = of_yojson_error (loc ^ "_of_yojson: this constructor requires arguments") yojson ;; let nested_list_invalid_sum loc yojson = of_yojson_error (loc ^ "_of_yojson: expected a variant type, saw a nested list") yojson ;; let empty_list_invalid_sum loc yojson = of_yojson_error (loc ^ "_of_yojson: expected a variant type, saw an empty list") yojson ;; let unexpected_stag loc yojson = of_yojson_error (loc ^ "_of_yojson: unexpected variant constructor") yojson ;; (* Errors concerning records *) let record_superfluous_fields ~what ~loc rev_fld_names yojson = let fld_names_str = String.concat (List.rev rev_fld_names) ~sep:" " in let msg = sprintf "%s_of_yojson: %s: %s" loc what fld_names_str in of_yojson_error msg yojson ;; let record_duplicate_fields loc rev_fld_names yojson = record_superfluous_fields ~what:"duplicate fields" ~loc rev_fld_names yojson ;; let record_extra_fields loc rev_fld_names yojson = record_superfluous_fields ~what:"extra fields" ~loc rev_fld_names yojson ;; let rec record_get_undefined_loop fields = function | [] -> String.concat (List.rev fields) ~sep:" " | (true, field) :: rest -> record_get_undefined_loop (field :: fields) rest | _ :: rest -> record_get_undefined_loop fields rest ;; let record_undefined_elements loc yojson lst = let undefined = record_get_undefined_loop [] lst in let msg = sprintf "%s_of_yojson: the following record elements were undefined: %s" loc undefined in of_yojson_error msg yojson ;; let record_list_instead_atom loc yojson = let msg = loc ^ "_of_yojson: list instead of atom for record expected" in of_yojson_error msg yojson ;; let record_poly_field_value loc yojson = let msg = loc ^ "_of_yojson: cannot convert values of types resulting from polymorphic record \ fields" in of_yojson_error msg yojson ;; (* Errors concerning polymorphic variants *) exception No_variant_match let no_variant_match () = raise No_variant_match let no_matching_variant_found loc yojson = of_yojson_error (loc ^ "_of_yojson: no matching variant found") yojson ;; let ptag_no_args loc yojson = of_yojson_error (loc ^ "_of_yojson: polymorphic variant does not take arguments") yojson ;; let ptag_incorrect_n_args loc cnstr yojson = let msg = sprintf "%s_of_yojson: polymorphic variant tag %S has incorrect number of arguments" loc cnstr in of_yojson_error msg yojson ;; let ptag_takes_args loc yojson = of_yojson_error (loc ^ "_of_yojson: polymorphic variant tag takes an argument") yojson ;; let nested_list_invalid_poly_var loc yojson = of_yojson_error (loc ^ "_of_yojson: a nested list is an invalid polymorphic variant") yojson ;; let empty_list_invalid_poly_var loc yojson = of_yojson_error (loc ^ "_of_yojson: the empty list is an invalid polymorphic variant") yojson ;; let empty_type loc yojson = of_yojson_error (loc ^ "_of_yojson: trying to convert an empty type") yojson ;; ppx_yojson_conv_lib-0.17.0/yojsonable_intf.ml000066400000000000000000000016131461647336100214150ustar00rootroot00000000000000module type S = sig type t val t_of_yojson : Yojson.Safe.t -> t val yojson_of_t : t -> Yojson.Safe.t end module type S1 = sig type 'a t val t_of_yojson : (Yojson.Safe.t -> 'a) -> Yojson.Safe.t -> 'a t val yojson_of_t : ('a -> Yojson.Safe.t) -> 'a t -> Yojson.Safe.t end module type S2 = sig type ('a, 'b) t val t_of_yojson : (Yojson.Safe.t -> 'a) -> (Yojson.Safe.t -> 'b) -> Yojson.Safe.t -> ('a, 'b) t val yojson_of_t : ('a -> Yojson.Safe.t) -> ('b -> Yojson.Safe.t) -> ('a, 'b) t -> Yojson.Safe.t end module type S3 = sig type ('a, 'b, 'c) t val t_of_yojson : (Yojson.Safe.t -> 'a) -> (Yojson.Safe.t -> 'b) -> (Yojson.Safe.t -> 'c) -> Yojson.Safe.t -> ('a, 'b, 'c) t val yojson_of_t : ('a -> Yojson.Safe.t) -> ('b -> Yojson.Safe.t) -> ('c -> Yojson.Safe.t) -> ('a, 'b, 'c) t -> Yojson.Safe.t end