From 30d0f84ea4cd7d109de3f0e151062da974fa64e9 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Tue, 29 Sep 2026 10:06:00 +0200 Subject: [PATCH] Drop table.fields for formatTemplate.fields --- graph.go | 2 +- path.go | 4 ++-- table.go | 11 ++++++----- todo.md | 1 - 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/graph.go b/graph.go index fee1b54..bbb226b 100644 --- a/graph.go +++ b/graph.go @@ -61,7 +61,7 @@ func contained(n node) []namedNode { case *template: return namedNodes(n.fields) case *table: - return append([]namedNode{{node: n.formatTemplate}}, namedNodes(n.fields)...) + return append([]namedNode{{node: n.formatTemplate}}, namedNodes(n.formatTemplate.fields)...) case *tableColumn: if len(n.t.cellTemplates) == 0 { return nil diff --git a/path.go b/path.go index 206ec95..ead0746 100644 --- a/path.go +++ b/path.go @@ -438,8 +438,8 @@ func (t *table) step(tail []string) (column node, child *table, err error) { if len(tail) == 0 { return nil, nil, nil } - if i, ok := t.col[tail[0]]; ok { - return t.fields[t.header[i]], nil, nil + if column, ok := t.formatTemplate.fields[tail[0]]; ok { + return column, nil, nil } if child = t.descendant(tail[0]); child == nil { return nil, nil, fmt.Errorf("no column or linked table %q in %s", tail[0], t.segment) diff --git a/table.go b/table.go index a0da290..a5c70e8 100644 --- a/table.go +++ b/table.go @@ -19,7 +19,6 @@ type table struct { formatTemplate *template // fields are the column nodes header []string col map[string]int - fields map[string]node // column nodes, the format's fields rowNode *tableRow cells []string // rows × columns, flat cellTemplates map[int]*template @@ -157,7 +156,6 @@ func (t *table) parseRows(data string) error { } t.header = strings.Split(header, "\t") t.col = make(map[string]int, len(t.header)) - t.fields = make(map[string]node, len(t.header)) for i, name := range t.header { if err := checkName(name); err != nil { return fmt.Errorf("column %w", err) @@ -166,7 +164,6 @@ func (t *table) parseRows(data string) error { return fmt.Errorf("column %q is named twice", name) } t.col[name] = i - t.fields[name] = &tableColumn{t, i} } if header == data { return fmt.Errorf("has no rows below its header; a table is at least two rows") @@ -338,10 +335,14 @@ func (t *table) compileRowFormat(format string) error { } } } - if err := checkTokens(toks, t.fields); err != nil { + fields := make(map[string]node, len(t.header)) + for i, name := range t.header { + fields[name] = &tableColumn{t, i} + } + if err := checkTokens(toks, fields); err != nil { return err } - t.formatTemplate = &template{format: format, tokens: toks, fields: t.fields, repeat: 1, isRecord: true, site: tableSite{t, formatRow}} + t.formatTemplate = &template{format: format, tokens: toks, fields: fields, repeat: 1, isRecord: true, site: tableSite{t, formatRow}} t.rowNode = &tableRow{t} return nil } diff --git a/todo.md b/todo.md index a72d389..9607b20 100644 --- a/todo.md +++ b/todo.md @@ -28,7 +28,6 @@ ranking `readSurvey.walk` hardest and all seven the unit they would least modify This round, in order: -- Drop `table.fields` for `formatTemplate.fields`: one map held in two fields. - Rename `arm.key` to `head`, as `template.head` reads it, leaving `key` the table's key column; give `renderScope.row` a type that is not `tablePin`, since it pins nothing; and name `value.go` by the `valueProof` it holds.