Make great documentation goal 1.2, and plan the README's reorganisation and the nested-template gaps #33
@@ -885,8 +885,8 @@ inline.go inline templates: Template, NewTemplate, FakeTemplate, IsTemplat
|
||||
format.go the {token} grammar: scanning, tokens, operands, validation, compiling a format
|
||||
draws.go the memo a hold or draw group keeps its draws in; and a render's draws and the scope it reads its reference paths through
|
||||
holdfence.go the load fences over the hold: the routes and spellings that read one held name two ways
|
||||
drawfence.go the load fences over reference draws: a drawGroup's, and a render's and a record's columns through the survey
|
||||
readsurvey.go the load-time survey of what a render reads, and what a path reads of a table family, and its verdict on them; and the fence on a table reaching its own family
|
||||
drawfence.go the load fences over reference draws and their refusals: a drawGroup's, a render's and a record's columns judged on the survey, and a table reaching its own family
|
||||
readsurvey.go the load-time survey of what a render reads, and what a path reads of a table family
|
||||
pins.go the pin set: the table rows a render fixes, which the draw fences replay
|
||||
reference.go reference sigils, and binding references across the tree
|
||||
graph.go the node graph: tree walks, containment and render edges, and the cycle and repeat fences
|
||||
|
||||
+159
-1
@@ -1,6 +1,10 @@
|
||||
package fejkdata
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// drawFence fences each template of a scope as a render of its own, remembering which nodes read a
|
||||
// reference path.
|
||||
@@ -60,6 +64,42 @@ func (f *drawFence) checkRecordDraws(path string, n node) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// checkOwnFamily refuses a table's format or cell that reads, however many templates
|
||||
// away and through a repeat or a draw group too, a table of its own family: a whole
|
||||
// read draws its row without pinning it, so the family would draw apart from the row
|
||||
// it renders, whichever draws the reaching template holds.
|
||||
// docs/decisions.md#a-table-never-reaches-its-own-family-by-any-route
|
||||
func checkOwnFamily(path string, n node) error {
|
||||
t, isTemplate := n.(*template)
|
||||
if !isTemplate || t.site.table == nil {
|
||||
return nil
|
||||
}
|
||||
own := t.site.table
|
||||
seen := map[node]bool{}
|
||||
var find func(n node) (renderEdge, *table, bool)
|
||||
find = func(n node) (renderEdge, *table, bool) {
|
||||
if seen[n] {
|
||||
return renderEdge{}, nil, false
|
||||
}
|
||||
seen[n] = true
|
||||
for _, e := range renderEdges(n) {
|
||||
if e.readsRef() {
|
||||
if familyTable, isTable := n.(*template).head(e.read.head).(*table); isTable && familyTable.familyRoot() == own.familyRoot() {
|
||||
return e, familyTable, true
|
||||
}
|
||||
}
|
||||
if e, familyTable, found := find(e.to); found {
|
||||
return e, familyTable, true
|
||||
}
|
||||
}
|
||||
return renderEdge{}, nil, false
|
||||
}
|
||||
if e, familyTable, found := find(t); found {
|
||||
return fmt.Errorf("%s: %s reads %s, a table of its own family, which a bare read of %s would draw apart from the row it renders; read the family from a template beside it, or add the value as a column", path, e.reached(), familyTable.segment, own.segment)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// readsPath reports whether rendering n reads a reference path, short of a repeat, which renders
|
||||
// over draws of its own.
|
||||
func (f *drawFence) readsPath(n node) bool { return f.hasRead(n, false) }
|
||||
@@ -117,3 +157,121 @@ func readsTable(n node, a arm) bool {
|
||||
_, isTable := t.head(a.head).(*table)
|
||||
return isTable
|
||||
}
|
||||
|
||||
// check refuses what one draw per reference path cannot answer for: a read selecting a row its route
|
||||
// pinned another of, a read of a level beside a path another read takes into it, and two reads of one
|
||||
// table family that select different rows.
|
||||
func (s *readSurvey) check() error {
|
||||
if c := s.clash; c != nil {
|
||||
return fmt.Errorf("%s: %w; read the family from a template beside it, or add the value as a column", c.route.spelled(c.spelling), c.err)
|
||||
}
|
||||
sort.SliceStable(s.reads, func(i, j int) bool {
|
||||
if s.reads[i].at.group != s.reads[j].at.group {
|
||||
return s.reads[i].at.group < s.reads[j].at.group
|
||||
}
|
||||
return s.reads[i].a.path < s.reads[j].a.path
|
||||
})
|
||||
for i, level := range s.reads {
|
||||
for _, into := range s.reads[i+1:] {
|
||||
if into.at.group != level.at.group || alternatives(level.at, into.at) {
|
||||
continue
|
||||
}
|
||||
if strings.HasPrefix(into.a.path, level.a.path+".") && !(level.tr != nil && level.tr.landsRow) {
|
||||
return overlapError(level.at.route, level.a.spelling, into)
|
||||
}
|
||||
}
|
||||
}
|
||||
return checkFamilies(s.reads)
|
||||
}
|
||||
|
||||
// checkFamilies refuses reads of one table family in one draw group that cannot
|
||||
// read one consistent draw: a table rendered whole beside a path into the family,
|
||||
// a table one read draws that another pins, and two reads pinning different rows.
|
||||
// The reads come sorted by group and path.
|
||||
func checkFamilies(reads []pathRead) error {
|
||||
for i, r := range reads {
|
||||
if r.tr == nil {
|
||||
continue
|
||||
}
|
||||
for _, o := range reads[:i] {
|
||||
if o.tr == nil || o.at.group != r.at.group || alternatives(o.at, r.at) || o.tr.headTable.familyRoot() != r.tr.headTable.familyRoot() {
|
||||
continue
|
||||
}
|
||||
if err := checkFamilyPair(o, r); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return replayPairs(reads)
|
||||
}
|
||||
|
||||
// checkFamilyPair refuses a table read whole beside a path into its family, and a
|
||||
// table one read draws that the other pins, since which token renders first would
|
||||
// then decide the row.
|
||||
// docs/decisions.md#a-bare-reference-draws-each-time-a-reference-path-is-held
|
||||
func checkFamilyPair(a, b pathRead) error {
|
||||
for _, pair := range [][2]pathRead{{a, b}, {b, a}} {
|
||||
x, y := pair[0], pair[1]
|
||||
if len(x.a.tail) == 0 && len(y.a.tail) > 0 {
|
||||
return overlapError(x.at.route, x.a.spelling, y)
|
||||
}
|
||||
if drawn := x.tr.drawnOf(&y.tr.pins); drawn != nil {
|
||||
if s, ok := y.tr.selected(x.tr.headTable); ok && len(x.tr.sels) == 0 {
|
||||
tail := x.a.tail
|
||||
if s.t != x.tr.headTable {
|
||||
tail = append([]string{x.tr.headTable.segment}, tail...)
|
||||
}
|
||||
return fmt.Errorf("%s draws %s, which %s selects a row of; write {%s.%s}, or draw them apart with a drawGroup",
|
||||
x.at.route.spelled(x.a.spelling), drawn.segment, y.at.route.spelled(y.a.spelling), s.spelling, joinSegments(tail))
|
||||
}
|
||||
return fmt.Errorf("%s draws %s, which %s selects a row of; select that row in both, or draw them apart with a drawGroup",
|
||||
x.at.route.spelled(x.a.spelling), drawn.segment, y.at.route.spelled(y.a.spelling))
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// replayPairs replays, of every two reads that can render together, the later into the
|
||||
// earlier's pins. Pairs find every conflict a full replay would: clash judges a row against one
|
||||
// pinned table, and the read that pinned it holds that pin itself, since a read's pins carry
|
||||
// its rows' ancestors, so the pair of those two reads clashes the same way.
|
||||
func replayPairs(reads []pathRead) error {
|
||||
for i, r := range reads {
|
||||
if r.tr == nil {
|
||||
continue
|
||||
}
|
||||
for _, o := range reads[i+1:] {
|
||||
if o.tr == nil || o.at.group != r.at.group || alternatives(r.at, o.at) {
|
||||
continue
|
||||
}
|
||||
d := r.tr.pins.clone()
|
||||
if err := o.tr.replay(&d); err != nil {
|
||||
return conflict(o, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func conflict(r pathRead, err error) error {
|
||||
return fmt.Errorf("%s: %w; select the same rows in every path into the family, or draw them apart with a drawGroup", r.at.route.spelled(r.a.spelling), err)
|
||||
}
|
||||
|
||||
// alternatives reports whether two reads never render together: one read renders one row of a
|
||||
// table, so reads under different rows the walks pinned, or under different rows of one whole
|
||||
// draw, never meet.
|
||||
func alternatives(a, b surveyAt) bool {
|
||||
return a.pins.differs(&b.pins) || a.wholePins.differs(&b.wholePins)
|
||||
}
|
||||
|
||||
func overlapError(route surveyRoute, ref string, into pathRead) error {
|
||||
apart := ""
|
||||
switch {
|
||||
case route.spelling == into.at.route.spelling:
|
||||
case isRef(into.at.route.label):
|
||||
apart = fmt.Sprintf(", or move {%s} into a field with a drawGroup", into.at.route.label)
|
||||
default:
|
||||
apart = fmt.Sprintf(", or give %s a drawGroup", into.at.route.spelling)
|
||||
}
|
||||
return fmt.Errorf("%s renders its own draw of what %s reads a path through; name the fields you want instead%s", route.spelled(ref), into.at.route.spelled(into.a.spelling), apart)
|
||||
}
|
||||
|
||||
+10
-161
@@ -1,17 +1,20 @@
|
||||
package fejkdata
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
import "fmt"
|
||||
|
||||
// readSurvey gathers, at load, the references one render reads, by draw group, for check to compare.
|
||||
type readSurvey struct {
|
||||
reads []pathRead
|
||||
read map[readKey]bool
|
||||
seen map[nodeVisit]bool
|
||||
clash error
|
||||
clash *pinClash
|
||||
}
|
||||
|
||||
// pinClash is the first read whose selectors clash with a row its route pinned.
|
||||
type pinClash struct {
|
||||
route surveyRoute
|
||||
spelling string
|
||||
err error
|
||||
}
|
||||
|
||||
// surveyAt is where a survey stands: the draw group its reads draw in, how the render's root reached it, the
|
||||
@@ -126,7 +129,7 @@ func (s *readSurvey) edge(from node, e renderEdge, at surveyAt) {
|
||||
pins := at.pins.clone()
|
||||
if err := tr.replay(&pins); err != nil {
|
||||
if s.clash == nil {
|
||||
s.clash = fmt.Errorf("%s: %w; read the family from a template beside it, or add the value as a column", at.route.spelled(a.spelling), err)
|
||||
s.clash = &pinClash{at.route, a.spelling, err}
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -211,157 +214,3 @@ func (r *tableRead) replay(d *pinSet) error {
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
// check refuses what one draw per reference path cannot answer for: a read selecting a row its route
|
||||
// pinned another of, a read of a level beside a path another read takes into it, and two reads of one
|
||||
// table family that select different rows.
|
||||
func (s *readSurvey) check() error {
|
||||
if s.clash != nil {
|
||||
return s.clash
|
||||
}
|
||||
sort.SliceStable(s.reads, func(i, j int) bool {
|
||||
if s.reads[i].at.group != s.reads[j].at.group {
|
||||
return s.reads[i].at.group < s.reads[j].at.group
|
||||
}
|
||||
return s.reads[i].a.path < s.reads[j].a.path
|
||||
})
|
||||
for i, level := range s.reads {
|
||||
for _, into := range s.reads[i+1:] {
|
||||
if into.at.group != level.at.group || alternatives(level.at, into.at) {
|
||||
continue
|
||||
}
|
||||
if strings.HasPrefix(into.a.path, level.a.path+".") && !(level.tr != nil && level.tr.landsRow) {
|
||||
return overlapError(level.at.route, level.a.spelling, into)
|
||||
}
|
||||
}
|
||||
}
|
||||
return checkFamilies(s.reads)
|
||||
}
|
||||
|
||||
// checkFamilies refuses reads of one table family in one draw group that cannot
|
||||
// read one consistent draw: a table rendered whole beside a path into the family,
|
||||
// a table one read draws that another pins, and two reads pinning different rows.
|
||||
// The reads come sorted by group and path.
|
||||
func checkFamilies(reads []pathRead) error {
|
||||
for i, r := range reads {
|
||||
if r.tr == nil {
|
||||
continue
|
||||
}
|
||||
for _, o := range reads[:i] {
|
||||
if o.tr == nil || o.at.group != r.at.group || alternatives(o.at, r.at) || o.tr.headTable.familyRoot() != r.tr.headTable.familyRoot() {
|
||||
continue
|
||||
}
|
||||
if err := checkFamilyPair(o, r); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return replayPairs(reads)
|
||||
}
|
||||
|
||||
// checkOwnFamily refuses a table's format or cell that reads, however many templates
|
||||
// away and through a repeat or a draw group too, a table of its own family: a whole
|
||||
// read draws its row without pinning it, so the family would draw apart from the row
|
||||
// it renders, whichever draws the reaching template holds.
|
||||
// docs/decisions.md#a-table-never-reaches-its-own-family-by-any-route
|
||||
func checkOwnFamily(path string, n node) error {
|
||||
t, isTemplate := n.(*template)
|
||||
if !isTemplate || t.site.table == nil {
|
||||
return nil
|
||||
}
|
||||
own := t.site.table
|
||||
seen := map[node]bool{}
|
||||
var find func(n node) (renderEdge, *table, bool)
|
||||
find = func(n node) (renderEdge, *table, bool) {
|
||||
if seen[n] {
|
||||
return renderEdge{}, nil, false
|
||||
}
|
||||
seen[n] = true
|
||||
for _, e := range renderEdges(n) {
|
||||
if e.readsRef() {
|
||||
if familyTable, isTable := n.(*template).head(e.read.head).(*table); isTable && familyTable.familyRoot() == own.familyRoot() {
|
||||
return e, familyTable, true
|
||||
}
|
||||
}
|
||||
if e, familyTable, found := find(e.to); found {
|
||||
return e, familyTable, true
|
||||
}
|
||||
}
|
||||
return renderEdge{}, nil, false
|
||||
}
|
||||
if e, familyTable, found := find(t); found {
|
||||
return fmt.Errorf("%s: %s reads %s, a table of its own family, which a bare read of %s would draw apart from the row it renders; read the family from a template beside it, or add the value as a column", path, e.reached(), familyTable.segment, own.segment)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// checkFamilyPair refuses a table read whole beside a path into its family, and a
|
||||
// table one read draws that the other pins, since which token renders first would
|
||||
// then decide the row.
|
||||
// docs/decisions.md#a-bare-reference-draws-each-time-a-reference-path-is-held
|
||||
func checkFamilyPair(a, b pathRead) error {
|
||||
for _, pair := range [][2]pathRead{{a, b}, {b, a}} {
|
||||
x, y := pair[0], pair[1]
|
||||
if len(x.a.tail) == 0 && len(y.a.tail) > 0 {
|
||||
return overlapError(x.at.route, x.a.spelling, y)
|
||||
}
|
||||
if drawn := x.tr.drawnOf(&y.tr.pins); drawn != nil {
|
||||
if s, ok := y.tr.selected(x.tr.headTable); ok && len(x.tr.sels) == 0 {
|
||||
tail := x.a.tail
|
||||
if s.t != x.tr.headTable {
|
||||
tail = append([]string{x.tr.headTable.segment}, tail...)
|
||||
}
|
||||
return fmt.Errorf("%s draws %s, which %s selects a row of; write {%s.%s}, or draw them apart with a drawGroup",
|
||||
x.at.route.spelled(x.a.spelling), drawn.segment, y.at.route.spelled(y.a.spelling), s.spelling, joinSegments(tail))
|
||||
}
|
||||
return fmt.Errorf("%s draws %s, which %s selects a row of; select that row in both, or draw them apart with a drawGroup",
|
||||
x.at.route.spelled(x.a.spelling), drawn.segment, y.at.route.spelled(y.a.spelling))
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// replayPairs replays, of every two reads that can render together, the later into the
|
||||
// earlier's pins. Pairs find every conflict a full replay would: clash judges a row against one
|
||||
// pinned table, and the read that pinned it holds that pin itself, since a read's pins carry
|
||||
// its rows' ancestors, so the pair of those two reads clashes the same way.
|
||||
func replayPairs(reads []pathRead) error {
|
||||
for i, r := range reads {
|
||||
if r.tr == nil {
|
||||
continue
|
||||
}
|
||||
for _, o := range reads[i+1:] {
|
||||
if o.tr == nil || o.at.group != r.at.group || alternatives(r.at, o.at) {
|
||||
continue
|
||||
}
|
||||
d := r.tr.pins.clone()
|
||||
if err := o.tr.replay(&d); err != nil {
|
||||
return conflict(o, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func conflict(r pathRead, err error) error {
|
||||
return fmt.Errorf("%s: %w; select the same rows in every path into the family, or draw them apart with a drawGroup", r.at.route.spelled(r.a.spelling), err)
|
||||
}
|
||||
|
||||
// alternatives reports whether two reads never render together: one read renders one row of a
|
||||
// table, so reads under different rows the walks pinned, or under different rows of one whole
|
||||
// draw, never meet.
|
||||
func alternatives(a, b surveyAt) bool {
|
||||
return a.pins.differs(&b.pins) || a.wholePins.differs(&b.wholePins)
|
||||
}
|
||||
|
||||
func overlapError(route surveyRoute, ref string, into pathRead) error {
|
||||
apart := ""
|
||||
switch {
|
||||
case route.spelling == into.at.route.spelling:
|
||||
case isRef(into.at.route.label):
|
||||
apart = fmt.Sprintf(", or move {%s} into a field with a drawGroup", into.at.route.label)
|
||||
default:
|
||||
apart = fmt.Sprintf(", or give %s a drawGroup", into.at.route.spelling)
|
||||
}
|
||||
return fmt.Errorf("%s renders its own draw of what %s reads a path through; name the fields you want instead%s", route.spelled(ref), into.at.route.spelled(into.a.spelling), apart)
|
||||
}
|
||||
|
||||
@@ -37,10 +37,6 @@ on 2026-09-29 a fifth time (Navigation 6.9, Locality 5.2, Shape 6.1, Self-suffic
|
||||
|
||||
This round, in order:
|
||||
|
||||
- Put the draw fence in one file: `drawFence.checkDraws` in `drawfence.go` hands
|
||||
`surveyRender(t).check()` the verdict, whose refusals live in `readsurvey.go`, and
|
||||
eight seats grepped one fence error across `holdfence.go`, `drawfence.go`,
|
||||
`readsurvey.go` and `pins.go`.
|
||||
- Split `formatOps.held` into the names an expansion holds and the reference paths a
|
||||
render's draws hold, deleting `keepsHold` and `heldCheck`'s skip of a reference path:
|
||||
one map carries both, told apart by `isRef` and `firstReach.path == ""`, and six seats
|
||||
|
||||
Reference in New Issue
Block a user