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 18 additions and 8 deletions
Showing only changes of commit 26b35abe70 - Show all commits
+10
View File
@@ -315,8 +315,18 @@ type arm struct {
steps []pathStep
leaves []node // every node the path may land on, one per variant it passes
cover node // what holding the path pins: the first choice it passes, else its leaf
kind armKind
}
// armKind is how expand reads an arm, fixed at compile.
type armKind uint8
const (
freshRead armKind = iota // drawn afresh at every read
heldRead // drawn once per expansion, kept in its hold
refPathRead // drawn once per draw group, kept in its memo
)
func (a arm) isRefPath() bool {
return isRef(a.head) && len(a.tail) > 0
}
+6
View File
@@ -112,6 +112,12 @@ func compileArm(t *template, a *arm) {
}
w := compilePath(head, a.tail)
a.steps, a.leaves, a.cover = w.steps, w.leaves, w.cover
switch _, held := t.compiled.held[a.head]; {
case a.isRefPath():
a.kind = refPathRead
case held:
a.kind = heldRead
}
}
// resolveLink binds every reference t reads, refusing one to t's own category, and keys
+2 -8
View File
@@ -158,21 +158,15 @@ func expand(s *generatorState, t *template, sc renderScope) string {
// read one row, either read twice gives one value, and a shown operand is the operand
// computed. Every other name is drawn afresh, so {word} {word} still draws twice.
func readField(s *generatorState, t *template, hold *drawMemo, sc renderScope, a arm) readValue {
if a.isRefPath() {
if a.kind == refPathRead {
return readReference(s, t, sc, a)
}
if sc.draws.trace != nil {
traceRead(sc.draws.trace, t, sc, a)
}
if _, expansionHolds := t.compiled.held[a.head]; !expansionHolds {
if len(a.tail) > 0 {
panic(internalError("%q reads a path into %q, which the expansion does not hold", a.spelling, a.head))
}
if a.kind == freshRead {
return readValue{text: render(s, t.head(a.head), sc)}
}
if hold == nil {
panic(internalError("%q reads a name the expansion holds, with no hold to keep it in", a.spelling))
}
return readMemo(s, t, hold, nil, sc, a)
}