March Docs

Toml

TOML v1.0 parser (pure March, no FFI)

Supports: strings (basic, literal, multiline), integers, floats, booleans, arrays, inline tables, table headers [x], array-of-tables [[x]], dotted keys, quoted keys, comments.

Public API: Toml.parse(src) : Result(TomlValue, TomlError) Toml.parse_exn(src) : TomlValue (panics on error) Toml.to_string(v) : String Toml.get(v, key) : Option(TomlValue) Toml.get_in(v, keys) : Option(TomlValue) Toml.get_str(v, key) : Option(String) Toml.get_int(v, key) : Option(Int) Toml.get_float(v, key) : Option(Float) Toml.get_bool(v, key) : Option(Bool) Toml.get_table(v, key) : Option(TomlValue) Toml.get_array(v, key) : Option(List(TomlValue))

Types

typeTomlValueTomlValue#
typeTomlErrorTomlError = TomlError(String, Int, Int)#

Functions

fngetget(v : TomlValue, key : String) : Option(TomlValue)#

Look up a top-level key in a TOML table value.

    Toml.get(table, "port")  -- Some(TInt(8080)) or None
fnget_arrayget_array(v : TomlValue, key : String) : Option(List(TomlValue))#

Get an array value by key, or None if absent or wrong type.

fnget_boolget_bool(v : TomlValue, key : String) : Option(Bool)#

Get a boolean value by key, or None if absent or wrong type.

fnget_floatget_float(v : TomlValue, key : String) : Option(Float)#

Get a float value by key, or None if absent or wrong type.

fnget_inget_in(v : TomlValue, keys : List(String)) : Option(TomlValue)#

Look up a nested key path.

    Toml.get_in(v, ["server", "host"])
fnget_intget_int(v : TomlValue, key : String) : Option(Int)#

Get an integer value by key, or None if absent or wrong type.

fnget_strget_str(v : TomlValue, key : String) : Option(String)#

Get a string value by key, or None if absent or wrong type.

fnget_tableget_table(v : TomlValue, key : String) : Option(TomlValue)#

Get a table value by key, or None if absent or wrong type.

fnparseparse(src : String) : Result(TomlValue, TomlError)#

Parse a TOML document string. Returns Ok(TomlValue) on success or Err(TomlError(message, line, col)) on failure.

    Toml.parse("port = 8080")  -- Ok(TTable([("port", TInt(8080))]))
fnparse_exnparse_exn(src : String) : TomlValue#

Parse TOML, panicking on error. Useful for compile-time literals.

fnto_stringto_string(v : TomlValue) : String#

Convert a TomlValue to a string representation.