From 526832fc3f475e793de5968231816900cce7be2b Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Thu, 24 Sep 2026 22:37:32 +0200 Subject: [PATCH] Compile a format holding a reference once, at link --- node.go | 16 ++++++++++------ table.go | 2 +- todo.md | 2 -- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/node.go b/node.go index 353acae..978efc8 100644 --- a/node.go +++ b/node.go @@ -42,10 +42,6 @@ func (*null) isNode() {} // 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. -// -// What `template.compileFormat` fills is final only once `linkTemplateRefs` has -// run: where the format holds a reference, that binds it and compiles the format -// again. type template struct { // Filled by `compileString`, `compileTemplate` and `table.compileWhole`: format string @@ -211,12 +207,20 @@ func compileString(s string) (node, error) { return nil, err } t := &template{format: s, repeat: 1, fromString: true} - if err := t.compileFormat(); err != nil { + if err := t.compileUnbound(); err != nil { return nil, err } return t, nil } +// compileUnbound compiles a format holding no reference; `linkTemplateRefs` compiles the rest. +func (t *template) compileUnbound() error { + if len(refTokens(t.format)) > 0 { + return nil + } + return t.compileFormat() +} + // compileFormat compiles the format into ops, and applies the fences that need the // compiled reads. func (t *template) compileFormat() error { @@ -335,7 +339,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.compileFormat(); err != nil { + if err := t.compileUnbound(); err != nil { return nil, err } return t, nil diff --git a/table.go b/table.go index f9c2431..54bf4ff 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.compileFormat() + return t.format.compileUnbound() } // setTablePaths gives every table the path a selector on it is written at, before a diff --git a/todo.md b/todo.md index 5a5dbcb..c01ef1d 100644 --- a/todo.md +++ b/todo.md @@ -19,8 +19,6 @@ Self-sufficiency 5.6), every seat capped by Locality or Self-sufficiency. This round, in order: -- Compile a template's format once: `compileFormat` runs again from `linkTemplateRefs`, - so `ops`, `bound` and `held` are provisional until linking and its fences run twice. - Parse a format once and have the fences read `t.ops`: `eachToken` rescans the format in `fieldTokens`, `operandTokens`, `boundReaders`, `renderEdges`, `loneRef`, `operandReader`, `checkNoRepeatedRead` and `compileOps`, and function-versus-field is