From 94e3eabbcf87901a347bd54c6799ffb505c5598e Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Wed, 7 Oct 2026 01:07:28 +0200 Subject: [PATCH] Name the column each case of columnReadOf reads, strip a head's / in categoryOf, and say on resolvedRef that its head carries the / --- reference.go | 5 ++++- resolve.go | 16 +++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/reference.go b/reference.go index 4ed0b96..d5959e8 100644 --- a/reference.go +++ b/reference.go @@ -8,12 +8,15 @@ import ( ) // resolvedRef is what a reference resolves to: the head its category is held -// under, and the tail read into it. +// under, its path from the root behind a "/", and the tail read into it. type resolvedRef struct { head string tail []string } +// categoryOf is the category path a resolvedRef's head names: the head without its "/". +func categoryOf(head string) string { return strings.TrimPrefix(head, "/") } + // refSegments resolves a reference written in folder to a path from the root. func refSegments(name string, folder []string) ([]string, error) { sigil, rest, err := grammar.RefShape(name) diff --git a/resolve.go b/resolve.go index a03042d..0d94386 100644 --- a/resolve.go +++ b/resolve.go @@ -171,15 +171,21 @@ func columnReadOf(t *template, targets map[*nameBinding]nameTarget) *columnRead return nil } a := ops[0].arms[0] - start, category, tail := t.startOf(a.head), a.head[min(1, len(a.head)):], a.tail + var start node + var category string + var tail []string switch b := a.named; { case a.kind == namedRead && b.bindsField(): - start, category = b.binder, "" - tail = append(append([]string{splitArm(b.ref, nil).head}, targets[b].tail...), a.tail...) + // {f as n}{n}: column f of the record binding n, in t's own category. + start, tail = b.binder, append(append([]string{splitArm(b.ref, nil).head}, targets[b].tail...), a.tail...) case a.kind == namedRead: - start, category = targets[b].start, b.binder.refs.byName[b.ref].head[1:] + // {/c as n}{n.x} or {/c.x as n}{n}: column x of category c. + start, category = targets[b].start, categoryOf(b.binder.refs.byName[b.ref].head) tail = append(targets[b].tail[:len(targets[b].tail):len(targets[b].tail)], a.tail...) - case !grammar.IsRef(a.head): + case grammar.IsRef(a.head): + // {/c.x}: column x of category c. + start, category, tail = t.startOf(a.head), categoryOf(a.head), a.tail + default: return nil } if target, isTemplate := start.(*template); isTemplate && target.isRecord && len(tail) == 1 {