Rename template.go to format.go, a table's tokens to cellTemplates, drawAt.alt to pinned and ftoken's brace-body kind to 't', and drop the done item

This commit is contained in:
2026-09-25 17:28:35 +02:00
committed by Lillem4n
parent 191186ec94
commit 005f4d7adc
11 changed files with 44 additions and 49 deletions
+1 -1
View File
@@ -870,7 +870,7 @@ render.go Fake and the recursive renderer (choices, format strings, expans
record.go records: Record, the JSON/CSV/SQL serializers, and their entry points
struct.go structs: FakeStruct, fake tags, and a field's Go type as its column's datatype
inline.go inline templates: Template, NewTemplate, FakeTemplate, IsTemplate, and their compile and link
template.go the {token} grammar: scanning, tokens, operands, validation, compiling a format
format.go the {token} grammar: scanning, tokens, operands, validation, compiling a format
hold.go the hold: one draw per held name, and reading a field through it
holdfence.go the load fences over the hold: the routes and spellings that read one held name two ways
holdset.go one reference draw per render and group: the hold set a render reads its paths through
+7 -7
View File
@@ -193,7 +193,7 @@ type drawWalk struct {
type drawAt struct {
group string
route drawRoute
alt pinSet
pinned pinSet
drawn *table // left out of the visit keys: only this table's own cells compare against it, which the own-family fence keeps true
whole pinSet
}
@@ -211,13 +211,13 @@ type pathRead struct {
type nodeVisit struct {
n node
group string
alt string
rows string
}
type readKey struct {
group string
path string
alt string
rows string
}
func newDrawWalk() *drawWalk {
@@ -251,16 +251,16 @@ func (w *drawWalk) walk(n node, at drawAt) {
in.whole = at.whole.clone()
in.whole.add(cell.cellOf, cell.cellRow)
w.edge(n, e, in)
case at.alt.clash(cell.cellOf, cell.cellRow) == nil:
case at.pinned.clash(cell.cellOf, cell.cellRow) == nil:
in := at
in.alt = at.alt.entered(cell.cellOf, cell.cellRow)
in.pinned = at.pinned.entered(cell.cellOf, cell.cellRow)
w.edge(n, e, in)
}
}
}
// rowsKey spells the rows the walk stands in, pinned and whole, for a map.
func (at drawAt) rowsKey() string { return at.alt.key() + "|" + at.whole.key() }
func (at drawAt) rowsKey() string { return at.pinned.key() + "|" + at.whole.key() }
// edge records the reference an edge reads, then walks on with every row the read
// pins entered, so a selected row renders only its own cells.
@@ -272,7 +272,7 @@ func (w *drawWalk) edge(from node, e renderEdge, at drawAt) {
w.reads = append(w.reads, pathRead{at, a, tr})
}
if tr != nil {
tr.pins.each(func(t *table, r int) { at.alt = at.alt.entered(t, r) })
tr.pins.each(func(t *table, r int) { at.pinned = at.pinned.entered(t, r) })
}
}
w.walk(e.to, at)
+1 -1
View File
@@ -219,4 +219,4 @@ func checkOwnFamily(t *template) error {
// alternatives reports whether two reads sit in different rows of one table: rows the walks pinned,
// or rows of one whole draw.
// docs/decisions.md#the-rows-of-a-table-are-alternatives
func alternatives(a, b drawAt) bool { return a.alt.differs(&b.alt) || a.whole.differs(&b.whole) }
func alternatives(a, b drawAt) bool { return a.pinned.differs(&b.pinned) || a.whole.differs(&b.whole) }
+2 -2
View File
@@ -8,7 +8,7 @@ import (
// ftoken is one unit of a scanned format string: a literal rune or the body of a
// {…} token.
type ftoken struct {
kind byte // 'l' literal rune, 'b' brace body
kind byte // 'l' literal rune, 't' token body
r rune
body string
}
@@ -38,7 +38,7 @@ func eachToken(format string, fn func(ftoken) error) error {
if end >= len(rs) {
return fmt.Errorf("unterminated '{' in %q", format)
}
t.kind, t.body = 'b', string(rs[i+1:end])
t.kind, t.body = 't', string(rs[i+1:end])
i = end
case '}':
if i+1 < len(rs) && rs[i+1] == '}' {
View File
+1 -1
View File
@@ -63,7 +63,7 @@ func contained(n node) []namedNode {
case *table:
return append([]namedNode{{node: n.format}}, named(n.fields)...)
case *column:
if len(n.t.tokens) == 0 {
if len(n.t.cellTemplates) == 0 {
return nil
}
var out []namedNode
+1 -1
View File
@@ -97,7 +97,7 @@ func readsFact(n node) string {
}
case *table:
collect(n.format)
for _, cell := range n.tokens {
for _, cell := range n.cellTemplates {
collect(cell)
}
case *template:
+6 -6
View File
@@ -22,7 +22,7 @@ type table struct {
fields map[string]node // column nodes, the format's fields
whole *row // the pinned row rendered by the format
cells []string // rows × columns, flat
tokens map[int]*template
cellTemplates map[int]*template
key int // key, name, weight and parent are column indexes, or -1
name int
weight int
@@ -64,7 +64,7 @@ func (t *table) cell(row, col int) string { return t.cells[row*len(t.columns)+co
// cellNode is what a cell renders: its compiled template where it carries tokens,
// else nil for its text.
func (t *table) cellNode(row, col int) *template { return t.tokens[row*len(t.columns)+col] }
func (t *table) cellNode(row, col int) *template { return t.cellTemplates[row*len(t.columns)+col] }
// tableOptions are the keys a table object takes; every other key is refused.
var tableOptions = []string{"format", "key", "name", "parent", "rows", "weight"}
@@ -312,11 +312,11 @@ func (t *table) checkCells() error {
if err != nil {
return fmt.Errorf("line %d, %s: %w", row+2, t.columns[col], err)
}
if t.tokens == nil {
t.tokens = map[int]*template{}
if t.cellTemplates == nil {
t.cellTemplates = map[int]*template{}
}
t.tokens[i] = n.(*template)
t.tokens[i].cellOf, t.tokens[i].cellRow = t, row
t.cellTemplates[i] = n.(*template)
t.cellTemplates[i].cellOf, t.cellTemplates[i].cellRow = t, row
}
return nil
}
+2 -2
View File
@@ -996,8 +996,8 @@ func TestEnteredRowsAgreeWithPinning(t *testing.T) {
for cr := 0; cr < cand.rows(); cr++ {
beside := s.clone()
refused := beside.pinRow(cand, cr) != nil
pinned := drawAt{alt: none.entered(cand, cr)}
if got := alternatives(drawAt{alt: s}, pinned); got != refused {
pinned := drawAt{pinned: none.entered(cand, cr)}
if got := alternatives(drawAt{pinned: s}, pinned); got != refused {
t.Errorf("alternatives(%s, %s) = %v, but pinning both refuses = %v", entered.selectorSpelling(row), cand.selectorSpelling(cr), got, refused)
}
if alternatives(whole, pinned) || alternatives(pinned, whole) {
-5
View File
@@ -19,11 +19,6 @@ Self-sufficiency 5.6), every seat capped by Locality or Self-sufficiency.
This round, in order:
- Rename what names two things: `template.go` holds the token grammar while `template`
is `node.go`'s type and `Template` `inline.go`'s; `kind` `'b'` is a brace body in
`ftoken` and a builtin in `formatToken` and `op`; `tokens` is a template's parsed format
and a table's cell templates; `drawAt.alt` holds the rows
a walk entered.
- Run the nine-seat panel again and file what it names here.
### Data