Ezr_toml
Slightly abstract API to save and load TOML files.
module TYPES : sig ... end
include module type of TYPES
with type toml_handle = TYPES.toml_handle
and type section_option = TYPES.section_option
and type section = TYPES.section
type toml_handle = TYPES.toml_handle
type section_option = TYPES.section_option = {
option_name : string;
option_comments : string list;
option_value : Ez_toml.V1.TOML.Types.value;
}
type section = TYPES.section = {
section_name : string;
section_comments : string list;
section_options : section_option list;
}
val make_empty : unit -> toml_handle
Creates a new handle with an empty TOML table.
val toml : toml_handle -> Ez_toml.V1.TOML.Types.node
Access to the underlying TOML node.
Please handle with care: any mutation of the returned node leads to undefined behaviors (mutations of this node should only happen via update hooks).
val section :
name:string ->
?after_comments:string list ->
section_option list ->
section
Combinator to define sections.
val option :
name:string ->
?after_comments:string list ->
Ez_toml.V1.TOML.Types.value ->
section_option
Combinator to define section options.
val add_section_update :
toml_handle ->
string ->
(name:string -> section) ->
unit
add_section_update handle section_name create_section
equips handle
with an update hook that calls create_section ~name
upon each call to save
, to determine whether the TOML representation needs to be updated.
val load : ?verbose:bool -> string -> toml_handle
load ~verbose filename
load and returns a handle for the TOML file filename
. Returns an empty TOML if filename
does not exist. Raises Sys_error
if the file exists but is not readable.
val reload : ?verbose:bool -> string -> toml_handle -> unit
reload ~verbose filename handle
reloads the TOML file filename
. Resets the handle to an empty TOML if filename
does not exit. Raises Sys_error
if the file exists but is not readable.
val save : ?verbose:bool -> string -> toml_handle -> unit
save ~verbose filename handle
triggers update hooks (that update the TOML representation), and save it in filename
if the representation has been modified.
For the purposes of caching, we reuse the same representation but remove update hooks (that are functional values).
Therefore, these need to be reinstated after loading a handle, using appropriate calls to add_section_update
.
type cacheable = toml_handle
val cacheable : toml_handle -> cacheable
val checksum : toml_handle -> Stdlib.Digest.t