TOML for Bend 2.
With Bend alone there is nothing to
install: import eztoml by its hub name and bend fetches it from
the hub into ~/.bend/lib on the first run.
0xd79254973edee82bcf56616220876efe is eztoml v0.5.0.
import 0xd79254973edee82bcf56616220876efe/main.bend as Toml
Or with ez, which records the
package in ez.toml (ez init makes one):
ez add Emerging-Patterns/eztoml
parse reads text into a document. render writes a document back. get
finds a value by key and at finds one by a dotted path. A hit is Found or
Miss. string, digits, and flag read a string, an integer's digits, and
a boolean. root is the document's table and bad is the first error.
str, integer, float, boolean, array, inline, table, and pair
build values. key writes a name bare or as a basic string.
import 0xd79254973edee82bcf56616220876efe/main.bend as Toml
def main() -> IO(Unit):
+doc = Toml.parse("[pkg]\nname = \"app\"\nver = 1\non = true\n")
IO.print(Toml.render(doc))
git clone https://github.com/Emerging-Patterns/eztoml
cd eztoml
mkdir -p bin
bend examples/demo/main.bend -o bin/demo.bin
bin/demo.bin
nix build builds the same fixture to result/bin/demo.
parse takes text, not bytes. Bend's File.read replaces each invalid UTF-8
byte with U+FFFD rather than rejecting it, and U+FFFD is valid in a comment or
a string, so parse reads such a file as the valid text it has become. When
invalid bytes must be refused, check the file as UTF-8 before parse
(TOML-TRUST-3).
SPEC.md lists every behavior eztoml guarantees, against TOML v1.0.0 and toml.abnf, each either proved by a quantified law in LAWS.bend or named as a trusted assumption. A row marked pending is not guaranteed yet. nix flake check runs the proof gate (bend PROOF.bend must print exactly All terms check. first) and bolt, whose trace rule checks that SPEC.md and the laws agree. The headline is the round trip: a document render writes reads back as the same document (TOML-RT-1).