~/bend-docscommunity

toml/toml.bend checks

raw source on the hub · import 0x046551eff0d59a82cf10d858b17b0c84/toml/toml.bend as Toml

toml/toml: ez's view of a TOML document: sections of string pairs. ez's ledger and lock are documents of tables of string (and one boolean) pairs, and every command reads them as a list of sections, each a header's segments and the pairs under it. Reading and writing TOML are eztoml's: parse walks the document eztoml's parse reads into that list, and normal writes a document through eztoml's render. Only eztoml's interface, main.bend, is imported; that a document it renders reads back as itself is its TOML-RT-1, trusted as EZ-TRUST-8.

The rest is ez's own and pure: finding a key's value, a header's segments, and the text of a section in the form ez assembles a document in before eztoml writes it (render). That form is the TOML ez wrote before eztoml 0.4, so an old ledger or lock and a new one read to the same sections.

2 imports
import Base
import 0x8fb95168b7719a8faec16af7ee47b246/main.bend as E

Types

type Kv source · line 18 · raw

Data

a key and the string written for it

type Sect source · line 22 · raw

Data

a section header and the pairs under it, in the order they were written

type Toml source · line 28 · raw

Data

a document read: the first error, "" when there is none, a name kept for the shape callers match on (always ""), the pairs above the first header, and every section that holds a pair, or holds no table, in document order

type Sym source · line 56 · raw

Data

what a header's next character is: the quoting toggles, an unquoted dot cuts, anything else is kept

type Split source · line 68 · raw

Data

a header being cut apart: quoted is true inside quotes, cur is the segment being gathered and out the finished ones, both reversed

Definitions

def value.at source · line 33 · raw

@kv:Kv -> @rest:String -> @key:String -> String

this pair's value when the key matches, otherwise whatever the rest of the table gave

def value source · line 39 · raw

@pairs:List<&2, Kv> -> @+key:String -> String

the value written for a key in a table, or "" when it is absent. The scan recurses first and picks after, so no recursive call hides inside a branch.

def sects source · line 47 · raw

@doc:Toml -> List<&2, Sect>

the sections a parse found, in the order they were written

def seg.sym source · line 62 · raw

@+ch:Char -> Sym

a header char classified. +ch because it is both asked about and kept.

def seg.done source · line 72 · raw

@cur:List<&2, Char> -> String

the segment gathered so far, in order

def seg.dot source · line 76 · raw

@quoted:Bool -> @cur:List<&2, Char> -> @out:List<&2, String> -> Split

a dot inside quotes is part of the segment; outside, it ends one

def seg.go source · line 84 · raw

@st:Split -> @sym:Sym -> Split

the state once a char has been classified

def seg.step source · line 95 · raw

@st:Split -> @ch:Char -> Split

one char of a header against the state

def seg.fin source · line 99 · raw

@st:Split -> List<&2, String>

the segment still being gathered, closed, and the rest put back in order

def seg.walk source · line 104 · raw

@cs:List<&2, Char> -> @st:Split -> Split

the walk one char at a time, written out rather than folded

def segments source · line 113 · raw

@head:String -> List<&2, String>

a header's segments, unquoted. packages."0x0a".files is three of them, and a quoted segment may hold the dots a bare one may not.

def quote source · line 118 · raw

@+text:String -> String

a string in quotes, which is how a segment or a key that is not bare is written, and how every value is

def bare.at source · line 123 · raw

@+ch:Char -> Bool

a char a bare key may hold. +ch because it is asked four questions; a predicate handed to a fold may not take one, so it is split out here.

def bare.all.step source · line 130 · raw

@here:Bool -> @rest:(@_:Unit -> Bool) -> Bool

one step of the walk, with the head's answer in hand. Bool.and runs both of its sides, so the first char that a bare key may not hold still cost a walk of the rest of the key.

def bare.all source · line 140 · raw

@cs:List<&2, Char> -> Bool

whether every char of a key is one a bare key may hold. Base's List.all applies an erased function parameter and so falls outside the termination check; this walk is structural.

