expr

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 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

View Source
var Renamed = func(string) string { return "" }

Renamed is the name that replaced s, a name the language no longer has; "" when s was never renamed. The builtin package sets it from its table.

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 Suggest's x, "" when none.

func Pinned added in v0.3.0

func Pinned(p workflow.Predicate, field string) []string

Pinned are the literals p's top-level conjunction pins field to, as Requires reads them.

func ReadsNow added in v0.3.0

func ReadsNow(p workflow.Predicate) bool

ReadsNow says whether p, a CompileWorkflow predicate, reads now, so its value can change as time passes with no fact changing.

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.

func Suggest added in v0.3.0

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

Suggest is what s plausibly meant among options, "" when nothing: the name that replaced s when it was renamed and options are empty or hold that name, else Closest's.

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.

func (Env) SetUntrusted added in v0.3.0

func (e Env) SetUntrusted(name string)

SetUntrusted marks the fact name as one an agent or a third party may set, which no releasing approval rule reads.

func (Env) Untrusted added in v0.3.0

func (e Env) Untrusted(name string) bool

Untrusted says whether SetUntrusted marked the fact name.

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 CompileString added in v0.3.0

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

CompileString type-checks src, an expression whose value is a string, against env, as Compile does a predicate; Text evaluates it.

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) Holds added in v0.4.0

func (p *Program) Holds(facts map[string]any) (bool, error)

Holds evaluates the predicate over facts, a fact facts lacks reading as its type's zero value; a runtime error, such as a fact of another Go type, is the error.

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.

func (*Program) Text added in v0.3.0

func (p *Program) Text(facts map[string]any) (string, error)

Text evaluates a program CompileString compiled over facts; a fact facts lacks reads as its type's zero value.

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