Module 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 = {
  1. option_name : string;
  2. option_comments : string list;
  3. option_value : Ez_toml.V1.TOML.Types.value;
}
type section = TYPES.section = {
  1. section_name : string;
  2. section_comments : string list;
  3. section_options : section_option list;
}

Initialization & Accessor

val make_empty : unit -> toml_handle

Creates a new handle with an empty TOML table.

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).

Section definitions

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.

Input/output

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.

Caching

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