From 6158eb0f46a58d342705850bb5f208b5b73fb4e3 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Mon, 28 Sep 2026 23:41:22 +0200 Subject: [PATCH] Build a table cell's template through compileString, and drop the done round item --- node.go | 12 ++++++++---- table.go | 4 ++-- todo.md | 3 --- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/node.go b/node.go index 352f96b..c6b5a2c 100644 --- a/node.go +++ b/node.go @@ -68,7 +68,7 @@ type cellSite struct { row int } -// templateLink is what a template's references resolve to in the assembled tree. +// templateLink is what a template resolves to in the assembled tree. type templateLink struct { refs map[string]refBinding // each reference the format reads -> what it resolves to refHeads map[string]node // each refBinding.key -> the category it names @@ -172,7 +172,11 @@ func compileAt(v any, pos position) (node, error) { func compileItem(v any, pos position) (node, error) { switch v := v.(type) { case string: - return compileString(v) + t, err := compileString(v, cellSite{}) + if err != nil { + return nil, err + } + return t, nil case []any: return compileChoice(v, pos) case map[string]any: @@ -199,12 +203,12 @@ func jsonKind(v any) string { return fmt.Sprintf("%T", v) } -func compileString(s string) (node, error) { +func compileString(s string, cell cellSite) (*template, error) { toks, err := parseChecked(s, nil) if err != nil { return nil, err } - return &template{format: s, tokens: toks, repeat: 1, fromString: true}, nil + return &template{format: s, tokens: toks, repeat: 1, fromString: true, cell: cell}, nil } // fixedText is one render's output when the format holds no token; repeat is the caller's. diff --git a/table.go b/table.go index 4c9165d..d407d26 100644 --- a/table.go +++ b/table.go @@ -308,14 +308,14 @@ func (t *table) checkCells() error { if strings.IndexByte(cell, '{') < 0 && strings.IndexByte(cell, '}') < 0 { continue } - toks, err := parseChecked(cell, nil) + n, err := compileString(cell, cellSite{t, row}) if err != nil { return fmt.Errorf("line %d, %s: %w", row+2, t.header[col], err) } if t.cellTemplates == nil { t.cellTemplates = map[int]*template{} } - t.cellTemplates[i] = &template{format: cell, tokens: toks, repeat: 1, fromString: true, cell: cellSite{t, row}} + t.cellTemplates[i] = n } return nil } diff --git a/todo.md b/todo.md index 3420edc..25716c2 100644 --- a/todo.md +++ b/todo.md @@ -23,9 +23,6 @@ Shape 5.8, Self-sufficiency 5.7), every seat capped by Locality, all nine naming This round, in order: -- Return each phase's output from compile, link and format compile, not fill - `template`'s 25 fields in place from four files: five seats had to know which phase a - function runs in to know which fields are valid yet. - Make `renderEdges` panic on a node it does not handle, as `render` does: its `default: return nil` silently exempts a new node kind from every fence, and nothing at `expand` says `renderEdges` mirrors it.