Documentation
¶
Overview ¶
Package projection adds the `{ ... }` projection syntax. The parser dispatches the opening `{` through this bundle's PrimaryExtension; the ProjectionExpr it produces is lowered at build time to the projection runtime action, which evaluates the body with expr-lang. Without this bundle, `{ }` in expression position is a syntax error.
Typical use:
{ name: "Maksymilian", extra: true } -> { name: .name }
{ id: 1, status: "new" } -> { ..., status: "active" }
Index ¶
- Constants
- func Bundle(_ map[string]string) compiler.Bundle
- func DefaultEvaluator(_ context.Context, req Request) (any, error)
- func Library(eval Evaluator) action.Library
- func Primary() compiler.PrimaryExtension
- func PrimaryWithFunctions(functions *FunctionSet) compiler.PrimaryExtension
- func RewriteFunctionReferences(source string, references map[string]string) string
- type Evaluator
- type Extension
- type FunctionDefinition
- type FunctionParameter
- type FunctionSet
- type Request
Constants ¶
const ID = "projection"
Variables ¶
This section is empty.
Functions ¶
func DefaultEvaluator ¶
DefaultEvaluator returns the input unchanged.
func Library ¶
Library returns the runtime projection action bound to eval. A nil eval falls back to DefaultEvaluator, which is a pass-through — used only in isolated parser tests.
func Primary ¶
func Primary() compiler.PrimaryExtension
Primary returns the parser extension. Exposed so tests can build a parser without spinning up the whole bundle.
func PrimaryWithFunctions ¶ added in v0.63.0
func PrimaryWithFunctions(functions *FunctionSet) compiler.PrimaryExtension
PrimaryWithFunctions returns a projection primary carrying this file-local function set. It merges with the ordinary projection primary through the compiler's existing MergeablePrimary contract.
func RewriteFunctionReferences ¶ added in v0.63.0
RewriteFunctionReferences replaces qualified function names while preserving quoted text and ordinary member access. It is used when an imported module's local function names are mounted below its @include namespace.
Types ¶
type Evaluator ¶
Evaluator converts a projection body into a value. NewExprEvaluator is the production implementation; DefaultEvaluator is a pass-through used only in isolated tests.
func NewExprEvaluator ¶
func NewExprEvaluator() Evaluator
NewExprEvaluator compiles each projection body once and caches it. The transformation rules are documented in buildProgramSource and preprocessDots.
type Extension ¶
type Extension struct {
// contains filtered or unexported fields
}
Extension is the compile-time parser extension. It dispatches on the opening brace and scans the raw source up to the matching close, tracking quotes so braces inside strings are ignored.
func (Extension) MergeWith ¶ added in v0.63.0
func (e Extension) MergeWith(older compiler.PrimaryExtension) compiler.PrimaryExtension
MergeWith carries a source-local function set into the existing projection parser. The compiler merges it only into compilations that declared or inherited those functions.
type FunctionDefinition ¶ added in v0.63.0
type FunctionDefinition struct {
Name string
Parameters []FunctionParameter
Result string
Body string
Position compiler.Position
}
FunctionDefinition is the expression-only form of an NFlow @func declaration. The projection extension owns expression compilation so calls receive normal expr-lang type checking without a process-global function registry.
type FunctionParameter ¶ added in v0.63.0
FunctionParameter describes one typed parameter in a source-local @func.
type FunctionSet ¶ added in v0.63.0
type FunctionSet struct {
// contains filtered or unexported fields
}
FunctionSet is immutable after construction and can be shared by the projections compiled from one source/module. Its cache is deliberately local to that source; identical expression text in another source cannot reuse a program with different function bindings.
func MergeFunctionSets ¶ added in v0.63.0
func MergeFunctionSets(older, newer *FunctionSet) *FunctionSet
MergeFunctionSets combines inherited and local declarations without silently shadowing a function name. Identical inherited declarations are de-duplicated.
func NewFunctionSet ¶ added in v0.63.0
func NewFunctionSet(definitions []FunctionDefinition) *FunctionSet
NewFunctionSet copies declarations and assigns deterministic internal names for expr-lang, whose custom-function API accepts simple identifiers only.
func (*FunctionSet) Compile ¶ added in v0.63.0
func (s *FunctionSet) Compile(source string, position compiler.Position) (compiler.ExpressionProgram, error)
Compile rewrites source-visible function names and compiles an expression with this immutable source-local function environment.
func (*FunctionSet) Validate ¶ added in v0.63.0
func (s *FunctionSet) Validate() error
Validate compiles all declarations, checking signatures, bodies, references, result types, and recursion before a program is built.