TOML text to nested dicts (Effect's encoding/Toml, whose behaviour is
based on the toml 4.1.2 package). It parses what Effect's parser parses and
rejects what it rejects, which is not always what tomllib does; use
tomllib when a file must follow the TOML specification to the letter.
A date-time with an offset is a datetime in UTC (Effect's Date, within the
years datetime holds); a local date, date-time or time stays text. parse
returns a Result: invalid text is an EncodingError with Effect's message,
its position counted in UTF-16 code units.
Functions#
parse#
parse(text) -> Result[dict[str, Any], EncodingError]The tables, keys and values of text, or an EncodingError
(module "Toml") giving what is wrong and where.
| Parameter | Type | Description |
|---|---|---|
text | str |
Returns Result[dict[str, Any], EncodingError]
def parse(text: str, /) -> Result[dict[str, Any], EncodingError]:
"""The tables, keys and values of ``text``, or an ``EncodingError``
(module ``"Toml"``) giving what is wrong and where."""
try:
return Ok(parse_nested(_Parser(text.removeprefix("\ufeff")).parse))
except ValueError as error:
return Err(EncodingError(kind="Decode", module="Toml", input=text, message=str(error)))