Documentation
¶
Overview ¶
Package totalcall finds the total(expr) calls an expression makes and judges where they may appear — the one rule shared by the engine (internal/processing: ATTR_FORMULA's two-pass build, the expression filterer's and overlay formula's refusals), the merge gate (internal/mergegate) and the no-execute field-reference pass (internal/descriptor: predict and the runtime's entry check). It parses expr-lang and nothing else, so internal/descriptor may import it without reaching the engine (TestPredictNoExecutionImports).
total(expr) is ATTR_FORMULA's cohort-total term: the sum of a row-level expression over the post-filter rows, computed in a pre-pass and read as a constant by every row. A formula that calls it is therefore NOT row-local — Contains is the per-attribute predicate every type-keyed row-local gate must ask beside the attribute type.
Index ¶
- Constants
- func ArgKey(c *exprast.CallNode) string
- func Args(src string) []string
- func Contains(src string) bool
- func Index(keys []string) map[string]int
- func IsCall(n exprast.Node) (*exprast.CallNode, bool)
- func Options(index map[string]int, read func(args ...any) (any, error)) []expr.Option
- func Refusal(src, site string) *errors.CodedError
Constants ¶
const FormulaSite = "ATTR_FORMULA"
FormulaSite is the one expression site that accepts total().
const Func = "total"
Func is the expression function name. Lowercase, like coef / lookup; an embedder ExprFunction may not claim it.
Variables ¶
This section is empty.
Functions ¶
func ArgKey ¶
ArgKey is the accumulator key of a one-argument total() call: its argument's canonical printed form.
func Args ¶
Args returns the argument source of every distinct one-argument total() call in src, in walk order (post-order: an inner call before its parent, left before right), keyed by the argument's canonical printed form (ast.Node.String) — the key the engine's patcher reads back to find a call's accumulator. nil when src does not parse or makes no call.
func Contains ¶
Contains reports whether src calls total(...) anywhere. A source that does not parse reports false — its compile reports the syntax error.
func Index ¶
Index maps every key of keys (Args) to its slot, the position the patched total(<slot>) call reads.
func Options ¶
Options declares total() for the compile of a total-bearing formula: the function — read(slot) is the slot's published sum, typed func(int) float64 — and the patcher rewriting every total(<arg>) call to total(<slot>), the slot index holds for its argument's key (ArgKey). The engine binds read to its pre-pass sums; predict, which never runs the program, binds a placeholder. Both declare total() through here, so a formula type-checks identically on either side (`total(qty) + "a"` is a float64 + string on both).
func Refusal ¶
func Refusal(src, site string) *errors.CodedError
Refusal is the coded refusal of src's total() calls at the named expression site ("ATTR_FORMULA", "FILTER_EXPRESSION", "OVERLAY_FORMULA"), nil when every call is admissible:
- outside ATTR_FORMULA, any call is PULSE_FORMULA_TOTAL_SITE;
- in ATTR_FORMULA, a call whose argument itself calls total() is PULSE_FORMULA_TOTAL_NESTED, and one with other than exactly one argument is PULSE_FORMULA_TOTAL_ARITY.
A source that does not parse yields nil (the compile reports it).
Types ¶
This section is empty.