Module encoding/toml

encoding/toml

Basic TOML parser for configuration files.

Parses a subset of TOML into a TomlValue tree. Supports: strings, integers, booleans, table sections, comments.

Example

{ toml_parse, TomlValue } :: import "std/encoding/toml";
// Or via the encoding index:
{ toml_parse, TomlValue } :: import "std/encoding";

Types

TomlValue enum
TomlValue

TOML value type — the result of parsing a TOML document.

Variants

VariantFieldsDescription
Strvalue: String

A TOML string value.

Intvalue: i64

A TOML integer value.

Boolvalue: bool

A TOML boolean value.

Tablekeys: ArrayList(String), values: ArrayList(enum(Str(value: String), Int(value: i64), Bool(value: bool)))

A TOML table (ordered key-value map).

impl(TomlValue, ...)
new_table : (TomlValue) fn() -> TomlValue

Create a new empty table.

Returns: TomlValue

get : (TomlValue) fn(self : TomlValue, key : String) -> Option(TomlValue)

Look up a value by key in a table. Returns .None if not a table or key is missing.

Parameters

NameTypeNotes
selfTomlValue
keyString

Returns: Option(TomlValue)

has_key : (TomlValue) fn(self : TomlValue, key : String) -> bool

Check whether the table contains the given key.

Parameters

NameTypeNotes
selfTomlValue
keyString

Returns: bool

set : (TomlValue) fn(self : TomlValue, key : String, value : TomlValue) -> unit

Insert or update a key-value pair in the table.

Parameters

NameTypeNotes
selfTomlValue
keyString
valueTomlValue

Returns: unit

table_len : (TomlValue) fn(self : TomlValue) -> usize

Return the number of keys in the table, or 0 if not a table.

Parameters

NameTypeNotes
selfTomlValue

Returns: usize

as_string : (TomlValue) fn(self : TomlValue) -> Option(String)

Extract the string value, or .None if not a Str.

Parameters

NameTypeNotes
selfTomlValue

Returns: Option(String)

as_int : (TomlValue) fn(self : TomlValue) -> Option(i64)

Extract the integer value, or .None if not an Int.

Parameters

NameTypeNotes
selfTomlValue

Returns: Option(i64)

as_bool : (TomlValue) fn(self : TomlValue) -> Option(bool)

Extract the boolean value, or .None if not a Bool.

Parameters

NameTypeNotes
selfTomlValue

Returns: Option(bool)

Functions

toml_parse function
fn(input : String) -> Result(TomlValue, String)

Parse a TOML string into a TomlValue tree. Returns Result(TomlValue, String).

Parameters

NameTypeNotes
inputString

Returns: Result(TomlValue, String)