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
4 changed files with 9 additions and 9 deletions
Showing only changes of commit 30d0f84ea4 - Show all commits
+1 -1
View File
@@ -61,7 +61,7 @@ func contained(n node) []namedNode {
case *template: case *template:
return namedNodes(n.fields) return namedNodes(n.fields)
case *table: case *table:
return append([]namedNode{{node: n.formatTemplate}}, namedNodes(n.fields)...) return append([]namedNode{{node: n.formatTemplate}}, namedNodes(n.formatTemplate.fields)...)
case *tableColumn: case *tableColumn:
if len(n.t.cellTemplates) == 0 { if len(n.t.cellTemplates) == 0 {
return nil return nil
+2 -2
View File
@@ -438,8 +438,8 @@ func (t *table) step(tail []string) (column node, child *table, err error) {
if len(tail) == 0 { if len(tail) == 0 {
return nil, nil, nil return nil, nil, nil
} }
if i, ok := t.col[tail[0]]; ok { if column, ok := t.formatTemplate.fields[tail[0]]; ok {
return t.fields[t.header[i]], nil, nil return column, nil, nil
} }
if child = t.descendant(tail[0]); child == nil { if child = t.descendant(tail[0]); child == nil {
return nil, nil, fmt.Errorf("no column or linked table %q in %s", tail[0], t.segment) return nil, nil, fmt.Errorf("no column or linked table %q in %s", tail[0], t.segment)
+6 -5
View File
@@ -19,7 +19,6 @@ type table struct {
formatTemplate *template // fields are the column nodes formatTemplate *template // fields are the column nodes
header []string header []string
col map[string]int col map[string]int
fields map[string]node // column nodes, the format's fields
rowNode *tableRow rowNode *tableRow
cells []string // rows × columns, flat cells []string // rows × columns, flat
cellTemplates map[int]*template cellTemplates map[int]*template
@@ -157,7 +156,6 @@ func (t *table) parseRows(data string) error {
} }
t.header = strings.Split(header, "\t") t.header = strings.Split(header, "\t")
t.col = make(map[string]int, len(t.header)) t.col = make(map[string]int, len(t.header))
t.fields = make(map[string]node, len(t.header))
for i, name := range t.header { for i, name := range t.header {
if err := checkName(name); err != nil { if err := checkName(name); err != nil {
return fmt.Errorf("column %w", err) return fmt.Errorf("column %w", err)
@@ -166,7 +164,6 @@ func (t *table) parseRows(data string) error {
return fmt.Errorf("column %q is named twice", name) return fmt.Errorf("column %q is named twice", name)
} }
t.col[name] = i t.col[name] = i
t.fields[name] = &tableColumn{t, i}
} }
if header == data { if header == data {
return fmt.Errorf("has no rows below its header; a table is at least two rows") return fmt.Errorf("has no rows below its header; a table is at least two rows")
@@ -338,10 +335,14 @@ func (t *table) compileRowFormat(format string) error {
} }
} }
} }
if err := checkTokens(toks, t.fields); err != nil { fields := make(map[string]node, len(t.header))
for i, name := range t.header {
fields[name] = &tableColumn{t, i}
}
if err := checkTokens(toks, fields); err != nil {
return err return err
} }
t.formatTemplate = &template{format: format, tokens: toks, fields: t.fields, repeat: 1, isRecord: true, site: tableSite{t, formatRow}} t.formatTemplate = &template{format: format, tokens: toks, fields: fields, repeat: 1, isRecord: true, site: tableSite{t, formatRow}}
t.rowNode = &tableRow{t} t.rowNode = &tableRow{t}
return nil return nil
} }
-1
View File
@@ -28,7 +28,6 @@ ranking `readSurvey.walk` hardest and all seven the unit they would least modify
This round, in order: This round, in order:
- Drop `table.fields` for `formatTemplate.fields`: one map held in two fields.
- Rename `arm.key` to `head`, as `template.head` reads it, leaving `key` the table's key - Rename `arm.key` to `head`, as `template.head` reads it, leaving `key` the table's key
column; give `renderScope.row` a type that is not `tablePin`, since it pins nothing; column; give `renderScope.row` a type that is not `tablePin`, since it pins nothing;
and name `value.go` by the `valueProof` it holds. and name `value.go` by the `valueProof` it holds.