std/toml

TOML 1.0, read into the values of std/json and written back: tables are objects, arrays arrays, strings strings, integers and floats numbers, booleans booleans, and dates and times their text, as RFC 3339 writes them.

import "std/json"
import "std/toml"

Json config = parse_toml(read_text("settings.toml"))?
print(json_text(json_at(config, "/server/host")))
print(to_toml(config))
Function Result
parse_toml(text) a Result[Json]: the document as a table
read_toml(text) a Result[TomlDocument]: the document, in root, and the line of each of its parts, in lines, by JSON Pointer
toml_line(doc, pointer) the line of the part pointer names, as "/program/0/main"; of the nearest table that holds it when the part is not there; 0 when there is none
to_toml(table) the TOML text of a table: its values first, then its tables and arrays of tables, each with its header

Every error says its line, as in line 3: key 'name' is given twice: a key given twice, a table declared twice or added to after it was written inline, a value that is not one, an escape that is not one, a number with a leading zero or a misplaced _, and anything after a value on its line. read_toml gives a program that reads its settings the line of a setting that is wrong, as cuarzo.toml problems are reported.