Skip to content

Commit

Permalink
Merge pull request #16 from mattjbray/feat-no-containers
Browse files Browse the repository at this point in the history
feat: remove dep on containers
  • Loading branch information
mattjbray authored Nov 6, 2019
2 parents 1cc66eb + a463f8b commit 1f8f7ea
Show file tree
Hide file tree
Showing 25 changed files with 163 additions and 51 deletions.
1 change: 1 addition & 0 deletions decoders-bencode.opam
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ build: [
depends: [
"dune" {build}
"ounit" {with-test}
"containers" {with-test}
"decoders"
"bencode"
"odoc" {with-doc}
Expand Down
1 change: 1 addition & 0 deletions decoders-cbor.opam
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ build: [
depends: [
"dune" {build}
"ounit" {with-test}
"containers" {with-test}
"decoders"
"cbor"
"odoc" {with-doc}
Expand Down
1 change: 1 addition & 0 deletions decoders-ezjsonm.opam
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ build: [
depends: [
"dune" {build}
"ounit" {with-test}
"containers" {with-test}
"decoders"
"ezjsonm" {>= "0.4.0"}
"odoc" {with-doc}
Expand Down
2 changes: 1 addition & 1 deletion decoders-ocyaml.opam
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ build: [
]
depends: [
"dune" {build}
"containers"
"containers" {with-test}
"decoders"
"ocyaml"
"odoc" {with-doc}
Expand Down
1 change: 1 addition & 0 deletions decoders-sexplib.opam
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ build: [
depends: [
"dune" {build}
"ounit" {with-test}
"containers" {with-test}
"decoders"
"sexplib0"
"sexplib"
Expand Down
2 changes: 1 addition & 1 deletion decoders.opam
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ build: [
]
depends: [
"dune" {build}
"containers"
"containers" {with-test}
"ocaml" { >= "4.03.0" }
]
6 changes: 3 additions & 3 deletions src-bencode/decode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ module Bencode_decodeable : Decode.Decodeable with type value = Bencode.t = stru

let pp fmt t = Format.fprintf fmt "@[%s@]" (Bencode.pretty_print t)

let of_string (input : string) : (value, string) CCResult.t =
let of_string (input : string) : (value, string) result =
try Ok (Bencode.decode (`String input)) with
| _ -> Error "invalid bencode"

let of_file (file : string) : (value, string) CCResult.t =
let of_file (file : string) : (value, string) result =
try
let v = CCIO.with_in file (fun ic -> Bencode.decode (`Channel ic)) in
let v = Decoders_util.with_file_in file (fun ic -> Bencode.decode (`Channel ic)) in
Ok v
with
| e -> Error (Printexc.to_string e)
Expand Down
3 changes: 2 additions & 1 deletion src-bencode/encode.ml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
open Decoders
module Bencode_encodeable = struct
type value = Bencode.t

Expand All @@ -12,7 +13,7 @@ module Bencode_encodeable = struct
let of_list xs = Bencode.List xs
let of_key_value_pairs xs =
let xs =
CCList.filter_map
Decoders_util.My_list.filter_map
(function
| Bencode.String s, v -> Some (s,v)
| _ -> None)
Expand Down
7 changes: 4 additions & 3 deletions src-cbor/decode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ module Cbor_decodeable : Decode.Decodeable with type value = CBOR.Simple.t = str

let pp fmt t = Format.fprintf fmt "@[%s@]" (CBOR.Simple.to_diagnostic t)

let of_string (input : string) : (value, string) CCResult.t =
let of_string (input : string) : (value, string) result =
try Ok (CBOR.Simple.decode input) with
| CBOR.Error msg -> Error msg

let of_file (file : string) : (value, string) CCResult.t =
try Ok (CCIO.with_in file (fun chan -> CCIO.read_all chan |> CBOR.Simple.decode)) with
let of_file (file : string) : (value, string) result =
try Ok (Decoders_util.with_file_in file
(fun chan -> Decoders_util.read_all chan |> CBOR.Simple.decode)) with
| e -> Error (Printexc.to_string e)

let get_string = function
Expand Down
6 changes: 3 additions & 3 deletions src-ezjsonm/decode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ module Ezjsonm_decodeable : Decode.Decodeable with type value = Ezjsonm.value =

let pp fmt t = Format.fprintf fmt "@[%a@]" pp_t t

let of_string (input : string) : (value, string) CCResult.t =
let of_string (input : string) : (value, string) result =
try Ok (Ezjsonm.from_string input) with
| Ezjsonm.Parse_error (_json, msg) -> Error msg

let of_file (file : string) : (value, string) CCResult.t =
try Ok (CCIO.with_in file Ezjsonm.from_channel) with
let of_file (file : string) : (value, string) result =
try Ok (Decoders_util.with_file_in file Ezjsonm.from_channel) with
| e -> Error (Printexc.to_string e)

let get_string = function
Expand Down
2 changes: 1 addition & 1 deletion src-ezjsonm/encode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module Ezjsonm_encodeable = struct
let of_key_value_pairs xs =
`O
(xs
|> CCList.filter_map (fun (k, v) ->
|> Decoders.Decoders_util.My_list.filter_map (fun (k, v) ->
match k with
| `String k -> Some (k, v)
| _ -> None))
Expand Down
8 changes: 4 additions & 4 deletions src-ocyaml/decode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module Yaml_decodeable : Decode.Decodeable with type value = Ocyaml.yaml = struc
fun t ->
try
get_string t
|> CCOpt.map int_of_string
|> Decoders_util.My_opt.map int_of_string
with
| Failure _ -> None

Expand All @@ -45,22 +45,22 @@ module Yaml_decodeable : Decode.Decodeable with type value = Ocyaml.yaml = struc
fun t ->
try
get_string t
|> CCOpt.map float_of_string
|> Decoders_util.My_opt.map float_of_string
with
| Failure _ -> None

let get_bool : value -> bool option =
fun t ->
try
get_string t
|> CCOpt.map bool_of_string
|> Decoders_util.My_opt.map bool_of_string
with
| Failure _ -> None

let get_null : value -> unit option =
fun t ->
get_string t
|> CCOpt.flat_map (function
|> Decoders_util.My_opt.flat_map (function
| "" -> Some ()
| _ -> None
)
Expand Down
8 changes: 4 additions & 4 deletions src-sexplib/decode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ module Sexplib_decodeable : Decode.Decodeable with type value = Sexp.t = struct
Format.fprintf fmt "@[%a@]"
Sexp.pp_hum value

let of_string (input : string) : (value, string) CCResult.t =
let of_string (input : string) : (value, string) result =
try Ok (Sexplib.Sexp.of_string input) with
| Failure msg -> Error msg

let of_file (file : string) : (value, string) CCResult.t =
let of_file (file : string) : (value, string) result =
try Ok (Sexplib.Sexp.load_sexp file) with
| e -> Error (Printexc.to_string e)

Expand All @@ -32,11 +32,11 @@ module Sexplib_decodeable : Decode.Decodeable with type value = Sexp.t = struct

let get_key_value_pairs = function
| Sexp.List lst ->
lst |> CCList.map (function
lst |> Decoders_util.My_list.map (function
| Sexp.List [key; value] -> Some (key, value)
| Sexp.List (key :: values) -> Some (key, Sexp.List values)
| _ -> None)
|> CCList.all_some
|> Decoders_util.My_list.all_some
| _ -> None

let to_list values = Sexp.List values
Expand Down
1 change: 1 addition & 0 deletions src-sexplib/test/dune
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
(package decoders-sexplib)
(libraries
decoders-sexplib
containers
oUnit))
8 changes: 4 additions & 4 deletions src-yojson/basic.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ module Json_decodeable : Decode.Decodeable with type value = Yojson.Basic.json =
type value = Yojson.Basic.json
let pp fmt json = Format.fprintf fmt "@[%s@]" (Yojson.Basic.pretty_to_string json)

let of_string : string -> (value, string) CCResult.t =
let of_string : string -> (value, string) result =
fun string ->
try CCResult.Ok (Yojson.Basic.from_string string) with
try Ok (Yojson.Basic.from_string string) with
| Yojson.Json_error msg -> Error msg

let of_file file =
try CCResult.Ok (Yojson.Basic.from_file file) with
try Ok (Yojson.Basic.from_file file) with
| e -> Error (Printexc.to_string e)

let get_string = function
Expand Down Expand Up @@ -64,7 +64,7 @@ module Json_encodeable = struct
let of_key_value_pairs xs =
`Assoc
(xs
|> CCList.filter_map (fun (k, v) ->
|> Decoders_util.My_list.filter_map (fun (k, v) ->
match k with
| `String k -> Some (k, v)
| _ -> None))
Expand Down
1 change: 1 addition & 0 deletions src-yojson/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(library
(name decoders_yojson)
(public_name decoders-yojson)
(flags :standard -warn-error -3)
(libraries
decoders
yojson))
10 changes: 5 additions & 5 deletions src-yojson/raw.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ module Json_decodeable : Decode.Decodeable with type value = Yojson.Raw.json = s
type value = Yojson.Raw.json
let pp fmt json = Format.fprintf fmt "@[%s@]" (Yojson.Raw.pretty_to_string json)

let of_string : string -> (value, string) CCResult.t =
let of_string : string -> (value, string) result =
fun string ->
try CCResult.Ok (Yojson.Raw.from_string string) with
try Ok (Yojson.Raw.from_string string) with
| Yojson.Json_error msg -> Error (msg)

let of_file file =
try CCResult.Ok (Yojson.Raw.from_file file) with
try Ok (Yojson.Raw.from_file file) with
| e -> Error (Printexc.to_string e)

let get_string = function
Expand Down Expand Up @@ -93,9 +93,9 @@ module Json_encodeable = struct
let of_key_value_pairs xs =
`Assoc
(xs
|> CCList.filter_map (fun (k, v) ->
|> Decoders_util.My_list.filter_map (fun (k, v) ->
Json_decodeable.get_string k
|> CCOpt.map (fun k -> (k, v))
|> Decoders_util.My_opt.map (fun k -> (k, v))
))
end

Expand Down
8 changes: 4 additions & 4 deletions src-yojson/safe.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ module Json_decodeable : Decode.Decodeable with type value = Yojson.Safe.json =
type value = Yojson.Safe.json
let pp fmt json = Format.fprintf fmt "@[%s@]" (Yojson.Safe.pretty_to_string json)

let of_string : string -> (value, string) CCResult.t =
let of_string : string -> (value, string) result =
fun string ->
try CCResult.Ok (Yojson.Safe.from_string string) with
try Ok (Yojson.Safe.from_string string) with
| Yojson.Json_error msg -> Error msg

let of_file file =
try CCResult.Ok (Yojson.Safe.from_file file) with
try Ok (Yojson.Safe.from_file file) with
| e -> Error (Printexc.to_string e)

let get_string = function
Expand Down Expand Up @@ -64,7 +64,7 @@ module Json_encodeable = struct
let of_key_value_pairs xs =
`Assoc
(xs
|> CCList.filter_map (fun (k, v) ->
|> Decoders_util.My_list.filter_map (fun (k, v) ->
match k with
| `String k -> Some (k, v)
| _ -> None))
Expand Down
2 changes: 2 additions & 0 deletions src/decoders.ml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
module Decode = Decode
module Encode = Encode

module Decoders_util = Decoders_util
Loading

0 comments on commit 1f8f7ea

Please sign in to comment.