def bare source · line 148 · raw

@+text:String -> Bool

whether a key can be written without quotes

def key source · line 152 · raw

@+text:String -> String

a key as it is written: bare when it can be, quoted when it must be

def render.pair source · line 159 · raw

@kv:Kv -> String

one key = "value" line

def render.pairs source · line 164 · raw

@ps:List<&2, Kv> -> String

every pair of a section, in the order it holds them

def render.sect source · line 173 · raw

@sect:Sect -> String

one table: its header, then its pairs. The header is written as it is given, so a caller that needs a quoted segment quotes it.

def render.all source · line 178 · raw

@ss:List<&2, Sect> -> List<&2, String>

every table of a document

def render source · line 187 · raw

@ss:List<&2, Sect> -> String

a document of tables, one blank line between them, as ez assembles it; normal is what is written

def normal source · line 191 · raw

@text:String -> String

a document written as eztoml writes it: read by eztoml, and rendered back

def flag.text source · line 198 · raw

@bit:Bool -> String

a truth value as TOML writes it

def pair.of source · line 208 · raw

@+name:String -> @val:0x8fb95168b7719a8faec16af7ee47b246/main.Val -> List<&2, Kv>

a pair whose value is written as text: a string or a boolean, as ez writes them; an integer as its digits. A table, an array or an inline table is not a pair of the section.

def pairs.of source · line 222 · raw

@rows:List<&2, 0x8fb95168b7719a8faec16af7ee47b246/main.Val> -> List<&2, Kv>

the pairs among a table's rows, in order

def row.table source · line 232 · raw

@row:0x8fb95168b7719a8faec16af7ee47b246/main.Val -> Bool

whether a row is a table

def has.table.step source · line 240 · raw

@here:Bool -> @rest:(@_:Unit -> Bool) -> Bool

the rest of the walk, when this row was not a table

def has.table source · line 248 · raw

@rows:List<&2, 0x8fb95168b7719a8faec16af7ee47b246/main.Val> -> Bool

whether a table's rows hold a table, stopping at the first

def head.of source · line 256 · raw

@segs:List<&2, String> -> String

a header as ez names it: its segments, each bare or quoted, joined by dots

def sect.put source · line 270 · raw

@skip:Bool -> @+ps:List<&2, Kv> -> @+segs:List<&2, String> -> List<&2, Sect>

a table's section, when it holds a pair or no table. A table that holds only tables is the parent a dotted header implies, which ez never writes a pair into; old ledgers and locks name no such table, so it is no section. (segs arrive innermost first, as tables builds them; the header reads them outermost first)

def sect.keep source · line 277 · raw

@+ps:List<&2, Kv> -> @parent:Bool -> @+segs:List<&2, String> -> List<&2, Sect>

def table.sects source · line 281 · raw

@+segs:List<&2, String> -> @+sub:List<&2, 0x8fb95168b7719a8faec16af7ee47b246/main.Val> -> @inner:List<&2, Sect> -> List<&2, Sect>

a table's section, then the sections of the tables in it

def tables source · line 287 · raw

@rows:List<&2, 0x8fb95168b7719a8faec16af7ee47b246/main.Val> -> @+segs:List<&2, String> -> List<&2, Sect>

the sections of every table among a table's rows, in document order: each table's own section, then the tables in it, then the tables after it. The path to the table is kept innermost first, so a level prepends its name.

def parse.of source · line 298 · raw

@+doc:0x8fb95168b7719a8faec16af7ee47b246/main.Doc -> Toml

a document eztoml read, as sections

def parse source · line 303 · raw

@text:String -> Toml

a document read from TOML text: eztoml's reading of it, as sections

def show.kv source · line 310 · raw

@kv:Kv -> String

a pair as key=value

def show.kvs source · line 315 · raw

@ps:List<&2, Kv> -> List<&2, String>

every pair of a section, shown

def show.sect source · line 323 · raw

@sect:Sect -> String

a section as name key=value ..

def show.sects source · line 328 · raw

@ss:List<&2, Sect> -> List<&2, String>

every section of a document, shown