Rename refBinding.key to head, and the stale key wording beside it
This commit is contained in:
+2
-2
@@ -90,8 +90,8 @@ func checkOwnFamily(t *template) error {
|
||||
seen[n] = true
|
||||
for _, e := range renderEdges(n) {
|
||||
if e.readsRef() {
|
||||
if head, isTable := n.(*template).head(e.read.head).(*table); isTable && head.familyRoot() == own.familyRoot() {
|
||||
return e, head, true
|
||||
if read, isTable := n.(*template).head(e.read.head).(*table); isTable && read.familyRoot() == own.familyRoot() {
|
||||
return e, read, true
|
||||
}
|
||||
}
|
||||
if e, head, found := find(e.to); found {
|
||||
|
||||
@@ -322,11 +322,11 @@ func splitArm(name string, refs map[string]refBinding) arm {
|
||||
if !linked || len(b.tail) == 0 {
|
||||
head := name
|
||||
if linked {
|
||||
head = b.key
|
||||
head = b.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)
|
||||
if err != nil || len(segs) == 1 {
|
||||
@@ -371,7 +371,7 @@ type callFn func(s *session, emitted string, operands []string) string
|
||||
// re-scans the format.
|
||||
type op struct {
|
||||
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
|
||||
// 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.
|
||||
|
||||
@@ -74,7 +74,7 @@ const formatRow = -1
|
||||
// templateLink is what a template resolves to in the assembled tree.
|
||||
type templateLink struct {
|
||||
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
|
||||
drawGroupKey string // its draw group keyed by its category: what a render reads its reference paths under
|
||||
}
|
||||
|
||||
+7
-7
@@ -9,10 +9,10 @@ import (
|
||||
// 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, "/") }
|
||||
|
||||
// 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.
|
||||
type refBinding struct {
|
||||
key string
|
||||
head string
|
||||
tail []string
|
||||
}
|
||||
|
||||
@@ -119,15 +119,15 @@ func (t *template) resolveLink(folder []string, path, category string, root map[
|
||||
if err != nil {
|
||||
return link, fmt.Errorf("%s: reference {%s}: %w", path, name, err)
|
||||
}
|
||||
key := "/" + strings.Join(categorySegs, ".")
|
||||
if category != "" && key == "/"+category {
|
||||
head := "/" + strings.Join(categorySegs, ".")
|
||||
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)
|
||||
}
|
||||
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)
|
||||
}
|
||||
link.refHeads[key] = target
|
||||
link.refs[name] = refBinding{key, tail}
|
||||
link.refHeads[head] = target
|
||||
link.refs[name] = refBinding{head, tail}
|
||||
}
|
||||
link.readsColumn = columnReadOf(t, link)
|
||||
return link, nil
|
||||
|
||||
+1
-1
@@ -102,7 +102,7 @@ func readsFact(n node) string {
|
||||
}
|
||||
case *template:
|
||||
for _, b := range n.link.refs {
|
||||
set[strings.TrimPrefix(b.key, "/")] = true
|
||||
set[strings.TrimPrefix(b.head, "/")] = true
|
||||
}
|
||||
for _, field := range n.fields {
|
||||
collect(field)
|
||||
|
||||
Reference in New Issue
Block a user