aboutsummaryrefslogtreecommitdiff
path: root/lib/helpers/toml.ml
diff options
context:
space:
mode:
Diffstat (limited to 'lib/helpers/toml.ml')
-rw-r--r--lib/helpers/toml.ml31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/helpers/toml.ml b/lib/helpers/toml.ml
new file mode 100644
index 0000000..1b7fb15
--- /dev/null
+++ b/lib/helpers/toml.ml
@@ -0,0 +1,31 @@
+module Decode = struct
+ module S = struct
+ type value = Otoml.t
+
+ let pp : Format.formatter -> value -> unit =
+ fun format t -> Format.pp_print_string format (Otoml.Printer.to_string t)
+
+ let of_string : string -> (value, string) result =
+ Otoml.Parser.from_string_result
+
+ let of_file : string -> (value, string) result =
+ Otoml.Parser.from_file_result
+
+ let get_string : value -> string option = Otoml.get_opt Otoml.get_string
+ let get_int : value -> int option = Otoml.get_opt Otoml.get_integer
+ let get_float : value -> float option = Otoml.get_opt Otoml.get_float
+ let get_bool : value -> bool option = Otoml.get_opt Otoml.get_boolean
+ let get_null : value -> unit option = fun _ -> None
+
+ let get_list : value -> value list option =
+ Otoml.get_opt @@ Otoml.get_array Fun.id
+
+ let get_key_value_pairs : value -> (value * value) list option =
+ Otoml.get_opt (fun key ->
+ Otoml.get_table key |> List.map (fun (k, v) -> (Otoml.string k, v)))
+
+ let to_list : value list -> value = Otoml.array
+ end
+
+ include Decoders.Decode.Make (S)
+end