Page
Library
Module
Module type
Parameter
Class
Class type
Source
Base.TomlImplementationSourceRaised when a TOML value type is not what an accessor or another function expects.
Raised when the parser encounters invalid TOML syntax. The first member of the tuple is the source file position (line and column).
type t = | TomlString of string| TomlInteger of toml_integer| TomlFloat of toml_float| TomlBoolean of bool| TomlOffsetDateTime of toml_date| TomlLocalDateTime of toml_date| TomlLocalDate of toml_date| TomlLocalTime of toml_date| TomlArray of t list| TomlTable of (string * t) list| TomlInlineTable of (string * t) list| TomlTableArray of t listmodule Printer : sig ... endmodule Parser : sig ... endConstructors create TOML values from OCaml values.
val string : string -> tval integer : toml_integer -> tval float : toml_float -> tval boolean : bool -> tAccessors can be used by themselves on TOML values, or passed to high-level interface functions such as find.
By default they expect a strict match, e.g. get_string fails on values other than TomlString _. However, they all provide a boolean ~strict argument that enables type conversion when set to false. Not all types can be converted between each other, so ~strict:false does not prevent all type errors.
All accessors will raise Type_error exception if type conversion is disabled or fails. High-level interface functions handle those exceptions, so you don't need to handle it.
If you want to use accessors directly on TOML values and you want option or result values instead of exceptions, you can use get_opt and get_result combinators.
Unwraps a table and applies an accessor to the values of its fields, useful for unwrapping tables with homogenous field types in a single step.
Converts a TOML array to a list of OCaml values by applying an accessor function to each of them.
For example, if you want to retrieve an array of strings, you can use get_array get_string toml_value.
In non-strict mode, forces a value x to a single-item array [x].
Note that the strict flag is not passed to the accessor. If you want the accessor to also attempt type conversion on the array values, you should specify it explicitly: get_array ~strict:false (get_string ~strict:false) toml_value.
val get_string : ?strict:bool -> t -> stringIn non-strict mode, converts integer, float, boolean, and datetime values to strings. Trying to convert an array or a table to string will raise Type_error.
val get_integer : ?strict:bool -> t -> toml_integerIn non-strict mode, converts string and boolean values to integers.
Strings are parsed as integers, true is converted to 1, false is converted to 0, and floats are truncated.
val get_float : ?strict:bool -> t -> toml_floatIn non-strict mode, converts string, boolean, and integer values to floats.
val get_boolean : ?strict:bool -> t -> boolIn non-strict mode, converts integer, float, and string values to booleans.
The conversion logic mimics "truth values" in dynamically typed languages. Empty strings, numeric values 0 (integer) and 0.0 (float), empty arrays and tables are treated as false, everything else is true.
In non-strict mode, these functions will try to convert strings to dates.
In the default implementation dates are represented as strings, so the conversion is a no-op.
They will handle the Stdlib.Failure exception raised by string to datetime conversion functions. Thus if you supply your own datetime module to the functorial interface, you may want to catch exceptions raised by your library of choice and re-raise them as Failure.
These combinators are mainly useful for unwrapping standalong TOML values by hand. They handle the Type_error exception and return None or Error msg when it occurs.
The high-level interface functions handle exceptions raised by accessors themselves.
val get_result : ('a -> 'b) -> 'a -> ('b, string) resultval path_exists : t -> string list -> boolReturns true if there is a value at the specified path in a table.
For the purpose of this function, an empty table does exist, i.e. if you have foo.bar = {}, then path_exists t ["foo"; "bar"] is true.
val list_table_keys : t -> string listReturns a list of all keys of a table, in their original order.
val list_table_keys_exn : t -> string listLooks up a value in a table and unwraps it using an accessor function.
Updates a table field at a specified path.
Passing Some toml_value inserts a new value or replaces an existing value.
If a key path partially does not exist, additional tables are created as needed. For example, update (TomlTable []) ["foo"; "bar"] (Some (TomlString "baz"))] will produce TomlTable [("foo", TomlTable [("bar", TomlString "baz")])].
The use_inline_tables flag determines whether automatically-created missing tables will be normal or inline tables.
Passing None as the argument will delete the field at the specified path. It's safe to attempt deleting values at paths that don't exist: there will be no error and the original TOML will be returned unchanged.
Makes a printable representation of a table key path, for example, ["foo"; "bar baz"; "quux"] gives foo."bar baz".quux.
module Helpers : sig ... end