|
|
|
@@ -6,26 +6,34 @@ import (
|
|
|
|
|
"strings"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// drawFence fences each template of a scope as a render of its own, remembering which nodes read a
|
|
|
|
|
// reference path.
|
|
|
|
|
// drawFence fences each template of a scope as a render of its own, over one fold of what every
|
|
|
|
|
// node reads.
|
|
|
|
|
// docs/decisions.md#a-render-shares-one-reference-draw-per-category-per-group
|
|
|
|
|
// docs/decisions.md#the-expansion-hold-and-the-renders-draws-are-two-fences
|
|
|
|
|
type drawFence struct {
|
|
|
|
|
memo map[hasReadMemo]bool
|
|
|
|
|
fold *readFold
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type hasReadMemo struct {
|
|
|
|
|
n node
|
|
|
|
|
stopAtGroup bool
|
|
|
|
|
func (f *drawFence) reads() *readFold {
|
|
|
|
|
if f.fold == nil {
|
|
|
|
|
f.fold = newReadFold()
|
|
|
|
|
}
|
|
|
|
|
return f.fold
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// checkDrawGroup refuses a draw group that splits nothing: one whose render reads every reference
|
|
|
|
|
// path inside a repeat or a nested draw group, which draw apart from it whatever it names.
|
|
|
|
|
func (f *drawFence) checkDrawGroup(path string, n node) error {
|
|
|
|
|
if t, ok := n.(*template); ok && t.drawGroup != "" && !f.splitsDraws(t) {
|
|
|
|
|
return fmt.Errorf("%s: drawGroup %q splits nothing, since nothing it renders reads a reference path outside a repeat or a nested drawGroup; drop it", path, t.drawGroup)
|
|
|
|
|
t, ok := n.(*template)
|
|
|
|
|
if !ok || t.drawGroup == "" {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
for _, r := range f.reads().rootReads(t) {
|
|
|
|
|
if r.at.group == "" && r.draws() {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return fmt.Errorf("%s: drawGroup %q splits nothing, since nothing it renders reads a reference path outside a repeat or a nested drawGroup; drop it", path, t.drawGroup)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (f *drawFence) checkDraws(path string, n node) error {
|
|
|
|
@@ -33,10 +41,11 @@ func (f *drawFence) checkDraws(path string, n node) error {
|
|
|
|
|
if !ok {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
if !f.readsPath(t) {
|
|
|
|
|
reads := f.reads().rootReads(t)
|
|
|
|
|
if !anyDraws(reads) {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
if err := surveyRender(t).check(); err != nil {
|
|
|
|
|
if err := survey(reads, t.link.drawGroupKey).check(); err != nil {
|
|
|
|
|
return fmt.Errorf("%s: %w", path, err)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
@@ -50,15 +59,11 @@ func (f *drawFence) checkRecordDraws(path string, n node) error {
|
|
|
|
|
if !ok || !t.isRecord {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
columns := sortedNames(t.fields)
|
|
|
|
|
reads := false
|
|
|
|
|
for _, name := range columns {
|
|
|
|
|
reads = reads || f.readsPath(t.fields[name])
|
|
|
|
|
}
|
|
|
|
|
if !reads {
|
|
|
|
|
reads := f.reads().columnReads(t, sortedNames(t.fields))
|
|
|
|
|
if !anyDraws(reads) {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
if err := surveyColumns(t, columns).check(); err != nil {
|
|
|
|
|
if err := survey(reads, t.link.drawGroupKey).check(); err != nil {
|
|
|
|
|
return fmt.Errorf("%s: %w", path, err)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
@@ -100,41 +105,17 @@ func checkOwnFamily(path string, n node) error {
|
|
|
|
|
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) }
|
|
|
|
|
// draws reports whether a read's draw is its group's to answer for: a path, or a table read whole,
|
|
|
|
|
// whose row the group draws.
|
|
|
|
|
func (r pathRead) draws() bool { return len(r.a.tail) > 0 || r.tr != nil }
|
|
|
|
|
|
|
|
|
|
// splitsDraws reports whether rendering n reads a reference path that n's own draw group answers
|
|
|
|
|
// for: one outside a repeat and outside a nested draw group, which hold their own draws.
|
|
|
|
|
func (f *drawFence) splitsDraws(n node) bool { return f.hasRead(n, true) }
|
|
|
|
|
|
|
|
|
|
// hasRead walks what rendering n renders for a reference path, stopping at a repeat — and at a nested
|
|
|
|
|
// draw group when stopAtGroup — since each holds draws of its own.
|
|
|
|
|
func (f *drawFence) hasRead(n node, stopAtGroup bool) bool {
|
|
|
|
|
k := hasReadMemo{n, stopAtGroup}
|
|
|
|
|
if r, done := f.memo[k]; done {
|
|
|
|
|
return r
|
|
|
|
|
}
|
|
|
|
|
r := false
|
|
|
|
|
for _, e := range renderEdges(n) {
|
|
|
|
|
if readsOnEdge(n, e) || (walksInto(e.to, stopAtGroup) && f.hasRead(e.to, stopAtGroup)) {
|
|
|
|
|
r = true
|
|
|
|
|
break
|
|
|
|
|
func anyDraws(reads []pathRead) bool {
|
|
|
|
|
for _, r := range reads {
|
|
|
|
|
if r.draws() {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if f.memo == nil {
|
|
|
|
|
f.memo = map[hasReadMemo]bool{}
|
|
|
|
|
}
|
|
|
|
|
f.memo[k] = r
|
|
|
|
|
return r
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func readsOnEdge(n node, e renderEdge) bool {
|
|
|
|
|
return e.readsRef() && (len(e.read.tail) > 0 || readsTable(n, e.read))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func walksInto(to node, stopAtGroup bool) bool {
|
|
|
|
|
return !repeats(to) && !(stopAtGroup && grouped(to))
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func repeats(n node) bool {
|
|
|
|
@@ -142,22 +123,6 @@ func repeats(n node) bool {
|
|
|
|
|
return isTemplate && t.repeat > 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func grouped(n node) bool {
|
|
|
|
|
t, isTemplate := n.(*template)
|
|
|
|
|
return isTemplate && t.link.drawGroupKey != ""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// readsTable reports whether a reference of n names a table, whose draw the render's
|
|
|
|
|
// group answers for even when read whole.
|
|
|
|
|
func readsTable(n node, a arm) bool {
|
|
|
|
|
t, isTemplate := n.(*template)
|
|
|
|
|
if !isTemplate {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
_, 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.
|
|
|
|
|