diff --git a/bin/spatialblock/dune b/bin/spatialblock/dune index 57a5303..9c62917 100644 --- a/bin/spatialblock/dune +++ b/bin/spatialblock/dune @@ -2,7 +2,7 @@ (package spatial-shell) (public_name spatialblock) (name main) - (libraries mltp_ipc spatial_ipc unix jsoner)) + (libraries mltp_ipc spatial_ipc unix ezjsonm-encoding)) (rule (alias man-pages) diff --git a/bin/spatialblock/main.ml b/bin/spatialblock/main.ml index 06e8b1a..5876072 100644 --- a/bin/spatialblock/main.ml +++ b/bin/spatialblock/main.ml @@ -4,12 +4,12 @@ module App_id_map = Hashtbl.Make (String) let app_id_map = App_id_map.create 10 let entry_jsoner = - let open Jsoner.Decoding in + let open Ezjsonm_encoding.Decoding in let open Syntax in let+ app_id = field "app_id" string and+ icon = field "icon" string in (app_id, icon) -let config_jsoner = Jsoner.Decoding.list entry_jsoner +let config_jsoner = Ezjsonm_encoding.Decoding.list entry_jsoner let load_config () = let read_file path = In_channel.(with_open_text path input_all) in @@ -22,7 +22,8 @@ let load_config () = let config_path = config_dir // "spatial" // "spatialblock.json" in if Sys.file_exists config_path then let conf = - read_file config_path |> Jsoner.Decoding.of_string_exn config_jsoner + read_file config_path + |> Ezjsonm_encoding.Decoding.of_string_exn config_jsoner in List.iter (fun (entry, icon) -> App_id_map.add app_id_map entry icon) conf else () diff --git a/bin/spatialmsg/main.ml b/bin/spatialmsg/main.ml index 6948f3b..5aa830d 100644 --- a/bin/spatialmsg/main.ml +++ b/bin/spatialmsg/main.ml @@ -10,7 +10,7 @@ let spatial_error = 2 type format = Json | Quiet let pp_json encoding fmt value = - let json = Jsoner.to_string_exn ~minify:true encoding value in + let json = Ezjsonm_encoding.to_string_exn ~minify:true encoding value in Format.fprintf fmt "%s" json let output_get_windows (reply : Spatial_ipc.get_windows_reply) = function diff --git a/dune-project b/dune-project index bcf9910..4b6ff64 100644 --- a/dune-project +++ b/dune-project @@ -18,7 +18,7 @@ (name spatial-shell) (synopsis "Implementing a spatial model inspired by Material Shell, for i3 and Sway") - (depends (ocaml (>= "5.0.0")) poll (clap (>= "0.3.0")) (ezjsonm (>= "1.2.0")) conf-scdoc)) + (depends (ocaml (>= "5.0.0")) poll (clap (>= "0.3.0")) ezjsonm-encoding conf-scdoc)) (package (allow_empty) diff --git a/lib/jsoner/dune b/lib/jsoner/dune deleted file mode 100644 index 2ff057a..0000000 --- a/lib/jsoner/dune +++ /dev/null @@ -1,3 +0,0 @@ -(library - (name jsoner) - (libraries ezjsonm)) diff --git a/lib/jsoner/json_decoder.ml b/lib/jsoner/json_decoder.ml deleted file mode 100644 index 313ce49..0000000 --- a/lib/jsoner/json_decoder.ml +++ /dev/null @@ -1,54 +0,0 @@ -(* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. *) - -type 'a t = Ezjsonm.value -> 'a - -module Syntax = struct - let ( let+ ) dec f value = f (dec value) - - let ( and+ ) x y value = - let x = x value in - let y = y value in - (x, y) - - let ( let* ) dec k value = - let x = dec value in - k x value - - let return x _value = x -end - -let field str enc value = - try enc (Ezjsonm.find value [ str ]) with - | Not_found -> failwith (str ^ " not found") - | exn -> - Format.printf "%s\n" str; - raise exn - -let field_opt str enc value = - try - match Ezjsonm.find_opt value [ str ] with - | Some x -> Some (enc x) - | None -> None - with _exn -> None - -let list enc = Ezjsonm.get_list enc -let string = Ezjsonm.get_string -let int64 = Ezjsonm.get_int64 -let int = Ezjsonm.get_int - -let string_enum l = - let open Syntax in - let+ constant = string in - try List.assoc constant l - with Not_found -> failwith (constant ^ " not a correct value") - -let bool = Ezjsonm.get_bool -let of_string_exn dec str = Ezjsonm.value_from_string str |> dec -let of_string dec str = try Some (of_string_exn dec str) with _ -> None - -let rec mu : ('a t -> 'a t) -> 'a t = - fun f_enc value -> (f_enc (mu f_enc)) value - -let float = Ezjsonm.get_float diff --git a/lib/jsoner/json_encoder.ml b/lib/jsoner/json_encoder.ml deleted file mode 100644 index 2d2f8d5..0000000 --- a/lib/jsoner/json_encoder.ml +++ /dev/null @@ -1,29 +0,0 @@ -(* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. *) - -type 'a t = 'a -> Ezjsonm.value - -let string = Ezjsonm.string -let bool = Ezjsonm.bool -let list = Ezjsonm.list -let int64 = Ezjsonm.int64 -let int = Ezjsonm.int - -let field : string -> 'a t -> 'a -> Ezjsonm.value -> Ezjsonm.value = - fun name enc value json -> - match json with - | `O fields -> `O ((name, enc value) :: fields) - | _ -> raise (Invalid_argument "Json_encoder.field") - -let field_opt : - type a. string -> a t -> a option -> Ezjsonm.value -> Ezjsonm.value = - fun name enc value json -> - match value with Some value -> field name enc value json | None -> json - -let string_enum l value = - let rec assoc_rev x = function - | [] -> raise Not_found - | (a, b) :: l -> if compare b x = 0 then a else assoc_rev x l - in - Ezjsonm.string @@ assoc_rev value l diff --git a/lib/jsoner/jsoner.ml b/lib/jsoner/jsoner.ml deleted file mode 100644 index f0c04ca..0000000 --- a/lib/jsoner/jsoner.ml +++ /dev/null @@ -1,239 +0,0 @@ -(* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. *) - -type 'a t = { decoder : 'a Json_decoder.t; encoder : 'a Json_encoder.t } - -let to_json_exn jsoner value = jsoner.encoder value -let to_json jsoner value = try Some (jsoner.encoder value) with _ -> None - -let to_string_exn ~minify jsoner value = - Ezjsonm.value_to_string ~minify (to_json_exn jsoner value) - -let to_string ~minify jsoner value = - try Some (to_string_exn ~minify jsoner value) with _ -> None - -let from_string_exn jsoner string = - jsoner.decoder (Ezjsonm.value_from_string string) - -let from_string jsoner value = - try Some (from_string_exn jsoner value) with _ -> None - -let conv from_value to_value jsoner = - { - decoder = (fun json -> jsoner.decoder json |> to_value); - encoder = (fun value -> from_value value |> jsoner.encoder); - } - -let string = { decoder = Json_decoder.string; encoder = Json_encoder.string } - -let string_enum l = - { encoder = Json_encoder.string_enum l; decoder = Json_decoder.string_enum l } - -let list { decoder; encoder } = - { decoder = Json_decoder.list decoder; encoder = Json_encoder.list encoder } - -let int64 = { decoder = Json_decoder.int64; encoder = Json_encoder.int64 } -let int = { decoder = Json_decoder.int; encoder = Json_encoder.int } -let bool = { decoder = Json_decoder.bool; encoder = Json_encoder.bool } - -type 'a field = { - name : string; - field_encoder : 'a -> Ezjsonm.value -> Ezjsonm.value; - field_decoder : 'a Json_decoder.t; -} - -let req name { encoder; decoder } = - { - name; - field_encoder = Json_encoder.field name encoder; - field_decoder = Json_decoder.field name decoder; - } - -let opt name { encoder; decoder } = - { - name; - field_encoder = Json_encoder.field_opt name encoder; - field_decoder = Json_decoder.field_opt name decoder; - } - -let obj1 f = - { - encoder = (fun value -> f.field_encoder value (`O [])); - decoder = (fun json -> f.field_decoder json); - } - -let obj2 f1 f2 = - { - encoder = - (fun (v1, v2) -> `O [] |> f1.field_encoder v1 |> f2.field_encoder v2); - decoder = - (let open Json_decoder.Syntax in - let+ v1 = f1.field_decoder and+ v2 = f2.field_decoder in - (v1, v2)); - } - -let obj3 f1 f2 f3 = - { - encoder = - (fun (v1, v2, v3) -> - `O [] |> f1.field_encoder v1 |> f2.field_encoder v2 - |> f3.field_encoder v3); - decoder = - (let open Json_decoder.Syntax in - let+ v1 = f1.field_decoder - and+ v2 = f2.field_decoder - and+ v3 = f3.field_decoder in - (v1, v2, v3)); - } - -let obj4 f1 f2 f3 f4 = - { - encoder = - (fun (v1, v2, v3, v4) -> - `O [] |> f1.field_encoder v1 |> f2.field_encoder v2 - |> f3.field_encoder v3 |> f4.field_encoder v4); - decoder = - (let open Json_decoder.Syntax in - let+ v1 = f1.field_decoder - and+ v2 = f2.field_decoder - and+ v3 = f3.field_decoder - and+ v4 = f4.field_decoder in - (v1, v2, v3, v4)); - } - -let obj5 f1 f2 f3 f4 f5 = - { - encoder = - (fun (v1, v2, v3, v4, v5) -> - `O [] |> f1.field_encoder v1 |> f2.field_encoder v2 - |> f3.field_encoder v3 |> f4.field_encoder v4 |> f5.field_encoder v5); - decoder = - (let open Json_decoder.Syntax in - let+ v1 = f1.field_decoder - and+ v2 = f2.field_decoder - and+ v3 = f3.field_decoder - and+ v4 = f4.field_decoder - and+ v5 = f5.field_decoder in - (v1, v2, v3, v4, v5)); - } - -let obj6 f1 f2 f3 f4 f5 f6 = - { - encoder = - (fun (v1, v2, v3, v4, v5, v6) -> - `O [] |> f1.field_encoder v1 |> f2.field_encoder v2 - |> f3.field_encoder v3 |> f4.field_encoder v4 |> f5.field_encoder v5 - |> f6.field_encoder v6); - decoder = - (let open Json_decoder.Syntax in - let+ v1 = f1.field_decoder - and+ v2 = f2.field_decoder - and+ v3 = f3.field_decoder - and+ v4 = f4.field_decoder - and+ v5 = f5.field_decoder - and+ v6 = f6.field_decoder in - (v1, v2, v3, v4, v5, v6)); - } - -let obj7 f1 f2 f3 f4 f5 f6 f7 = - { - encoder = - (fun (v1, v2, v3, v4, v5, v6, v7) -> - `O [] |> f1.field_encoder v1 |> f2.field_encoder v2 - |> f3.field_encoder v3 |> f4.field_encoder v4 |> f5.field_encoder v5 - |> f6.field_encoder v6 |> f7.field_encoder v7); - decoder = - (let open Json_decoder.Syntax in - let+ v1 = f1.field_decoder - and+ v2 = f2.field_decoder - and+ v3 = f3.field_decoder - and+ v4 = f4.field_decoder - and+ v5 = f5.field_decoder - and+ v6 = f6.field_decoder - and+ v7 = f7.field_decoder in - (v1, v2, v3, v4, v5, v6, v7)); - } - -let obj8 f1 f2 f3 f4 f5 f6 f7 f8 = - { - encoder = - (fun (v1, v2, v3, v4, v5, v6, v7, v8) -> - `O [] |> f1.field_encoder v1 |> f2.field_encoder v2 - |> f3.field_encoder v3 |> f4.field_encoder v4 |> f5.field_encoder v5 - |> f6.field_encoder v6 |> f7.field_encoder v7 |> f8.field_encoder v8); - decoder = - (let open Json_decoder.Syntax in - let+ v1 = f1.field_decoder - and+ v2 = f2.field_decoder - and+ v3 = f3.field_decoder - and+ v4 = f4.field_decoder - and+ v5 = f5.field_decoder - and+ v6 = f6.field_decoder - and+ v7 = f7.field_decoder - and+ v8 = f8.field_decoder in - (v1, v2, v3, v4, v5, v6, v7, v8)); - } - -let obj9 f1 f2 f3 f4 f5 f6 f7 f8 f9 = - { - encoder = - (fun (v1, v2, v3, v4, v5, v6, v7, v8, v9) -> - `O [] |> f1.field_encoder v1 |> f2.field_encoder v2 - |> f3.field_encoder v3 |> f4.field_encoder v4 |> f5.field_encoder v5 - |> f6.field_encoder v6 |> f7.field_encoder v7 |> f8.field_encoder v8 - |> f9.field_encoder v9); - decoder = - (let open Json_decoder.Syntax in - let+ v1 = f1.field_decoder - and+ v2 = f2.field_decoder - and+ v3 = f3.field_decoder - and+ v4 = f4.field_decoder - and+ v5 = f5.field_decoder - and+ v6 = f6.field_decoder - and+ v7 = f7.field_decoder - and+ v8 = f8.field_decoder - and+ v9 = f9.field_decoder in - (v1, v2, v3, v4, v5, v6, v7, v8, v9)); - } - -let obj10 f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 = - { - encoder = - (fun (v1, v2, v3, v4, v5, v6, v7, v8, v9, v10) -> - `O [] |> f1.field_encoder v1 |> f2.field_encoder v2 - |> f3.field_encoder v3 |> f4.field_encoder v4 |> f5.field_encoder v5 - |> f6.field_encoder v6 |> f7.field_encoder v7 |> f8.field_encoder v8 - |> f9.field_encoder v9 |> f10.field_encoder v10); - decoder = - (let open Json_decoder.Syntax in - let+ v1 = f1.field_decoder - and+ v2 = f2.field_decoder - and+ v3 = f3.field_decoder - and+ v4 = f4.field_decoder - and+ v5 = f5.field_decoder - and+ v6 = f6.field_decoder - and+ v7 = f7.field_decoder - and+ v8 = f8.field_decoder - and+ v9 = f9.field_decoder - and+ v10 = f10.field_decoder in - (v1, v2, v3, v4, v5, v6, v7, v8, v9, v10)); - } - -let merge_objs j1 j2 = - { - encoder = - (fun (v1, v2) -> - match (j1.encoder v1, j2.encoder v2) with - | `O l1, `O l2 -> `O (l1 @ l2) - | _ -> raise (Invalid_argument "merge_objs: expected objects")); - decoder = (fun json -> (j1.decoder json, j2.decoder json)); - } - -module Decoding = struct - type 'a jsoner = 'a t - - let from_jsoner { decoder; _ } = decoder - - include Json_decoder -end diff --git a/lib/jsoner/jsoner.mli b/lib/jsoner/jsoner.mli deleted file mode 100644 index 91b5590..0000000 --- a/lib/jsoner/jsoner.mli +++ /dev/null @@ -1,430 +0,0 @@ -(* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. *) - -(** JSON encoding/decoding library a la data-encoding, but with two key - differences: [Jsoner] does not have a dependency to [ZArith], and always - accepts JSON values which are supersets of the expected object. - - The examples of this documentation can be copy/pasted to an OCaml REPL. *) - -type 'a t -(** A JSON encoder/decoder, nicknamed Jsoner in the context of this library, - for a value of type ['a]. *) - -val to_json_exn : 'a t -> 'a -> Ezjsonm.value -(** [to_json_exn jsoner value] encodes [value] in JSON using [jsoner]. Will - raise an exception in case [jsoner] cannot serialize [value]. - - {[ - open Jsoner - - let jsoner = obj1 (req "hello" string) - - let json = to_json_exn jsoner "world" - (* `O [("hello", `String "world")] *) - ]} *) - -val to_json : 'a t -> 'a -> Ezjsonm.value option -(** [to_json_exn jsoner value] encodes [value] in JSON using [jsoner]. Will - return [None] in case [jsoner] cannot serialize [value]. *) - -val to_string_exn : minify:bool -> 'a t -> 'a -> string -(** [to_string_exn ~minify jsoner value] encodes [value] using [jsoner] into a - JSON value serialized in a string. Will raise an exception in case [jsoner] - cannot serialize [value]. *) - -val to_string : minify:bool -> 'a t -> 'a -> string option -(** [to_string ~minify jsoner value] encodes [value] using [jsoner] into a JSON - value serialized in a string. Will return [None] in case [jsoner] cannot - serialize [value]. *) - -val from_string_exn : 'a t -> string -> 'a -(** [from_string_exn jsoner str] decodes a JSON value from [str], then uses - [jsoner] to construct an OCaml value. Will raise an exception if [str] is - not a valid JSON value, or if [jsoner] cannot construct an OCaml value from - [str]. *) - -val from_string : 'a t -> string -> 'a option -(** [from_string jsoner str] decodes a JSON value from [str], then uses - [jsoner] to construct an OCaml value. Will return [None] if [str] is not a - valid JSON value, or if [jsoner] cannot construct an OCaml value from - [str]. *) - -val conv : ('a -> 'b) -> ('b -> 'a) -> 'b t -> 'a t -(** [conv f g jsoner] crafts a new Jsoner from [jsoner]. This is typically used - to creates a JSON encoder/decoder for OCaml records by projecting them to - tuples, and using [objN] combinators. - - {[ - open Jsoner - - type t = { f1 : int; f2 : bool } - - let jsoner = - conv - (fun { f1; f2 } -> (f1, f2)) - (fun (f1, f2) -> { f1; f2 }) - (obj2 (req "f1" int) (req "f2" bool)) - - let json = to_json_exn jsoner { f1 = 0; f2 = true } - (* `O [("f2", `Bool true); ("f1", `Float 0.)] *) - ]} *) - -val string_enum : (string * 'a) list -> 'a t -(** [string_enum] maps JSON strings to fixed OCaml values. - - {[ - open Jsoner - - type toggle = On | Off - - let toggle_jsoner = string_enum [ "on", On; "off", Off ] - - let json = to_json_exn toggle_jsoner On - (* `String "on" *) - - let toggle = from_string_exn toggle_jsoner {|"on"|} - (* On *) - ]} *) - -val string : string t -(** The Jsoner which maps JSON strings and OCaml strings. - - {[ - open Jsoner - - let json = to_json_exn string "hello, world!" - (* `String "hello, world!" *) - - let str = from_string_exn string {|"hello, world!"|} - (* "hello, world!" *) - ]} *) - -val int64 : int64 t -(** The Jsoner which maps JSON ints and OCaml int64. As a reminder, - Ezjsonm uses floats internally to encode integers. - - {[ - open Jsoner - - let json = to_json_exn int64 1L - (* `Float 1. *) - - let str = from_string_exn int64 "1" - (* 1L *) - ]} *) - -val int : int t -(** The Jsoner which maps JSON ints and OCaml ints. As a reminder, Ezjsonm uses - floats internally to encode integers. - - {[ - open Jsoner - - let json = to_json_exn int 1 - (* `Float 1. *) - - let str = from_string_exn int "1" - (* 1 *) - ]} *) - -val bool : bool t -(** The Jsoner which maps JSON booleans and OCaml booleans. - - {[ - open Jsoner - - let json = to_json_exn bool false - (* `Bool false *) - - let str = from_string_exn bool "false" - (* false *) - ]} *) - -val list : 'a t -> 'a list t -(** [list jsoner] creates a jsoner for a list of values based on the Jsoner of - said values. - - {[ - open Jsoner - - let json = to_json_exn (list bool) [true; true; false] - (* `A [`Bool true; `Bool true; `Bool false] *) - - let str = from_string_exn (list int) "[1, 2, 3]" - (* [1; 2; 3] *) - ]} - *) - -type 'a field -(** The description of one field of a JSON object. See {!req} and {!opt} to - construct [field] values, and {!obj1} to {!obj10} and {!merge_objs} to - construct Jsoner for objects. *) - -val req : string -> 'a t -> 'a field -(** [req field_name jsoner] represents a {i required} field. That is, - the decoding will fail if provided an object lacking this field (and raises an exepction with {!from_string_exn} and - {!from_string_exn}). - - {[ - open Jsoner - - let json = to_json_exn (obj1 (req "hello" string)) "world!" - (* `O [("hello", `String "world!")] *) - - let str = from_string_exn (obj1 (req "hello" string)) {|{ "hello": "world!"}|} - (* "world!" *) - - let str = from_string (obj1 (req "hello" string)) {|{ "bye": "world!"}|} - (* None *) - ]} *) - -val opt : string -> 'a t -> 'a option field -(** [opt field_name jsoner] represents an {i optional} field ({i i.e.}, wrapped - in an [option]). - - {[ - open Jsoner - - let json = to_json_exn (obj1 (opt "hello" string)) (Some "world!") - (* `O [("hello", `String "world!")] *) - - let json' = to_json_exn (obj1 (opt "hello" string)) None - (* `O [] *) - - let str = from_string_exn (obj1 (opt "hello" string)) {|{ "hello": "world!"}|} - (* Some "world!" *) - - let str = from_string (obj1 (opt "hello" string)) {|{ "bye": "world!"}|} - (* Some None *) - ]} *) - -val obj1 : 'a field -> 'a t -(** [obj1 f] represents an object characterized by {i at least} the field [f]. - This field can be optional or required depending on how it has been defined - (see {!req} and {!opt}). *) - -val obj2 : 'a field -> 'b field -> ('a * 'b) t -(** [obj2 f1 f2] represents an object characterized by {i at least} the fields passed - as arguments. They can be optional or required depending on how they have - been defined (see {!req} and {!opt}). *) - -val obj3 : 'a field -> 'b field -> 'c field -> ('a * 'b * 'c) t -(** [obj3 f1 f2 f3] represents an object characterized by {i at least} the - fields passed as arguments. They can be optional or required depending on - how they have been defined (see {!req} and {!opt}). *) - -val obj4 : 'a field -> 'b field -> 'c field -> 'd field -> ('a * 'b * 'c * 'd) t -(** [obj4 f1 f2 f3 f4] represents an object characterized by {i at least} the - fields passed as arguments. They can be optional or required depending on - how they have been defined (see {!req} and {!opt}). *) - -val obj5 : - 'a field -> - 'b field -> - 'c field -> - 'd field -> - 'e field -> - ('a * 'b * 'c * 'd * 'e) t -(** [obj5 f1 f2 f3 f4 f5] represents an object characterized by {i at least} - the fields passed as arguments. They can be optional or required depending - on how they have been defined (see {!req} and {!opt}). *) - -val obj6 : - 'a field -> - 'b field -> - 'c field -> - 'd field -> - 'e field -> - 'f field -> - ('a * 'b * 'c * 'd * 'e * 'f) t -(** [obj6 f1 f2 f3 f4 f5 f6] represents an object characterized by {i at least} - the fields passed as arguments. They can be optional or required depending - on how they have been defined (see {!req} and {!opt}). *) - -val obj7 : - 'a field -> - 'b field -> - 'c field -> - 'd field -> - 'e field -> - 'f field -> - 'g field -> - ('a * 'b * 'c * 'd * 'e * 'f * 'g) t -(** [obj7 f1 f2 f3 f4 f5 f6 f7] represents an object characterized by {i at - least} the fields passed as arguments. They can be optional or required - depending on how they have been defined (see {!req} and {!opt}). *) - -val obj8 : - 'a field -> - 'b field -> - 'c field -> - 'd field -> - 'e field -> - 'f field -> - 'g field -> - 'h field -> - ('a * 'b * 'c * 'd * 'e * 'f * 'g * 'h) t -(** [obj8 f1 f2 f3 f4 f5 f6 f7 f8] represents an object characterized by {i at - least} the fields passed as arguments. They can be optional or required - depending on how they have been defined (see {!req} and {!opt}). *) - -val obj9 : - 'a field -> - 'b field -> - 'c field -> - 'd field -> - 'e field -> - 'f field -> - 'g field -> - 'h field -> - 'i field -> - ('a * 'b * 'c * 'd * 'e * 'f * 'g * 'h * 'i) t -(** [obj9 f1 f2 f3 f4 f5 f6 f7 f8 f9] represents an object characterized by {i - at least} the fields passed as arguments. They can be optional or required - depending on how they have been defined (see {!req} and {!opt}). *) - -val obj10 : - 'a field -> - 'b field -> - 'c field -> - 'd field -> - 'e field -> - 'f field -> - 'g field -> - 'h field -> - 'i field -> - 'j field -> - ('a * 'b * 'c * 'd * 'e * 'f * 'g * 'h * 'i * 'j) t -(** [obj10 f1 f2 f3 f4 f5 f6 f7 f8 f9 f10] represents an object characterized - by {i at least} the fields passed as arguments. They can be optional or - required depending on how they have been defined (see {!req} and {!opt}). - *) - -val merge_objs : 'a t -> 'b t -> ('a * 'b) t -(** [merg_objs obj1 obj2] represents an object characterized by {i at least} - the fields of [obj1] and [obj2]. This is useful when an object expects at - least more than 10 fields. Note that it is expected that [obj1] and [obj2] - do not have conflict wrt. field names. This is not checked by [Jsoner], and - is considered an undefined behavior (which may change in a future version - of the library). - - {[ - open Jsoner - - let json = - to_string_exn - (merge_objs - (obj2 (req "foo" string) (req "bar" bool)) - (obj1 (opt "foobar" int))) - (("hello", true), Some 1) - (* `O [("bar", `Bool true); ("foo", `String "hello"); ("foobar", `Float 1.)] *) - ]} *) - -module Decoding : sig - type 'a jsoner = 'a t - - type 'a t - (** A JSON decoder. Compared to a [jsoner], this type provides the [mu] - combinator, and a monadic DSL to write decoder. See the {!Syntax} module. - *) - - val from_jsoner : 'a jsoner -> 'a t - (** [from_jsoner] specializes a jsoner to be a JSON decoder. *) - - val of_string : 'a t -> string -> 'a option - (** [of_string enc input] interprets [input] as a serialized Json - value, then uses [enc] to decode it into an OCaml value, if - possible. It returns [None] in case of error. *) - - val of_string_exn : 'a t -> string -> 'a - (** Same as [of_string], but raises exceptions in case of error. *) - - (** This modules provides a monadic interface to compose existing - decoders together. *) - module Syntax : sig - val ( let* ) : 'a t -> ('a -> 'b t) -> 'b t - (** The [bind] operator. *) - - val ( let+ ) : 'a t -> ('a -> 'b) -> 'b t - (** The [map] operator. *) - - val ( and+ ) : 'a t -> 'b t -> ('a * 'b) t - - val return : 'a -> 'a t - (** [return x] is the decoder that ignores the input Json value, and - always return [x]. *) - end - - val field : string -> 'a t -> 'a t - (** [field name dec] decodes the input Json as an object which - contains at least one property whose name is [name], and whose - value can be decoded with [dec]. The resulting OCaml value is - returned as-is. - - [field] is typically used to read from several property of an - object, which can later be composed together. - - {[ - let tup2 dl dr = - let open Jsoner.Decoding in - let open Syntax in - let+ x = field "0" dl - and+ y = field "1" dr in - (x, y) - ]} - - The decoding will fail in the input Json value does not have a - property [name]. *) - - val field_opt : string -> 'a t -> 'a option t - (** Same as {!val-field}, but the the decoding will not fail if the input - Json value does not have the expected property. In that case, - [None] is returned. *) - - val list : 'a t -> 'a list t - (** [list enc] decodes the input Json value as a list of values which - can be decoded using [enc]. *) - - val string : string t - (** [string] decodes the input Json value as a string. *) - - val int64 : int64 t - (** [int64] decodes the input Json value as an 64-byte integer. *) - - val bool : bool t - (** [bool] decodes the input Json value as a boolean. *) - - val float : float t - (** [float] decodes the input Json value as a float. *) - - val string_enum : (string * 'a) list -> 'a t - (** [string_enum l] decodes the input Json value as a string, then - compare said string with the values contained in the associated - list [l], to return the OCaml value associated to that string. *) - - val mu : ('a t -> 'a t) -> 'a t - (** [mu] is a combinator that lets you write a recursive decoder, - without having to write a recursive function. For instance, if [mu] - can be used to manipulate tree-like structures. - - {[ - open Jsoner.Decoding - - type tree = { value : int64; children : tree list } - - let decoder = - let open Syntax in - mu (fun tree_decoder -> - let+ value = field "value" int64 - and+ children = field "children" @@ list tree_decoder in - { value; children }) - - let leaf = of_string_exn decoder {|{ "value": 3 , "children" : [] }|} - (* { value = 3L; children = [] } *) - - let tree = of_string_exn decoder {|{ "value": 3 , "children" : [ { "value": 5, "children": [] } ] }|} - (* { value = 3L; children = [{ value = 5L; children = [] }] } *) - ]} *) -end diff --git a/lib/spatial_ipc/dune b/lib/spatial_ipc/dune index b1a9752..0698342 100644 --- a/lib/spatial_ipc/dune +++ b/lib/spatial_ipc/dune @@ -1,6 +1,6 @@ (library (name spatial_ipc) - (libraries mltp_ipc jsoner miam)) + (libraries mltp_ipc ezjsonm-encoding miam)) (rule (alias man-pages) diff --git a/lib/spatial_ipc/spatial_ipc.ml b/lib/spatial_ipc/spatial_ipc.ml index 2417f08..599157d 100644 --- a/lib/spatial_ipc/spatial_ipc.ml +++ b/lib/spatial_ipc/spatial_ipc.ml @@ -127,7 +127,7 @@ let command_to_string = function type run_command_reply = { success : bool } let run_command_reply_encoding = - let open Jsoner in + let open Ezjsonm_encoding in conv (fun { success } -> success) (fun success -> { success }) @@ -136,15 +136,15 @@ let run_command_reply_encoding = type window = { app_id : string; name : string } type get_windows_reply = { focus : int option; windows : window list } -let window_encoding : window Jsoner.t = - let open Jsoner in +let window_encoding : window Ezjsonm_encoding.t = + let open Ezjsonm_encoding in conv (fun { app_id; name } -> (app_id, name)) (fun (app_id, name) -> { app_id; name }) (obj2 (req "app_id" string) (req "name" string)) -let get_windows_reply_encoding : get_windows_reply Jsoner.t = - let open Jsoner in +let get_windows_reply_encoding : get_windows_reply Ezjsonm_encoding.t = + let open Ezjsonm_encoding in conv (fun { focus; windows } -> (focus, windows)) (fun (focus, windows) -> { focus; windows }) @@ -152,8 +152,8 @@ let get_windows_reply_encoding : get_windows_reply Jsoner.t = type get_workspaces_reply = { focus : int; windows : (int * window) list } -let get_workspaces_reply_encoding : get_workspaces_reply Jsoner.t = - let open Jsoner in +let get_workspaces_reply_encoding : get_workspaces_reply Ezjsonm_encoding.t = + let open Ezjsonm_encoding in conv (fun { focus; windows } -> (focus, windows)) (fun (focus, windows) -> { focus; windows }) @@ -164,10 +164,11 @@ let get_workspaces_reply_encoding : get_workspaces_reply Jsoner.t = type get_workspace_config_reply = { layout : layout; column_count : int } let layout_encoding = - Jsoner.string_enum [ ("maximize", Maximize); ("column", Column) ] + Ezjsonm_encoding.string_enum [ ("maximize", Maximize); ("column", Column) ] -let get_workspace_config_reply_encoding : get_workspace_config_reply Jsoner.t = - let open Jsoner in +let get_workspace_config_reply_encoding : + get_workspace_config_reply Ezjsonm_encoding.t = + let open Ezjsonm_encoding in conv (fun { layout; column_count } -> (layout, column_count)) (fun (layout, column_count) -> { layout; column_count }) @@ -179,18 +180,19 @@ type 'a t = | Get_workspaces : get_workspaces_reply t | Get_workspace_config : get_workspace_config_reply t -let reply_encoding : type a. a t -> a Jsoner.t = function +let reply_encoding : type a. a t -> a Ezjsonm_encoding.t = function | Run_command _ -> run_command_reply_encoding | Get_windows -> get_windows_reply_encoding | Get_workspaces -> get_workspaces_reply_encoding | Get_workspace_config -> get_workspace_config_reply_encoding let reply_to_string : type a. a t -> a -> string = - fun cmd reply -> Jsoner.to_string_exn ~minify:true (reply_encoding cmd) reply + fun cmd reply -> + Ezjsonm_encoding.to_string_exn ~minify:true (reply_encoding cmd) reply let reply_of_string : type a. a t -> string -> a option = fun cmd reply -> - let open Jsoner in + let open Ezjsonm_encoding in from_string (reply_encoding cmd) reply let reply_of_string_exn cmd reply = diff --git a/lib/spatial_ipc/spatial_ipc.mli b/lib/spatial_ipc/spatial_ipc.mli index f897be5..ff44b2a 100644 --- a/lib/spatial_ipc/spatial_ipc.mli +++ b/lib/spatial_ipc/spatial_ipc.mli @@ -30,10 +30,12 @@ type get_windows_reply = { focus : int option; windows : window list } type get_workspaces_reply = { focus : int; windows : (int * window) list } type get_workspace_config_reply = { layout : layout; column_count : int } -val run_command_reply_encoding : run_command_reply Jsoner.t -val get_windows_reply_encoding : get_windows_reply Jsoner.t -val get_workspaces_reply_encoding : get_workspaces_reply Jsoner.t -val get_workspace_config_reply_encoding : get_workspace_config_reply Jsoner.t +val run_command_reply_encoding : run_command_reply Ezjsonm_encoding.t +val get_windows_reply_encoding : get_windows_reply Ezjsonm_encoding.t +val get_workspaces_reply_encoding : get_workspaces_reply Ezjsonm_encoding.t + +val get_workspace_config_reply_encoding : + get_workspace_config_reply Ezjsonm_encoding.t type 'a t = | Run_command : command -> run_command_reply t diff --git a/lib/sway_ipc/dune b/lib/sway_ipc/dune index 2cc4727..fb297b9 100644 --- a/lib/sway_ipc/dune +++ b/lib/sway_ipc/dune @@ -1,3 +1,3 @@ (library (name sway_ipc) - (libraries jsoner mltp_ipc sway_ipc_types unix)) + (libraries ezjsonm-encoding mltp_ipc sway_ipc_types unix)) diff --git a/lib/sway_ipc/sway_ipc.ml b/lib/sway_ipc/sway_ipc.ml index 5a9b076..a18c02d 100644 --- a/lib/sway_ipc/sway_ipc.ml +++ b/lib/sway_ipc/sway_ipc.ml @@ -31,7 +31,7 @@ let send_command : type a. ?socket:socket -> a Message.t -> a = Socket.write_raw_message ~magic_string socket raw; let op', payload = Socket.read_raw_message ~magic_string socket in assert (op = op'); - Jsoner.Decoding.of_string_exn (Message.reply_decoder cmd) payload + Ezjsonm_encoding.Decoding.of_string_exn (Message.reply_decoder cmd) payload let subscribe events = let socket = connect () in diff --git a/lib/sway_ipc_types/dune b/lib/sway_ipc_types/dune index 2500481..0be4e60 100644 --- a/lib/sway_ipc_types/dune +++ b/lib/sway_ipc_types/dune @@ -1,3 +1,3 @@ (library (name sway_ipc_types) - (libraries mltp_ipc jsoner)) + (libraries mltp_ipc ezjsonm-encoding)) diff --git a/lib/sway_ipc_types/event.ml b/lib/sway_ipc_types/event.ml index e8dd43a..389d352 100644 --- a/lib/sway_ipc_types/event.ml +++ b/lib/sway_ipc_types/event.ml @@ -37,7 +37,7 @@ let event_type_of_code = function | _ -> raise (Invalid_argument "event_type_of_code") let event_type_decoder = - Jsoner.Decoding.string_enum + Ezjsonm_encoding.Decoding.string_enum [ ("workspace", Workspace); ("mode", Mode); @@ -64,7 +64,7 @@ let event_type_string = function type workspace_change = Init | Empty | Focus | Move | Rename | Urgent | Reload let workspace_change_decoder = - Jsoner.Decoding.string_enum + Ezjsonm_encoding.Decoding.string_enum [ ("init", Init); ("empty", Empty); @@ -82,7 +82,7 @@ type workspace_event = { } let workspace_event_decoder = - let open Jsoner.Decoding in + let open Ezjsonm_encoding.Decoding in let open Syntax in let+ change = field "change" workspace_change_decoder and+ current = field "current" Node.decoder @@ -92,7 +92,7 @@ let workspace_event_decoder = type mode_event = { change : string; pango_markup : bool } let mode_event_decoder = - let open Jsoner.Decoding in + let open Ezjsonm_encoding.Decoding in let open Syntax in let+ change = field "change" string and+ pango_markup = field "pango_markup" bool in @@ -110,7 +110,7 @@ type window_change = | Mark let window_change_decoder = - Jsoner.Decoding.string_enum + Ezjsonm_encoding.Decoding.string_enum [ ("new", New); ("close", Close); @@ -126,7 +126,7 @@ let window_change_decoder = type window_event = { change : window_change; container : Node.t } let window_event_decoder = - let open Jsoner.Decoding in + let open Ezjsonm_encoding.Decoding in let open Syntax in let+ change = field "change" window_change_decoder and+ container = field "container" Node.decoder in @@ -135,7 +135,7 @@ let window_event_decoder = type tick_event = { first : bool; payload : string } let tick_event_decoder = - let open Jsoner.Decoding in + let open Ezjsonm_encoding.Decoding in let open Syntax in let+ first = field "first" bool and+ payload = field "payload" string in { first; payload } @@ -149,7 +149,7 @@ type t = type event = t let decoder (code : event_type) = - let open Jsoner.Decoding in + let open Ezjsonm_encoding.Decoding in let open Syntax in match code with | Workspace -> @@ -168,4 +168,4 @@ let decoder (code : event_type) = let event_of_raw_message (opc, payload) = let ev = event_type_of_code opc in - Jsoner.Decoding.of_string_exn (decoder ev) payload + Ezjsonm_encoding.Decoding.of_string_exn (decoder ev) payload diff --git a/lib/sway_ipc_types/input_device.ml b/lib/sway_ipc_types/input_device.ml index b35667e..ecc7707 100644 --- a/lib/sway_ipc_types/input_device.ml +++ b/lib/sway_ipc_types/input_device.ml @@ -11,7 +11,7 @@ type input_type = | Switch let input_type_decoder = - Jsoner.Decoding.string_enum + Ezjsonm_encoding.Decoding.string_enum [ ("keyboard", Keyboard); ("pointer", Pointer); @@ -35,7 +35,7 @@ type t = { } let decoder = - let open Jsoner.Decoding in + let open Ezjsonm_encoding.Decoding in let open Syntax in let+ identifier = field "identifier" string and+ name = field "name" string diff --git a/lib/sway_ipc_types/libinput.ml b/lib/sway_ipc_types/libinput.ml index 145eb4d..c54ec75 100644 --- a/lib/sway_ipc_types/libinput.ml +++ b/lib/sway_ipc_types/libinput.ml @@ -5,7 +5,7 @@ type send_events = Enabled | Disabled | Disabled_on_external_mouse | Unknown let send_events_decoder = - Jsoner.Decoding.string_enum + Ezjsonm_encoding.Decoding.string_enum [ ("enabled", Enabled); ("disabled", Disabled); @@ -16,31 +16,31 @@ let send_events_decoder = type tap = Enabled | Disabled | Unknown let tap_decoder = - Jsoner.Decoding.string_enum + Ezjsonm_encoding.Decoding.string_enum [ ("enabled", Enabled); ("disabled", Disabled); ("unknown", Unknown) ] type tap_button_map = Lmr | Lrm | Unknown let tap_button_map_decoder = - Jsoner.Decoding.string_enum + Ezjsonm_encoding.Decoding.string_enum [ ("lmr", Lmr); ("lrm", Lrm); ("unknown", Unknown) ] type tap_drag = Enabled | Disabled | Unknown let tap_drag_decoder = - Jsoner.Decoding.string_enum + Ezjsonm_encoding.Decoding.string_enum [ ("enabled", Enabled); ("disabled", Disabled); ("unknown", Unknown) ] type tap_drag_lock = Enabled | Disabled | Unknown let tap_drag_lock_decoder = - Jsoner.Decoding.string_enum + Ezjsonm_encoding.Decoding.string_enum [ ("enabled", Enabled); ("disabled", Disabled); ("unknown", Unknown) ] type accel_profile = None | Flat | Adaptive | Unknown let accel_profile_decoder = - Jsoner.Decoding.string_enum + Ezjsonm_encoding.Decoding.string_enum [ ("none", None); ("flat", Flat); @@ -51,19 +51,19 @@ let accel_profile_decoder = type natural_scroll = Enabled | Disabled | Unknown let natural_scroll_decoder = - Jsoner.Decoding.string_enum + Ezjsonm_encoding.Decoding.string_enum [ ("enabled", Enabled); ("disabled", Disabled); ("unknown", Unknown) ] type left_handed = Enabled | Disabled | Unknown let left_handed_decoder = - Jsoner.Decoding.string_enum + Ezjsonm_encoding.Decoding.string_enum [ ("enabled", Enabled); ("disabled", Disabled); ("unknown", Unknown) ] type click_method = None | Button_areas | Clickfinger | Unknown let click_method_decoder = - Jsoner.Decoding.string_enum + Ezjsonm_encoding.Decoding.string_enum [ ("none", None); ("button_areas", Button_areas); @@ -74,13 +74,13 @@ let click_method_decoder = type middle_emulation = Enabled | Disabled | Unknown let middle_emulation_decoder = - Jsoner.Decoding.string_enum + Ezjsonm_encoding.Decoding.string_enum [ ("enabled", Enabled); ("disabled", Disabled); ("unknown", Unknown) ] type scroll_method = None | Two_fingers | Edge | On_button_down | Unknown let scroll_method_decoder = - Jsoner.Decoding.string_enum + Ezjsonm_encoding.Decoding.string_enum [ ("none", None); ("two_fingers", Two_fingers); @@ -92,13 +92,13 @@ let scroll_method_decoder = type dwt = Enabled | Disabled | Unknown let dwt_decoder = - Jsoner.Decoding.string_enum + Ezjsonm_encoding.Decoding.string_enum [ ("enabled", Enabled); ("disabled", Disabled); ("unknown", Unknown) ] type calibration_matrix = float * float * float * float * float * float let calibration_matrix_decoder = - let open Jsoner.Decoding in + let open Ezjsonm_encoding.Decoding in let open Syntax in let+ l = list float in match l with @@ -126,7 +126,7 @@ type t = { type libinput = t let decoder = - let open Jsoner.Decoding in + let open Ezjsonm_encoding.Decoding in let open Syntax in let+ send_events = field_opt "send_events" send_events_decoder and+ tap = field_opt "tap" tap_decoder diff --git a/lib/sway_ipc_types/message.ml b/lib/sway_ipc_types/message.ml index 4134abb..c385cde 100644 --- a/lib/sway_ipc_types/message.ml +++ b/lib/sway_ipc_types/message.ml @@ -5,7 +5,7 @@ type subscribe_reply = { success : bool } let subscribe_reply_decoder = - let open Jsoner.Decoding in + let open Ezjsonm_encoding.Decoding in let open Syntax in let+ success = field "success" bool in { success } @@ -17,7 +17,7 @@ type run_command_reply = { } let run_command_reply_decoder = - let open Jsoner.Decoding in + let open Ezjsonm_encoding.Decoding in let open Syntax in let+ success = field "success" bool and+ parse_error = field_opt "parse_error" bool @@ -27,7 +27,7 @@ let run_command_reply_decoder = type send_tick_reply = { success : bool } let send_tick_reply_decoder = - let open Jsoner.Decoding in + let open Ezjsonm_encoding.Decoding in let open Syntax in let+ success = field "success" bool in { success } @@ -62,10 +62,11 @@ let to_raw_message : type reply. reply t -> Mltp_ipc.Raw_message.t = function | Get_tree -> (4l, "") | Send_tick payload -> (10l, payload) -let reply_decoder : type reply. reply t -> reply Jsoner.Decoding.t = function - | Run_command _ -> Jsoner.Decoding.list run_command_reply_decoder - | Get_workspaces -> Jsoner.Decoding.list Workspace.decoder +let reply_decoder : type reply. reply t -> reply Ezjsonm_encoding.Decoding.t = + function + | Run_command _ -> Ezjsonm_encoding.Decoding.list run_command_reply_decoder + | Get_workspaces -> Ezjsonm_encoding.Decoding.list Workspace.decoder | Subscribe _ -> subscribe_reply_decoder - | Get_outputs -> Jsoner.Decoding.list Output.decoder + | Get_outputs -> Ezjsonm_encoding.Decoding.list Output.decoder | Get_tree -> Node.decoder | Send_tick _ -> send_tick_reply_decoder diff --git a/lib/sway_ipc_types/node.ml b/lib/sway_ipc_types/node.ml index 878eba7..f4c7807 100644 --- a/lib/sway_ipc_types/node.ml +++ b/lib/sway_ipc_types/node.ml @@ -10,7 +10,7 @@ type fullscreen_mode = | Global_fullscreen (* 2 *) let fullscreen_mode_decoder = - let open Jsoner.Decoding in + let open Ezjsonm_encoding.Decoding in let open Syntax in let+ i = int64 in match i with @@ -22,7 +22,7 @@ let fullscreen_mode_decoder = type node_type = Root | Output | Workspace | Con | Floating_con let node_type_decoder = - Jsoner.Decoding.string_enum + Ezjsonm_encoding.Decoding.string_enum [ ("root", Root); ("output", Output); @@ -34,7 +34,7 @@ let node_type_decoder = type border = Normal | None | Pixel | Csd let border_decoder = - Jsoner.Decoding.string_enum + Ezjsonm_encoding.Decoding.string_enum [ ("normal", Normal); ("none", None); ("pixel", Pixel); ("csd", Csd) ] type layout = @@ -46,7 +46,7 @@ type layout = | None let layout_decoder = - Jsoner.Decoding.string_enum + Ezjsonm_encoding.Decoding.string_enum [ ("splith", Split_horizontal); ("splitv", Split_vertical); @@ -58,17 +58,17 @@ let layout_decoder = type mark = string -let mark_decoder = Jsoner.Decoding.string +let mark_decoder = Ezjsonm_encoding.Decoding.string type application_state = Enabled | None let application_state_decoder = - Jsoner.Decoding.string_enum [ ("enabled", Enabled); ("none", None) ] + Ezjsonm_encoding.Decoding.string_enum [ ("enabled", Enabled); ("none", None) ] type user_state = Focus | Fullscreen | Open | Visible | None let user_state_decoder = - Jsoner.Decoding.string_enum + Ezjsonm_encoding.Decoding.string_enum [ ("focus", Focus); ("fullscreen", Fullscreen); @@ -80,7 +80,7 @@ let user_state_decoder = type idle_inhibitors = { application : application_state; user : user_state } let idle_inhibitors_decoder = - let open Jsoner.Decoding in + let open Ezjsonm_encoding.Decoding in let open Syntax in let+ application = application_state_decoder and+ user = user_state_decoder in { application; user } @@ -95,7 +95,7 @@ type window_properties = { } let window_properties_decoder = - let open Jsoner.Decoding in + let open Ezjsonm_encoding.Decoding in let open Syntax in let+ title = field "title" string and+ window_class = field "window_class" string @@ -140,7 +140,7 @@ type t = { type node = t let decoder = - let open Jsoner.Decoding in + let open Ezjsonm_encoding.Decoding in let open Syntax in mu (fun node_decoder -> let+ id = field "id" int64 diff --git a/lib/sway_ipc_types/output.ml b/lib/sway_ipc_types/output.ml index 8611e9c..cd027fa 100644 --- a/lib/sway_ipc_types/output.ml +++ b/lib/sway_ipc_types/output.ml @@ -5,7 +5,7 @@ type subpixel_hinting = Rgb | Bgr | Vrgb | Vbgr | None | Unknown let subpixel_hinting_decoder = - Jsoner.Decoding.string_enum + Ezjsonm_encoding.Decoding.string_enum [ ("rgb", Rgb); ("bgr", Bgr); @@ -24,7 +24,7 @@ type transform = | Flipped_two_seventy let transform_decoder = - Jsoner.Decoding.string_enum + Ezjsonm_encoding.Decoding.string_enum [ ("normal", Normal); ("90", Ninety); @@ -38,7 +38,7 @@ let transform_decoder = type mode = { width : int64; height : int64; refresh : int64 } let mode_decoder = - let open Jsoner.Decoding in + let open Ezjsonm_encoding.Decoding in let open Syntax in let+ width = field "width" int64 and+ height = field "height" int64 @@ -48,7 +48,7 @@ let mode_decoder = type orientation = Vertical | Horizontal | None let orientation_decoder = - Jsoner.Decoding.string_enum + Ezjsonm_encoding.Decoding.string_enum [ ("vertical", Vertical); ("horizontal", Horizontal); ("none", None) ] type t = { @@ -71,7 +71,7 @@ type t = { type output = t let decoder = - let open Jsoner.Decoding in + let open Ezjsonm_encoding.Decoding in let open Syntax in let+ name = field "name" string and+ make = field "make" string diff --git a/lib/sway_ipc_types/rect.ml b/lib/sway_ipc_types/rect.ml index 1b4cfcd..9748cca 100644 --- a/lib/sway_ipc_types/rect.ml +++ b/lib/sway_ipc_types/rect.ml @@ -6,7 +6,7 @@ type t = { x : int64; y : int64; width : int64; height : int64 } type rect = t let decoder = - let open Jsoner.Decoding in + let open Ezjsonm_encoding.Decoding in let open Syntax in let+ x = field "x" int64 and+ y = field "y" int64 diff --git a/lib/sway_ipc_types/seat.ml b/lib/sway_ipc_types/seat.ml index 69457a1..780415c 100644 --- a/lib/sway_ipc_types/seat.ml +++ b/lib/sway_ipc_types/seat.ml @@ -12,7 +12,7 @@ type t = { type seat = t let decoder = - let open Jsoner.Decoding in + let open Ezjsonm_encoding.Decoding in let open Syntax in let+ name = field "name" string and+ capabilities = field "capabilities" int64 diff --git a/lib/sway_ipc_types/sway_version.ml b/lib/sway_ipc_types/sway_version.ml index 2c3d4ab..c7f09ea 100644 --- a/lib/sway_ipc_types/sway_version.ml +++ b/lib/sway_ipc_types/sway_version.ml @@ -13,7 +13,7 @@ type t = { type sway_version = t let decoder = - let open Jsoner.Decoding in + let open Ezjsonm_encoding.Decoding in let open Syntax in let+ major = field "major" int64 and+ minor = field "minor" int64 diff --git a/lib/sway_ipc_types/workspace.ml b/lib/sway_ipc_types/workspace.ml index 6c429e2..7f2f7e4 100644 --- a/lib/sway_ipc_types/workspace.ml +++ b/lib/sway_ipc_types/workspace.ml @@ -15,7 +15,7 @@ type t = { type workspace = t let decoder = - let open Jsoner.Decoding in + let open Ezjsonm_encoding.Decoding in let open Syntax in let+ num = field "num" int64 and+ name = field "name" string diff --git a/lib/sway_ipc_types/workspace_id.ml b/lib/sway_ipc_types/workspace_id.ml index 806778a..735b548 100644 --- a/lib/sway_ipc_types/workspace_id.ml +++ b/lib/sway_ipc_types/workspace_id.ml @@ -6,7 +6,7 @@ type t = Index of int | Name of string type workspace_id = t let decoder = - let open Jsoner.Decoding in + let open Ezjsonm_encoding.Decoding in let open Syntax in let+ str = string in match int_of_string_opt str with Some id -> Index id | None -> Name str diff --git a/spatial-shell.opam b/spatial-shell.opam index 7a89fbb..624ddbd 100644 --- a/spatial-shell.opam +++ b/spatial-shell.opam @@ -13,7 +13,7 @@ depends: [ "ocaml" {>= "5.0.0"} "poll" "clap" {>= "0.3.0"} - "ezjsonm" {>= "1.2.0"} + "ezjsonm-encoding" "conf-scdoc" "odoc" {with-doc} ]