Trim comments that restate or argue

The operand order was written out in three places; it now lives at calcVars,
which fixes it, and the other two point there. Dropped the note explaining
why ')' is not reserved, which said what the set is not rather than what it
is, and shortened reservedList's doc to less than its body. The note on held
now states where it reaches instead of arguing against a design this repo no
longer contains.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
M
2026-08-31 13:43:19 +02:00
committed by lilleman-tw
parent 1b5e928d4f
commit 909596ec2d
3 changed files with 6 additions and 10 deletions
+1 -3
View File
@@ -257,11 +257,9 @@ func weightOf(raw any) (float64, error) {
// separates the segments of a path, '|' the arms of a token, '(' opens a function // separates the segments of a path, '|' the arms of a token, '(' opens a function
// call and '}' ends the token. A name carrying one is reachable by no format, so it // call and '}' ends the token. A name carrying one is reachable by no format, so it
// is rejected where it is authored rather than at the token that cannot reach it. // is rejected where it is authored rather than at the token that cannot reach it.
// ')' is absent deliberately — it is spellable on its own, so it stays legal.
const reservedInName = ".|(}" const reservedInName = ".|(}"
// reservedList is reservedInName spelled out for an error message, so the two // reservedList spells reservedInName for an error message, so the two cannot drift.
// cannot drift apart.
var reservedList = strings.Join(strings.Split(reservedInName, ""), " ") var reservedList = strings.Join(strings.Split(reservedInName, ""), " ")
// checkName rejects a name the dot path and {token} grammars cannot spell. Both a // checkName rejects a name the dot path and {token} grammars cannot spell. Both a
+3 -4
View File
@@ -138,8 +138,8 @@ func expand(s *session, t *template) string {
var b strings.Builder var b strings.Builder
b.Grow(t.grow) b.Grow(t.grow)
// One draw per held name, for this expansion only: a nested template and each // One draw per held name, for this expansion only: a nested template and each
// repeat iteration get their own, since each is its own expansion. held stays a // repeat iteration get their own, since each is its own expansion. held reaches
// local: nothing hands it to a builtin, so it and its maps never leave the stack. // no further than readField, which keeps it and its maps on the stack.
var held *draws var held *draws
if len(t.held) > 0 { if len(t.held) > 0 {
held = &draws{ held = &draws{
@@ -157,8 +157,7 @@ func expand(s *session, t *template) string {
case 'f': case 'f':
b.WriteString(readField(s, t, held, o.arms[s.IntN(len(o.arms))])) b.WriteString(readField(s, t, held, o.arms[s.IntN(len(o.arms))]))
case 'b': case 'b':
// A calc's operands are read here, in the order its expression first // Read in the order calcVars fixed, which is what op.operands holds.
// names them, so the value it computes is the value the format showed.
var operands []string var operands []string
if len(o.operands) > 0 { if len(o.operands) > 0 {
operands = make([]string, len(o.operands)) operands = make([]string, len(o.operands))
+2 -3
View File
@@ -317,9 +317,8 @@ type op struct {
r rune // kind 'c' r rune // kind 'c'
arms []arm // kind 'f': the '|' alternatives, split into key and path once arms []arm // kind 'f': the '|' alternatives, split into key and path once
call callFn call callFn
// operands names the sibling fields a {calc()} reads, in the order its // operands names the sibling fields a {calc()} reads, in the order calcVars
// expression first names them. expand reads them before the call, so the // fixed; expand reads them before the call. nil for every other builtin.
// evaluator never touches the node tree. nil for every other builtin.
operands []string operands []string
} }