funcs

package
v0.68.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package funcs implements source-local @func declarations. Function bodies are pure expressions, callable from projections, conditions, and argument maps.

Index

Constants

View Source
const ID = "func"

Variables

View Source
var Directive = compiler.Directive{
	Name: "func",
	Example: `@func commerce.shippingFeeMinor(subtotalMinor int, destinationZone string) int {
	  subtotalMinor >= 5000 && destinationZone == "domestic" ? 0 : 599
	}`,
	Handler:     handleDirective,
	OpaqueBlock: true,
}

Directive parses pure, single-expression function declarations. Its signature follows Go's name-then-type convention; braced bodies are expression syntax, not Go statement blocks.

Functions

func Bundle

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

Bundle contributes the @func directive, expression compiler, and projection primary for each prepared source. No function definitions are placed in a process-global registry.

func ExpressionCompilerFromMeta

func ExpressionCompilerFromMeta(meta map[string]any) compiler.ExpressionCompiler

ExpressionCompilerFromMeta returns a compiler for all functions visible in one source, including functions mounted through its @include namespaces.

Types

type FunctionDeclaration

type FunctionDeclaration struct {
	Name       string
	Parameters []projection.FunctionParameter
	Result     string
	Body       string
	Position   compiler.Position
}

FunctionDeclaration is the source-level representation stored by @func.

Jump to

Keyboard shortcuts

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