expression

package
v0.9.8 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: AGPL-3.0, AGPL-3.0-or-later Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package expression defines the single shared expression and rule evaluation contract (PLUGIN-007). Every feature — computed fields, constraints, workflow preconditions, and rules — must evaluate through one deterministic, side-effect-free Evaluator over a typed AST and a typed Value model.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrExprDepthExceeded

type ErrExprDepthExceeded struct {
	Limit int
}

ErrExprDepthExceeded reports an AST deeper than the allowed limit.

func (ErrExprDepthExceeded) Error

func (e ErrExprDepthExceeded) Error() string

type ErrExprParse

type ErrExprParse struct {
	Pos    int
	Detail string
}

ErrExprParse is returned for parse failures.

func (ErrExprParse) Error

func (e ErrExprParse) Error() string

type ErrExprTypeMismatch

type ErrExprTypeMismatch struct {
	Got, Want string
}

ErrExprTypeMismatch reports an operation on incompatible value kinds.

func (ErrExprTypeMismatch) Error

func (e ErrExprTypeMismatch) Error() string

type ErrUnknownFunction

type ErrUnknownFunction struct {
	Name string
}

ErrUnknownFunction reports a call to a function outside the closed registry.

func (ErrUnknownFunction) Error

func (e ErrUnknownFunction) Error() string

type Evaluator

type Evaluator interface {
	Eval(ctx context.Context, ast *Expr, scope Scope) (Value, error)
}

Evaluator evaluates an AST against a scope, deterministically and with no side effects.

type Expr

type Expr struct {
	Kind ExprKind

	// Literal
	Value Value
	// Ident
	Name string
	// Binary
	Op   string // + - * / = != < <= > >= AND OR
	L, R *Expr
	// Call / Aggregate
	Func string // ROUND | SUM
	Args []*Expr
}

Expr is a typed AST node.

type ExprError

type ExprError struct {
	Pos    int
	Detail string
}

ExprError is a typed expression error.

func (ExprError) Error

func (e ExprError) Error() string

type ExprKind

type ExprKind string

ExprKind classifies an AST node.

const (
	ExprLiteral   ExprKind = "literal"
	ExprIdent     ExprKind = "ident"
	ExprBinary    ExprKind = "binary"
	ExprCall      ExprKind = "call"      // ROUND(expr, N)
	ExprAggregate ExprKind = "aggregate" // SUM(table.field)
)

type ParseResult

type ParseResult struct {
	AST    *Expr
	Deps   []string
	Errors []ExprError
}

ParseResult is the outcome of parsing an expression source.

type Scope

type Scope interface {
	Lookup(path string) (Value, bool)
	Aggregate(fn, table, field string) (Value, error)
}

Scope resolves identifiers and aggregates. Lookup returns typed values only.

type TreeEvaluator

type TreeEvaluator struct {
	MaxDepth int
}

TreeEvaluator is a deterministic, depth-limited Evaluator. It performs no clock, randomness, or I/O; evaluation order is fixed by the AST.

func NewTreeEvaluator

func NewTreeEvaluator() *TreeEvaluator

NewTreeEvaluator returns an evaluator with a default depth limit of 64.

func (*TreeEvaluator) Eval

func (e *TreeEvaluator) Eval(ctx context.Context, ast *Expr, scope Scope) (Value, error)

Eval evaluates ast against scope.

type Value

type Value struct {
	Kind   ValueKind
	Number float64
	String string
	Bool   bool
}

Value is a typed expression value.

func BoolValue

func BoolValue(b bool) Value

BoolValue builds a boolean Value.

func NullValue

func NullValue() Value

NullValue builds a null Value.

func NumberValue

func NumberValue(n float64) Value

NumberValue builds a numeric Value.

func StringValue

func StringValue(s string) Value

StringValue builds a string Value.

type ValueKind

type ValueKind string

ValueKind classifies a typed value. No map[string]any crosses this boundary.

const (
	ValueNumber ValueKind = "number"
	ValueString ValueKind = "string"
	ValueBool   ValueKind = "bool"
	ValueNull   ValueKind = "null"
)

Jump to

Keyboard shortcuts

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