Make great documentation goal 1.2, and plan the README's reorganisation and the nested-template gaps #33

Open
lilleman wants to merge 966 commits from worktree-todo-relative-dates-exact-counts into main
3 changed files with 11 additions and 9 deletions
Showing only changes of commit 526832fc3f - Show all commits
+10 -6
View File
@@ -42,10 +42,6 @@ func (*null) isNode() {}
// JSON string is a template with no fields. repeat (default 1) renders that format // 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 // that many times and joins the results with separator (default ""), each render
// an independent pick. // 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 { type template struct {
// Filled by `compileString`, `compileTemplate` and `table.compileWhole`: // Filled by `compileString`, `compileTemplate` and `table.compileWhole`:
format string format string
@@ -211,12 +207,20 @@ func compileString(s string) (node, error) {
return nil, err return nil, err
} }
t := &template{format: s, repeat: 1, fromString: true} t := &template{format: s, repeat: 1, fromString: true}
if err := t.compileFormat(); err != nil { if err := t.compileUnbound(); err != nil {
return nil, err return nil, err
} }
return t, nil 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 // compileFormat compiles the format into ops, and applies the fences that need the
// compiled reads. // compiled reads.
func (t *template) compileFormat() error { func (t *template) compileFormat() error {
@@ -335,7 +339,7 @@ func compileTemplate(m map[string]any, pos position) (node, error) {
return nil, err 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} 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 nil, err
} }
return t, nil return t, nil
+1 -1
View File
@@ -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.format = &template{format: format, fields: t.fields, repeat: 1, record: true, table: t}
t.whole = &row{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 // setTablePaths gives every table the path a selector on it is written at, before a
-2
View File
@@ -19,8 +19,6 @@ Self-sufficiency 5.6), every seat capped by Locality or Self-sufficiency.
This round, in order: 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 - Parse a format once and have the fences read `t.ops`: `eachToken` rescans the format
in `fieldTokens`, `operandTokens`, `boundReaders`, `renderEdges`, `loneRef`, in `fieldTokens`, `operandTokens`, `boundReaders`, `renderEdges`, `loneRef`,
`operandReader`, `checkNoRepeatedRead` and `compileOps`, and function-versus-field is `operandReader`, `checkNoRepeatedRead` and `compileOps`, and function-versus-field is