From 2e778f3b31c4a8d3e0f9c9465caa7a1f96615af3 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Thu, 24 Sep 2026 22:43:05 +0200 Subject: [PATCH] Name a cell's line in its link-time errors, and say where a format holding a reference compiles --- node.go | 9 ++++----- reference.go | 3 +++ table.go | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/node.go b/node.go index 978efc8..8151be8 100644 --- a/node.go +++ b/node.go @@ -41,7 +41,7 @@ func (*null) isNode() {} // template renders a format string, substituting {tokens} from fields. A bare // JSON string is a template with no fields. repeat (default 1) renders that format // that many times and joins the results with separator (default ""), each render -// an independent pick. +// an independent pick. A format holding a reference compiles in `linkTemplateRefs`. type template struct { // Filled by `compileString`, `compileTemplate` and `table.compileWhole`: format string @@ -207,14 +207,13 @@ func compileString(s string) (node, error) { return nil, err } t := &template{format: s, repeat: 1, fromString: true} - if err := t.compileUnbound(); err != nil { + if err := t.compileRefFree(); err != nil { return nil, err } return t, nil } -// compileUnbound compiles a format holding no reference; `linkTemplateRefs` compiles the rest. -func (t *template) compileUnbound() error { +func (t *template) compileRefFree() error { if len(refTokens(t.format)) > 0 { return nil } @@ -339,7 +338,7 @@ func compileTemplate(m map[string]any, pos position) (node, error) { return nil, err } t := &template{format: o.format, fields: fields, repeat: o.repeat, separator: o.separator, datatype: o.datatype, drawGroup: o.group, record: fieldPos == inColumn} - if err := t.compileUnbound(); err != nil { + if err := t.compileRefFree(); err != nil { return nil, err } return t, nil diff --git a/reference.go b/reference.go index f1e34c7..00d09e8 100644 --- a/reference.go +++ b/reference.go @@ -91,6 +91,9 @@ func linkTemplateRefs(folder []string, path, category string, t *template, root if len(names) == 0 { return nil } + if t.cellOf != nil { + path = fmt.Sprintf("%s, line %d", path, t.cellRow+2) + } t.refs = make(map[string]refBinding, len(names)) t.refHeads = make(map[string]node, len(names)) for _, name := range names { diff --git a/table.go b/table.go index 54bf4ff..e4cb88f 100644 --- a/table.go +++ b/table.go @@ -335,7 +335,7 @@ func (t *table) compileWhole(format string) error { } t.format = &template{format: format, fields: t.fields, repeat: 1, record: true, table: t} t.whole = &row{t} - return t.format.compileUnbound() + return t.format.compileRefFree() } // setTablePaths gives every table the path a selector on it is written at, before a