Module Serialkit_toml.Toml

TOML definitions and codec.

TOML

val file_ext : string

file_ext is ".toml".

val mime_type : string

mime_type is "application/toml".

module Meta : sig ... end

TOML node metadata.

type 'a node = 'a * Meta.t

The type for data nodes. The node and its metadata.

type tz_offset_s = int

The type for time zone offsets between local and UTC timelines in seconds. This is the signed difference in seconds between the local timeline and the UTC timeline.

type date = int * int * int

The type dates. A year, a month and a day.

type time = (int * int * int) * float option * tz_offset_s option
type date_time = date option * time option
type table = (string node * value) node list
and value = [
  1. | `Boolean of bool node
  2. | `Integer of int64 node
  3. | `Float of float node
  4. | `String of string node
  5. | `Array of value list node
  6. | `Date_time of date_time node
  7. | `Table of table node
]
type t = table node

The type for TOML documents.

Formatting

type 'a fmt = Stdlib.Format.formatter -> 'a -> unit

The type for formatting functions.

val pp : t fmt

pp formats TOML.

val pp_layout : t fmt

pp_layout is like pp but uses layout information.

val pp_value : value fmt

pp_value formats TOML values.

Codec

module Error : sig ... end

Decoding errors.

val of_string : ?file:Serialkit_text.Tloc.fpath -> string -> (t, Error.t) Stdlib.result

of_string s parses TOML from s with the following limitations:

  • The ranges of date and time fields are checked but dates are not checked for validity. Use your favourite date-time library to validate them.

Note. All OCaml strings returned by this function are UTF-8 encoded.

val of_string' : ?pp_error:Error.t fmt -> ?file:Serialkit_text.Tloc.fpath -> string -> (t, string) Stdlib.result

of_string' is of_string composed with error_to_string.

val to_string : t -> string

to_string t is t as TOML.

Warning. Assumes all OCaml strings in t are UTF-8 encoded.

TOML indices

type index =
  1. | Nth of int
  2. | Key of string

The type for TOML indexing operations.

  • Nth n, lookup zero-based element n in a list. If n is negative, counts the number of elements from the end of the list, i.e. -1 is the last list element.
  • Key k, lookup binding k in an s-expression dictionary.
val pp_key : string fmt

pp_key formats a key, this is Format.pp_print_string.

val pp_index : ?pp_key:string fmt -> unit -> index fmt

pp_index formats indices. Keys are unbracketed and formatted with pp_key, defaults to pp_key.

TOML paths

type path = index list

The type for paths, a sequence of indexing operations in reverse order.

val path_of_string : string -> (path, string) Stdlib.result

path_of_string parses a path from s according to the syntax given here.

val pp_path : ?pp_key:string fmt -> unit -> path fmt

pp_path ?pp_key () is a formatter for paths using pp_key to format keys (defaults to pp_key).

Carets

type caret_loc =
  1. | Before
    (*

    The void before the TOML found by the path.

    *)
  2. | Over
    (*

    The TOML found by the path.

    *)
  3. | After
    (*

    The void after the TOML found by the path.

    *)

The type for caret locations.

type caret = caret_loc * path

The type for carets. A caret location and the path at which it applies.

val caret_of_string : string -> (caret, string) Stdlib.result

caret_of_string s parses a caret from s according to the syntax given here.

val pp_caret : ?pp_key:string fmt -> unit -> caret fmt

pp_caret ?pp_key () is a formatter for carets using pp_key to format keys (defaults to pp_key).