expr

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 19 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 expr compiles and evaluates the predicates of intent and workflow manifests: CEL expressions (cel-go) over typed facts, checked at load.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Closest added in v0.2.0

func Closest(s string, options []string) string

Closest is the option a typo of s plausibly meant, "" when none is that close: the same word in another case, or one at most max(1, len(s)/4) edits away, a swap of two neighbors counting as one. A tie is no suggestion, since either guess may be wrong.

func CompileWorkflow

func CompileWorkflow(src string, env Env) (workflow.Predicate, error)

CompileWorkflow compiles a workflow's `when` over env (one unit slot, trigger.* and config.*) plus now, the evaluation's time.

func DidYouMean added in v0.2.0

func DidYouMean(s string, options []string) string

DidYouMean is "; did you mean \"x\"?" for Closest's x, "" when none.

func Requires added in v0.2.0

func Requires(p workflow.Predicate, field, value string) bool

Requires says whether every match of p has field equal to value: a term field == "value" of p's top-level conjunction, which no other term can bypass.

Types

type Env

type Env map[string]Type // dotted field -> type, one slot

func (Env) ClearEnum added in v0.2.0

func (e Env) ClearEnum(name string)

ClearEnum lets the string fact name take any value again.

func (Env) Enum added in v0.2.0

func (e Env) Enum(name string) []string

Enum is the closed values of name, sorted; nil when it takes any value.

func (Env) Names added in v0.2.0

func (e Env) Names() []string

Names are the env's facts, sorted.

func (Env) SetEnum added in v0.2.0

func (e Env) SetEnum(name string, values []string)

SetEnum declares the closed values of the string fact name: a predicate that compares it with a literal outside them does not compile.

type Error

type Error struct {
	Col     int // 1-based within the expression
	Msg     string
	Snippet string // the expression, then a caret line
}

func (*Error) Error

func (e *Error) Error() string

type Facts

type Facts interface{ Get(field string) any }

Facts resolves a dotted field; the value's Go type matches the Env (bool, int, string, []string, time.Duration, time.Time).

type Program

type Program struct {
	// contains filtered or unexported fields
}

func Compile

func Compile(src string, env Env) (*Program, error)

Compile type-checks src against env; it returns an *Error on failure, and an empty or blank src is an error.

func (*Program) Eval

func (p *Program) Eval(f Facts) bool

Eval evaluates the predicate; a nil fact reads as its type's zero value and a runtime error, such as a fact of another Go type, reads as false.

func (*Program) Reads

func (p *Program) Reads() []string

Reads are the fields the predicate names, sorted.

func (*Program) Source added in v0.2.0

func (p *Program) Source() string

Source is the expression as the manifest wrote it.

type Type

type Type int
const (
	Bool Type = iota + 1
	Int
	String
	List
	Duration
	Time
)

func (Type) String

func (t Type) String() string

Jump to

Keyboard shortcuts

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