Make walkEvery the zero mode, and have drawPath's panic name the head its tail descends from
This commit is contained in:
@@ -37,7 +37,7 @@ func readField(s *session, t *template, held *hold, sc renderScope, a arm) draw
|
|||||||
if r, done := d.value[a.path]; done {
|
if r, done := d.value[a.path]; done {
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
r := renderLeaf(s, drawPath(t.head(a.key), a.tail, &d.pins, &pathDraws{s: s, held: d, a: &a}), sc)
|
r := renderLeaf(s, drawPath(t.head(a.key), a.tail, a.key, &d.pins, &pathDraws{s: s, held: d, a: &a}), sc)
|
||||||
if d.value == nil {
|
if d.value == nil {
|
||||||
d.value = map[string]draw{}
|
d.value = map[string]draw{}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -130,11 +130,11 @@ func names(segs []string) []string {
|
|||||||
type walkMode uint8
|
type walkMode uint8
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// walkCover stops at a choice, handing it whole to leaf, and reads no row.
|
|
||||||
walkCover walkMode = iota
|
|
||||||
// walkEvery proves every variant carries the rest of the path and walks each,
|
// walkEvery proves every variant carries the rest of the path and walks each,
|
||||||
// pinning the rows it selects in pins.
|
// pinning the rows it selects in pins.
|
||||||
walkEvery
|
walkEvery walkMode = iota
|
||||||
|
// walkCover stops at a choice, handing it whole to leaf, and reads no row.
|
||||||
|
walkCover
|
||||||
// walkProbe proves as walkEvery does, walking one variant, so a path that
|
// walkProbe proves as walkEvery does, walking one variant, so a path that
|
||||||
// resolves resolves whichever variants and rows are drawn.
|
// resolves resolves whichever variants and rows are drawn.
|
||||||
walkProbe
|
walkProbe
|
||||||
@@ -144,8 +144,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// pathWalk is one walk of a dotted path: level runs at each template a segment
|
// pathWalk is one walk of a dotted path: level runs at each template a segment
|
||||||
// descends into, leaf where the walk ends, and a nil action is skipped. A render's
|
// descends into, leaf where the walk ends, and a nil action is skipped.
|
||||||
// walk sets only pins and draws, so it allocates nothing.
|
|
||||||
type pathWalk struct {
|
type pathWalk struct {
|
||||||
mode walkMode
|
mode walkMode
|
||||||
level func(t *template, rest []string) error
|
level func(t *template, rest []string) error
|
||||||
@@ -211,10 +210,11 @@ func (w pathWalk) atLeaf(n node) error {
|
|||||||
|
|
||||||
// drawPath draws the rows and variants a path reads, pinning them in pins. The path
|
// drawPath draws the rows and variants a path reads, pinning them in pins. The path
|
||||||
// must be proved first, by a probe or by New's fences, so the walk cannot fail.
|
// must be proved first, by a probe or by New's fences, so the walk cannot fail.
|
||||||
func drawPath(n node, tail []string, pins *pinSet, draws *pathDraws) node {
|
// head is what n is reached by, for the panic.
|
||||||
|
func drawPath(n node, tail []string, head string, pins *pinSet, draws *pathDraws) node {
|
||||||
leaf, err := walkPath(n, tail, pathWalk{mode: walkDraw, pins: pins, draws: draws})
|
leaf, err := walkPath(n, tail, pathWalk{mode: walkDraw, pins: pins, draws: draws})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("fejkdata: %s: %v; the path should have been proved before it was drawn", joinSegments(tail), err))
|
panic(fmt.Sprintf("fejkdata: %s: %v; the path should have been proved before it was drawn", join(head, joinSegments(tail)), err))
|
||||||
}
|
}
|
||||||
return leaf
|
return leaf
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ func descend(s *session, root node, segments []string, sc renderScope) (node, er
|
|||||||
if _, err := walkPath(root, segments, pathWalk{mode: walkProbe, pins: &probe}); err != nil {
|
if _, err := walkPath(root, segments, pathWalk{mode: walkProbe, pins: &probe}); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return drawPath(root, segments, &sc.hold().pins, &pathDraws{s: s}), nil
|
return drawPath(root, segments, "", &sc.hold().pins, &pathDraws{s: s}), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// render evaluates a compiled node to a string. compile validates every node up
|
// render evaluates a compiled node to a string. compile validates every node up
|
||||||
|
|||||||
Reference in New Issue
Block a user