module Toml:sig..end
You should use the Toml.Value.To and Toml.Value.Of modules to navigate between
plain OCaml data structures and Toml data structures.
module Table:sig..end
val key : string -> Table.Key.tToml.Table.Key.Bad_key if the key contains invalid characters.module Value:sig..end
Toml offers a number of convenience function, to access and find values with a
minimum of typing.
Given a Toml value (of type Toml.Value.value), returns an OCaml value.
Example:
# let table = Toml.Table.empty
|> Toml.Table.add (Toml.key "foo") (Toml.Value.Of.string "bar");;
val table : Toml.Value.value Toml.Table.t = <abstr>
# let bar = Toml.Table.find (Toml.key "foo") table
|> Toml.Value.To.string;;
val bar : bytes = "bar"
# let table = Toml.Table.empty
|> Toml.Table.add (Toml.key "fortytwos")
(Toml.Value.Of.Array.int [42;42] |> Toml.Value.Of.array);;
val table : Toml.Value.value Toml.Table.t = <abstr>
# let fortytwos = Toml.Table.find (Toml.key "fortytwos") table
|> Toml.to_int_array;;
val fortytwos : int list = [42; 42]
# let table = Toml.Table.empty
|> Toml.Table.add (Toml.key "tables")
([
Toml.Table.empty
|> Toml.Table.add (Toml.key "foo") (Toml.of_string "foofoo");
Toml.Table.empty
|> Toml.Table.add (Toml.key "bar") (Toml.of_string "barbar");
] |> Toml.of_table_array);;
val table : Toml.Value.value Toml.Table.t = <abstr>
# let array_of_tables = Toml.Table.find (Toml.key "tables") table
|> Toml.to_table_array;;
val array_of_tables : Toml.Value.table list = [<abstr>; <abstr>]
All conversion functions raise Toml.Value.To.Bad_type if the type is wrong.
val to_bool : Value.value -> boolval to_int : Value.value -> intval to_float : Value.value -> floatval to_string : Value.value -> stringval to_date : Value.value -> Unix.tmval to_table : Value.value -> Value.value Table.tval to_bool_array : Value.value -> bool listval to_int_array : Value.value -> int listval to_float_array : Value.value -> float listval to_string_array : Value.value -> string listval to_date_array : Value.value -> Unix.tm listval to_array_array : Value.value -> Value.array listval to_table_array : Value.value -> Value.table listThese functions take a Toml key, a Toml table, and return a plain OCaml value if the key was found in the table.
Example:
# let table = Toml.Table.empty
|> Toml.Table.add (Toml.key "foo") (Toml.of_string "bar");;
val table : Toml.Value.value Toml.Table.t = <abstr>
# let bar = Toml.get_string (Toml.key "foo") table;;
val bar : bytes = "bar"
# let table = Toml.Table.empty
|> Toml.Table.add (Toml.key "fortytwos")
(Toml.of_int_array [42;42]);;
val table : Toml.Value.value Toml.Table.t = <abstr>
# let fortytwos = Toml.get_int_array (Toml.key "fortytwos") table;;
val fortytwos : int list = [42; 42]
All retrieval functions raise Not_found if the value was not found in the
table, and Toml.Value.To.Bad_type if the type is wrong.
val get_bool : Table.Key.t -> Value.value Table.t -> boolval get_int : Table.Key.t -> Value.value Table.t -> intval get_float : Table.Key.t -> Value.value Table.t -> floatval get_string : Table.Key.t -> Value.value Table.t -> stringval get_date : Table.Key.t -> Value.value Table.t -> Unix.tmval get_table : Table.Key.t ->
Value.value Table.t -> Value.value Table.tval get_bool_array : Table.Key.t -> Value.value Table.t -> bool listval get_int_array : Table.Key.t -> Value.value Table.t -> int listval get_float_array : Table.Key.t -> Value.value Table.t -> float listval get_string_array : Table.Key.t -> Value.value Table.t -> string listval get_date_array : Table.Key.t -> Value.value Table.t -> Unix.tm listval get_array_array : Table.Key.t -> Value.value Table.t -> Value.array listval get_table_array : Table.Key.t ->
Value.value Table.t -> Value.value Table.t listThese shorthand functions take an OCaml value and turn them into the appropriate Toml value.
Example:
# let table = Toml.Table.empty
|> Toml.Table.add (Toml.key "fortytwos")
(Toml.of_int_array [42;42]);;
val table : Toml.Value.value Toml.Table.t = <abstr>
val of_bool : bool -> Value.valueval of_int : int -> Value.valueval of_float : float -> Value.valueval of_string : string -> Value.valueval of_date : Unix.tm -> Value.valueval of_table : Value.table -> Value.valueval of_bool_array : bool list -> Value.valueval of_int_array : int list -> Value.valueval of_float_array : float list -> Value.valueval of_string_array : string list -> Value.valueval of_date_array : Unix.tm list -> Value.valueval of_array_array : Value.array list -> Value.valueval of_table_array : Value.table list -> Value.valuemodule Parser:sig..end
module Printer:sig..end
module Compare:sig..end