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 10 additions and 9 deletions
Showing only changes of commit 6158eb0f46 - Show all commits
+8 -4
View File
@@ -68,7 +68,7 @@ type cellSite struct {
row int 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 { type templateLink struct {
refs map[string]refBinding // each reference the format reads -> what it resolves to refs map[string]refBinding // each reference the format reads -> what it resolves to
refHeads map[string]node // each refBinding.key -> the category it names 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) { func compileItem(v any, pos position) (node, error) {
switch v := v.(type) { switch v := v.(type) {
case string: case string:
return compileString(v) t, err := compileString(v, cellSite{})
if err != nil {
return nil, err
}
return t, nil
case []any: case []any:
return compileChoice(v, pos) return compileChoice(v, pos)
case map[string]any: case map[string]any:
@@ -199,12 +203,12 @@ func jsonKind(v any) string {
return fmt.Sprintf("%T", v) return fmt.Sprintf("%T", v)
} }
func compileString(s string) (node, error) { func compileString(s string, cell cellSite) (*template, error) {
toks, err := parseChecked(s, nil) toks, err := parseChecked(s, nil)
if err != nil { if err != nil {
return nil, err 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. // fixedText is one render's output when the format holds no token; repeat is the caller's.
+2 -2
View File
@@ -308,14 +308,14 @@ func (t *table) checkCells() error {
if strings.IndexByte(cell, '{') < 0 && strings.IndexByte(cell, '}') < 0 { if strings.IndexByte(cell, '{') < 0 && strings.IndexByte(cell, '}') < 0 {
continue continue
} }
toks, err := parseChecked(cell, nil) n, err := compileString(cell, cellSite{t, row})
if err != nil { if err != nil {
return fmt.Errorf("line %d, %s: %w", row+2, t.header[col], err) return fmt.Errorf("line %d, %s: %w", row+2, t.header[col], err)
} }
if t.cellTemplates == nil { if t.cellTemplates == nil {
t.cellTemplates = map[int]*template{} 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 return nil
} }
-3
View File
@@ -23,9 +23,6 @@ Shape 5.8, Self-sufficiency 5.7), every seat capped by Locality, all nine naming
This round, in order: 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 - 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 `default: return nil` silently exempts a new node kind from every fence, and nothing
at `expand` says `renderEdges` mirrors it. at `expand` says `renderEdges` mirrors it.