main.bend source
main.bend on the hub · documented module
# eztoml: the TOML slice for string-valued sectioned docs. A line is blank, a# comment, a `[section]` header, or a `key = "value"` pair. A header is a# dotted path whose segments may be quoted, and a key may be quoted, so a file# path can be one. No arrays, no inline tables, no numbers.## parse, render, value, sects, segments, quote, key# types: Kv, Sect, Tomlimport Baseimport ./toml.bend as T# a key and the string written for itdef Kv(+key: String, +val: String) -> T.Kv: T.Kv{key, val}# a section header and the pairs under it, in the order they were writtendef Sect(+name: String, pairs: List<&2, T.Kv>) -> T.Sect: T.Sect{name, pairs}# the sections read so far, and the first error if there was onedef toml(bad: String, name: String, pairs: List<&2, T.Kv>, done: List<&2, T.Sect>) -> T.Toml: T.Toml{bad, name, pairs, done}# the sections of a document, and the first error if there was onedef parse(text: String) -> T.Toml: T.parse(text)# a document of tables, one blank line between themdef render(ss: List<&2, T.Sect>) -> String: T.render(ss)# the value written for a key in a table, or "" when it is absentdef value(pairs: List<&2, T.Kv>, +key: String) -> String: T.value(pairs, key)# the sections a parse found, in the order they were writtendef sects(t: T.Toml) -> List<&2, T.Sect>: T.sects(t)# a header's segments, unquoted. `packages."0x0a".files` is three of themdef segments(s: String) -> List<&2, String>: T.segments(s)# a string in quotes, which is how a segment or a key that is not bare is# written, and how every value isdef quote(+s: String) -> String: T.quote(s)# a key as it is written: bare when it can be, quoted when it must bedef key(+s: String) -> String: T.key(s)