TOML for Bend 2.
With Bend alone there is nothing to
install: import eztoml by its hub name and version, and bend fetches it
from the hub into ~/.bend/lib on the first
run; no install step. eztoml is built and checked on Bend 2.0.38.
import emerging-eztoml@0.9.0.0/main.bend as Toml
emerging-eztoml@0.9.0.0 is eztoml v0.9.0 and resolves to
0xc5d9d3e28b79ea98be22eb42c7e37802; to pin by content, import
0xc5d9d3e28b79ea98be22eb42c7e37802/main.bend instead.
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 emerging-eztoml@0.9.0.0/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.
Each file under laws/ is one guarantee eztoml makes, against TOML v1.0.0 and toml.abnf, stated as quantified laws under its prose, and proofs/ holds a proof of each by the same name. LAWS.bend and PROOF.bend only import them. A law file marked pending proves part of its guarantee, not all of it. nix flake check runs the proof gate (bend PROOF.bend must print exactly ALL PROOFS CHECK first) and bolt. The headline is the round trip: a document render writes reads back as the same document (laws/RenderThenParse.bend).