Rename refBinding.key to head, and the stale key wording beside it

This commit is contained in:
2026-09-29 10:14:00 +02:00
committed by Lillem4n
parent a7d77bd3ad
commit 6275c6d41e
5 changed files with 14 additions and 14 deletions
+2 -2
View File
@@ -90,8 +90,8 @@ func checkOwnFamily(t *template) error {
seen[n] = true seen[n] = true
for _, e := range renderEdges(n) { for _, e := range renderEdges(n) {
if e.readsRef() { if e.readsRef() {
if head, isTable := n.(*template).head(e.read.head).(*table); isTable && head.familyRoot() == own.familyRoot() { if read, isTable := n.(*template).head(e.read.head).(*table); isTable && read.familyRoot() == own.familyRoot() {
return e, head, true return e, read, true
} }
} }
if e, head, found := find(e.to); found { if e, head, found := find(e.to); found {
+3 -3
View File
@@ -322,11 +322,11 @@ func splitArm(name string, refs map[string]refBinding) arm {
if !linked || len(b.tail) == 0 { if !linked || len(b.tail) == 0 {
head := name head := name
if linked { if linked {
head = b.key head = b.head
} }
return arm{spelling: name, head: head, path: head} return arm{spelling: name, head: head, path: head}
} }
return pathArm(name, b.key, b.tail) return pathArm(name, b.head, b.tail)
} }
segs, err := splitPath(name) segs, err := splitPath(name)
if err != nil || len(segs) == 1 { if err != nil || len(segs) == 1 {
@@ -371,7 +371,7 @@ type callFn func(s *session, emitted string, operands []string) string
// re-scans the format. // re-scans the format.
type op struct { type op struct {
formatToken formatToken
arms []arm // nameRead: the '|' alternatives, split into key and path once arms []arm // nameRead: the '|' alternatives, split into head and tail once
call callFn call callFn
// operands are the fields the builtin reads, in the order its operands func // operands are the fields the builtin reads, in the order its operands func
// fixed; expand reads them before the call. nil for a builtin that reads none. // fixed; expand reads them before the call. nil for a builtin that reads none.
+1 -1
View File
@@ -74,7 +74,7 @@ const formatRow = -1
// templateLink is what a template resolves to in the assembled tree. // templateLink is what a template resolves to in the assembled tree.
type templateLink struct { type templateLink struct {
refs map[string]refBinding // each reference the format reads -> what it resolves to refs map[string]refBinding // each reference the format reads -> what it resolves to
refHeads map[string]node // each refBinding.key -> the category it names refHeads map[string]node // each refBinding.head -> the category it names
readsColumn *columnRead // set when the format is one reference alone reading a record's column readsColumn *columnRead // set when the format is one reference alone reading a record's column
drawGroupKey string // its draw group keyed by its category: what a render reads its reference paths under drawGroupKey string // its draw group keyed by its category: what a render reads its reference paths under
} }
+7 -7
View File
@@ -9,10 +9,10 @@ import (
// data root, {.a} from the folder this file sits in, {..a} from the folder above. // data root, {.a} from the folder this file sits in, {..a} from the folder above.
func isRef(name string) bool { return strings.HasPrefix(name, ".") || strings.HasPrefix(name, "/") } func isRef(name string) bool { return strings.HasPrefix(name, ".") || strings.HasPrefix(name, "/") }
// refBinding is what a reference resolves to: the key its category is held // refBinding is what a reference resolves to: the head its category is held
// under, and the tail read into it. // under, and the tail read into it.
type refBinding struct { type refBinding struct {
key string head string
tail []string tail []string
} }
@@ -119,15 +119,15 @@ func (t *template) resolveLink(folder []string, path, category string, root map[
if err != nil { if err != nil {
return link, fmt.Errorf("%s: reference {%s}: %w", path, name, err) return link, fmt.Errorf("%s: reference {%s}: %w", path, name, err)
} }
key := "/" + strings.Join(categorySegs, ".") head := "/" + strings.Join(categorySegs, ".")
if category != "" && key == "/"+category { if category != "" && head == "/"+category {
return link, fmt.Errorf("%s: reference {%s}: names the category it sits in; read a sibling field as a path, or move the shared value into its own category and reference that", path, name) return link, fmt.Errorf("%s: reference {%s}: names the category it sits in; read a sibling field as a path, or move the shared value into its own category and reference that", path, name)
} }
if err := checkPath(target, tail, key); err != nil { if err := checkPath(target, tail, head); err != nil {
return link, fmt.Errorf("%s: reference {%s}: %w", path, name, err) return link, fmt.Errorf("%s: reference {%s}: %w", path, name, err)
} }
link.refHeads[key] = target link.refHeads[head] = target
link.refs[name] = refBinding{key, tail} link.refs[name] = refBinding{head, tail}
} }
link.readsColumn = columnReadOf(t, link) link.readsColumn = columnReadOf(t, link)
return link, nil return link, nil
+1 -1
View File
@@ -102,7 +102,7 @@ func readsFact(n node) string {
} }
case *template: case *template:
for _, b := range n.link.refs { for _, b := range n.link.refs {
set[strings.TrimPrefix(b.key, "/")] = true set[strings.TrimPrefix(b.head, "/")] = true
} }
for _, field := range n.fields { for _, field := range n.fields {
collect(field) collect(field)