Bump cel-go to v0.10.0
This commit is contained in:
97
vendor/github.com/google/cel-go/interpreter/interpreter.go
generated
vendored
97
vendor/github.com/google/cel-go/interpreter/interpreter.go
generated
vendored
@@ -38,41 +38,118 @@ type Interpreter interface {
|
||||
decorators ...InterpretableDecorator) (Interpretable, error)
|
||||
}
|
||||
|
||||
// EvalObserver is a functional interface that accepts an expression id and an observed value.
|
||||
// The id identifies the expression that was evaluated, the programStep is the Interpretable or Qualifier that
|
||||
// was evaluated and value is the result of the evaluation.
|
||||
type EvalObserver func(id int64, programStep interface{}, value ref.Val)
|
||||
|
||||
// Observe constructs a decorator that calls all the provided observers in order after evaluating each Interpretable
|
||||
// or Qualifier during program evaluation.
|
||||
func Observe(observers ...EvalObserver) InterpretableDecorator {
|
||||
if len(observers) == 1 {
|
||||
return decObserveEval(observers[0])
|
||||
}
|
||||
observeFn := func(id int64, programStep interface{}, val ref.Val) {
|
||||
for _, observer := range observers {
|
||||
observer(id, programStep, val)
|
||||
}
|
||||
}
|
||||
return decObserveEval(observeFn)
|
||||
}
|
||||
|
||||
// EvalCancelledError represents a cancelled program evaluation operation.
|
||||
type EvalCancelledError struct {
|
||||
Message string
|
||||
// Type identifies the cause of the cancellation.
|
||||
Cause CancellationCause
|
||||
}
|
||||
|
||||
func (e EvalCancelledError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
// CancellationCause enumerates the ways a program evaluation operation can be cancelled.
|
||||
type CancellationCause int
|
||||
|
||||
const (
|
||||
// ContextCancelled indicates that the operation was cancelled in response to a Golang context cancellation.
|
||||
ContextCancelled CancellationCause = iota
|
||||
|
||||
// CostLimitExceeded indicates that the operation was cancelled in response to the actual cost limit being
|
||||
// exceeded.
|
||||
CostLimitExceeded
|
||||
)
|
||||
|
||||
// TODO: Replace all usages of TrackState with EvalStateObserver
|
||||
|
||||
// TrackState decorates each expression node with an observer which records the value
|
||||
// associated with the given expression id. EvalState must be provided to the decorator.
|
||||
// This decorator is not thread-safe, and the EvalState must be reset between Eval()
|
||||
// calls.
|
||||
// DEPRECATED: Please use EvalStateObserver instead. It composes gracefully with additional observers.
|
||||
func TrackState(state EvalState) InterpretableDecorator {
|
||||
observer := func(id int64, val ref.Val) {
|
||||
return Observe(EvalStateObserver(state))
|
||||
}
|
||||
|
||||
// EvalStateObserver provides an observer which records the value
|
||||
// associated with the given expression id. EvalState must be provided to the observer.
|
||||
// This decorator is not thread-safe, and the EvalState must be reset between Eval()
|
||||
// calls.
|
||||
func EvalStateObserver(state EvalState) EvalObserver {
|
||||
return func(id int64, programStep interface{}, val ref.Val) {
|
||||
state.SetValue(id, val)
|
||||
}
|
||||
return decObserveEval(observer)
|
||||
}
|
||||
|
||||
// TODO: Replace all usages of ExhaustiveEval with ExhaustiveEvalWrapper
|
||||
|
||||
// ExhaustiveEval replaces operations that short-circuit with versions that evaluate
|
||||
// expressions and couples this behavior with the TrackState() decorator to provide
|
||||
// insight into the evaluation state of the entire expression. EvalState must be
|
||||
// provided to the decorator. This decorator is not thread-safe, and the EvalState
|
||||
// must be reset between Eval() calls.
|
||||
func ExhaustiveEval(state EvalState) InterpretableDecorator {
|
||||
func ExhaustiveEval() InterpretableDecorator {
|
||||
ex := decDisableShortcircuits()
|
||||
obs := TrackState(state)
|
||||
return func(i Interpretable) (Interpretable, error) {
|
||||
var err error
|
||||
i, err = ex(i)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return obs(i)
|
||||
return ex(i)
|
||||
}
|
||||
}
|
||||
|
||||
func InterruptableEval() InterpretableDecorator {
|
||||
return decInterruptFolds()
|
||||
}
|
||||
|
||||
// Optimize will pre-compute operations such as list and map construction and optimize
|
||||
// call arguments to set membership tests. The set of optimizations will increase over time.
|
||||
func Optimize() InterpretableDecorator {
|
||||
return decOptimize()
|
||||
}
|
||||
|
||||
// RegexOptimization provides a way to replace an InterpretableCall for a regex function when the
|
||||
// RegexIndex argument is a string constant. Typically, the Factory would compile the regex pattern at
|
||||
// RegexIndex and report any errors (at program creation time) and then use the compiled regex for
|
||||
// all regex function invocations.
|
||||
type RegexOptimization struct {
|
||||
// Function is the name of the function to optimize.
|
||||
Function string
|
||||
// OverloadID is the ID of the overload to optimize.
|
||||
OverloadID string
|
||||
// RegexIndex is the index position of the regex pattern argument. Only calls to the function where this argument is
|
||||
// a string constant will be delegated to this optimizer.
|
||||
RegexIndex int
|
||||
// Factory constructs a replacement InterpretableCall node that optimizes the regex function call. Factory is
|
||||
// provided with the unoptimized regex call and the string constant at the RegexIndex argument.
|
||||
// The Factory may compile the regex for use across all invocations of the call, return any errors and
|
||||
// return an interpreter.NewCall with the desired regex optimized function impl.
|
||||
Factory func(call InterpretableCall, regexPattern string) (InterpretableCall, error)
|
||||
}
|
||||
|
||||
// CompileRegexConstants compiles regex pattern string constants at program creation time and reports any regex pattern
|
||||
// compile errors.
|
||||
func CompileRegexConstants(regexOptimizations ...*RegexOptimization) InterpretableDecorator {
|
||||
return decRegexOptimizer(regexOptimizations...)
|
||||
}
|
||||
|
||||
type exprInterpreter struct {
|
||||
dispatcher Dispatcher
|
||||
container *containers.Container
|
||||
|
Reference in New Issue
Block a user