projection

package
v0.18.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 7, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

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

View Source
const ID = "projection"

Variables

This section is empty.

Functions

func Bundle

func Bundle(_ map[string]string) core.Bundle

func DefaultEvaluator

func DefaultEvaluator(_ context.Context, req Request) (any, error)

DefaultEvaluator returns the input unchanged.

func Library

func Library(eval Evaluator) action.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() core.PrimaryExtension

Primary returns the parser extension. Exposed so tests can build a parser without spinning up the whole bundle.

Types

type Evaluator

type Evaluator func(context.Context, Request) (any, error)

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{}

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) Name

func (Extension) Name() string

func (Extension) Parse

func (Extension) Parse(p *core.Parser) (core.Expr, error)

func (Extension) TokenType

func (Extension) TokenType() core.TokenType

type Request

type Request struct {
	Raw   string
	Input any
}

Request is one projection evaluation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL