Name a cell's line in its link-time errors, and say where a format holding a reference compiles
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user