expression

package
v2.0.0-...-02ad64b Latest Latest
Warning

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

Go to latest
Published: May 19, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ASTSet

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

ASTSet represents a collection of compiledAST and their associated cel.Env.

func CompileASTs

func CompileASTs[T Expression](
	expressions []T,
	env *cel.Env,
	envOpts ...cel.EnvOption,
) (set ASTSet, err error)

CompileASTs parses and type checks a set of expressions, producing a resulting ASTSet. The value can then be converted to a ProgramSet via ASTSet.ToProgramSet or ASTSet.ReduceResiduals. Use Compile instead if no cel.ProgramOption args need to be provided or residuals do not need to be computed.

func (ASTSet) Merge

func (set ASTSet) Merge(other ASTSet) ASTSet

Merge combines a set with another, producing a new ASTSet.

func (ASTSet) ReduceResiduals

func (set ASTSet) ReduceResiduals(opts ...cel.ProgramOption) (ProgramSet, error)

ReduceResiduals generates a ProgramSet, performing a partial evaluation of the ASTSet to optimize the expression. If the expression is optimized to either a true or empty string constant result, no compiledProgram is generated for it. The main usage of this is to elide tautological expressions from the final result.

func (ASTSet) ToProgramSet

func (set ASTSet) ToProgramSet(opts ...cel.ProgramOption) (out ProgramSet, err error)

ToProgramSet generates a ProgramSet from the specified ASTs.

type Expression

type Expression interface {
	GetId() string
	GetMessage() string
	GetExpression() string
}

Expression is the read-only interface of either validate.Constraint or private.Constraint which can be the source of a CEL expression.

type ProgramSet

type ProgramSet []compiledProgram

ProgramSet is a list of compiledProgram expressions that are evaluated together with the same input value. All expressions in a ProgramSet may refer to a `this` variable.

func Compile

func Compile[T Expression](
	expressions []T,
	env *cel.Env,
	envOpts ...cel.EnvOption,
) (set ProgramSet, err error)

Compile produces a ProgramSet from the provided expressions in the given environment. If the generated cel.Program require cel.ProgramOption params, use CompileASTs instead with a subsequent call to ASTSet.ToProgramSet.

func (ProgramSet) Eval

func (s ProgramSet) Eval(val any, failFast bool) error

Eval applies the contained expressions to the provided `this` val, returning either *errors.ValidationError if the input is invalid or errors.RuntimeError if there is a type or range error. If failFast is true, execution stops at the first failed expression.

type Variable

type Variable struct {
	// Name is the variable's name
	Name string
	// Val is the value for this variable
	Val any
}

Variable implements interpreter.Activation, providing a lightweight named variable to cel.Program executions.

func (*Variable) Parent

func (v *Variable) Parent() interpreter.Activation

func (*Variable) ResolveName

func (v *Variable) ResolveName(name string) (any, bool)

type VariablePool

type VariablePool sync.Pool

func (*VariablePool) Get

func (p *VariablePool) Get() *Variable

func (*VariablePool) Put

func (p *VariablePool) Put(v *Variable)

Jump to

Keyboard shortcuts

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