diff --git a/README.md b/README.md index 66dbb2d..01f76cf 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/drawfence.go b/drawfence.go index 3d5a400..def7c1c 100644 --- a/drawfence.go +++ b/drawfence.go @@ -191,11 +191,11 @@ type drawWalk struct { // table rows it pinned, the table a whole read draws a row of, and the rows of whole draws whose // cells the walk is in. type drawAt struct { - group string - route drawRoute - alt 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 + group string + route drawRoute + 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 } // drawRoute is how a render reaches a draw: as its author spells it, and the root edge's label. @@ -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) diff --git a/family.go b/family.go index 55646fb..18230d0 100644 --- a/family.go +++ b/family.go @@ -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) } diff --git a/template.go b/format.go similarity index 99% rename from template.go rename to format.go index 7217f3f..7224bce 100644 --- a/template.go +++ b/format.go @@ -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] == '}' { diff --git a/template_stability_test.go b/format_stability_test.go similarity index 100% rename from template_stability_test.go rename to format_stability_test.go diff --git a/template_test.go b/format_test.go similarity index 100% rename from template_test.go rename to format_test.go diff --git a/graph.go b/graph.go index fc43333..d17b10c 100644 --- a/graph.go +++ b/graph.go @@ -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 diff --git a/shape_test.go b/shape_test.go index e9d418e..3b6c2c4 100644 --- a/shape_test.go +++ b/shape_test.go @@ -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: diff --git a/table.go b/table.go index f60d9cd..b06fcd3 100644 --- a/table.go +++ b/table.go @@ -13,26 +13,26 @@ import ( // columns, each row is one draw, and the format renders the drawn row. A column is a // cell of the row a render pinned; a cell carrying tokens compiles to a string node. type table struct { - category string - path string // the category's path from the data root, which a selector is written at - file string - format *template // fields are the column nodes - columns []string - col map[string]int - 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 - key int // key, name, weight and parent are column indexes, or -1 - name int - weight int - parent int - cum []float64 // cumulative weights, nil when uniform - byKey map[string]int - parentT *table - children map[string]*table - once sync.Once - index tableIndex + category string + path string // the category's path from the data root, which a selector is written at + file string + format *template // fields are the column nodes + columns []string + col map[string]int + fields map[string]node // column nodes, the format's fields + whole *row // the pinned row rendered by the format + cells []string // rows × columns, flat + cellTemplates map[int]*template + key int // key, name, weight and parent are column indexes, or -1 + name int + weight int + parent int + cum []float64 // cumulative weights, nil when uniform + byKey map[string]int + parentT *table + children map[string]*table + once sync.Once + index tableIndex } // tableIndex is what selection and linked draws look up, built on the first draw @@ -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 } diff --git a/table_test.go b/table_test.go index 8097a17..8fce3e6 100644 --- a/table_test.go +++ b/table_test.go @@ -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) { diff --git a/todo.md b/todo.md index 7b9aa8c..8ae15fc 100644 --- a/todo.md +++ b/todo.md @@ -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