Make checkNameReads and enter read on one pass, and keep name for names

This commit is contained in:
2026-10-03 12:25:35 +02:00
committed by Lillem4n
parent 62214370ed
commit c955d35bbe
4 changed files with 8 additions and 9 deletions
+2 -2
View File
@@ -716,11 +716,11 @@ anywhere: if `n`'s category has the format `{w}-{w}`, it draws `w` twice, and `{
A name is a pick of its own: `{t.name}` and `{/misc.territory.name}` beside it are two draws. A A name is a pick of its own: `{t.name}` and `{/misc.territory.name}` beside it are two draws. A
reference path the picked category reads is still held for the render as usual, so two names reference path the picked category reads is still held for the render as usual, so two names
bound to `sv_SE.person`, whose fields read `{.first-name.name}`, print the same first and last bound to `sv_SE.person`, whose fields read `{.first-name.name}` and `{.last-name.name}`, print the same first and last
name unless their reads sit in two [draw groups](#draw-group). name unless their reads sit in two [draw groups](#draw-group).
A name is drawn on its first read, and lives in the category binding it: any field of the A name is drawn on its first read, and lives in the category binding it: any field of the
category reads it, and a record's columns read one pick. Each render of the category picks category may read it, and a record's columns read one pick. Each render of the category picks
anew, and so does each bare reference to it. A name a `repeat` binds picks again on every anew, and so does each bare reference to it. A name a `repeat` binds picks again on every
iteration, and one bound outside the repeat keeps its pick on every line. iteration, and one bound outside the repeat keeps its pick on every line.
+1 -1
View File
@@ -23,7 +23,7 @@ package fejkdata
// `Generator.Fake`, `FakeRecord`, `Template.Fake` and `RecordTemplate.Fake` // `Generator.Fake`, `FakeRecord`, `Template.Fake` and `RecordTemplate.Fake`
// start one each, `FakeStruct` one per record, and `expandAnew` one per // start one each, `FakeStruct` one per record, and `expandAnew` one per
// iteration of a `template.repeat`. // iteration of a `template.repeat`.
// - hold — keeping one draw of a name, so every route to it reads that value: // - hold — keeping one draw of a field, so every route to it reads that value:
// an expansion holds a sibling path's head and an operand's field, its draw // an expansion holds a sibling path's head and an operand's field, its draw
// group a reference path's: `formatOps.held` and `heldCheck` an expansion's, // group a reference path's: `formatOps.held` and `heldCheck` an expansion's,
// `readReference` a draw group's. // `readReference` a draw group's.
+4 -5
View File
@@ -288,9 +288,8 @@ func linkName(t *template, a *arm) error {
return nil return nil
} }
// checkNameReads refuses a read of a name rendering, under the pick, a field it renders twice where // checkNameReads refuses each binding of t that checkUses refuses, and a read such as {n} whose
// a path through the name reads one draw of it: the pick keeps one draw there, and the two // pick renders twice a field another read, {n.w}, reads once: the pick keeps one draw of it.
// renders would disagree with it.
func checkNameReads(path string, t *template) error { func checkNameReads(path string, t *template) error {
for _, tok := range t.tokens { for _, tok := range t.tokens {
if tok.kind != nameBind { if tok.kind != nameBind {
@@ -474,8 +473,8 @@ func (d *renderDraws) depth() int {
return len(d.frameStack.frames) return len(d.frameStack.frames)
} }
// enter hides the frames already rendering from a read landing on n, and opens from memo a frame // enter starts a read landing on n: the read sees no frame opened before it, and gets from memo a
// for each name scope around n, so every read sharing memo reads one pick of each name. It // frame for each name scope around n, so reads sharing memo read one pick of each name. It
// returns the mark that closes those frames. // returns the mark that closes those frames.
func (sc renderScope) enter(n node, memo *drawMemo) (renderScope, int) { func (sc renderScope) enter(n node, memo *drawMemo) (renderScope, int) {
sc.base, sc.pick = sc.draws.depth(), nil sc.base, sc.pick = sc.draws.depth(), nil
+1 -1
View File
@@ -165,7 +165,7 @@ func expand(s *generatorState, t *template, sc renderScope) string {
return b.String() return b.String()
} }
// readField renders one arm of a token. A name the expansion holds — a level some // readField renders one arm of a token. A field the expansion holds — a level some
// token addresses by a dotted path that is not a reference, or a field an operand // token addresses by a dotted path that is not a reference, or a field an operand
// reads — is drawn once and kept in hold, so {place.postal-code} and {place.locality} // reads — is drawn once and kept in hold, so {place.postal-code} and {place.locality}
// read one row, either read twice gives one value, and a shown operand is the operand // read one row, either read twice gives one value, and a shown operand is the operand