A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://pkg.go.dev/github.com/google/cel-go/interpreter below:

interpreter package - github.com/google/cel-go/interpreter - Go Packages

Package interpreter provides functions to evaluate parsed expressions with the option to augment the evaluation with inputs and functions supplied at evaluation time.

This section is empty.

View Source
var MatchesRegexOptimization = &RegexOptimization{
	Function:   "matches",
	RegexIndex: 1,
	Factory: func(call InterpretableCall, regexPattern string) (InterpretableCall, error) {
		compiledRegex, err := regexp.Compile(regexPattern)
		if err != nil {
			return nil, err
		}
		return NewCall(call.ID(), call.Function(), call.OverloadID(), call.Args(), func(values ...ref.Val) ref.Val {
			if len(values) != 2 {
				return types.NoSuchOverloadErr()
			}
			in, ok := values[0].Value().(string)
			if !ok {
				return types.NoSuchOverloadErr()
			}
			return types.Bool(compiledRegex.MatchString(in))
		}), nil
	},
}

MatchesRegexOptimization optimizes the 'matches' standard library function by compiling the regex pattern and reporting any compilation errors at program creation time, and using the compiled regex pattern for all function call invocations.

func CostTrackerFactory(factory func() (*CostTracker, error)) costTrackPlanOption

CostTrackerFactory configures the factory method to generate a new cost-tracker per-evaluation.

func EvalStateFactory(factory func() EvalState) evalStateOption

EvalStateFactory configures the EvalState generator to be used by the EvalStateObserver.

PruneAst prunes the given AST based on the given EvalState and generates a new AST. Given AST is copied on write and a new AST is returned. Couple of typical use cases this interface would be:

A) 1) Evaluate expr with some unknowns, 2) If result is unknown:

a) PruneAst
b) Goto 1

Functional call results which are known would be effectively cached across iterations.

B) 1) Compile the expression (maybe via a service and maybe after checking a

compiled expression does not exists in local cache)

2) Prepare the environment and the interpreter. Activation might be empty. 3) Eval the expression. This might return unknown or error or a concrete

value.

4) PruneAst 4) Maybe cache the expression This is effectively constant folding the expression. How the environment is prepared in step 2 is flexible. For example, If the caller caches the compiled and constant folded expressions, but is not willing to constant fold(and thus cache results of) some external calls, then they can prepare the overloads accordingly.

Activation used to resolve identifiers by name and references by id.

An Activation is the primary mechanism by which a caller supplies input into a CEL program.

EmptyActivation returns a variable-free activation.

NewActivation returns an activation based on a map-based binding where the map keys are expected to be qualified names used with ResolveName calls.

The input `bindings` may either be of type `Activation` or `map[string]any`.

Lazy bindings may be supplied within the map-based input in either of the following forms: - func() any - func() ref.Val

The output of the lazy binding will overwrite the variable reference in the internal map.

Values which are not represented as ref.Val types on input may be adapted to a ref.Val using the types.Adapter configured in the environment.

NewHierarchicalActivation takes two activations and produces a new one which prioritizes resolution in the child first and parent(s) second.

ActualCostEstimator provides function call cost estimations at runtime CallCost returns an estimated cost for the function overload invocation with the given args, or nil if it has no estimate to provide. CEL attempts to provide reasonable estimates for its standard function library, so CallCost should typically not need to provide an estimate for CELs standard function.

type AttrFactoryOption func(*attrFactory) *attrFactory

AttrFactoryOption specifies a functional option for configuring an attribute factory.

EnableErrorOnBadPresenceTest error generation when a presence test or optional field selection is performed on a primitive type.

Attribute values are a variable or value with an optional set of qualifiers, such as field, key, or index accesses.

type AttributeFactory interface {
	
	
	
	
	
	
	
	
	
	
	AbsoluteAttribute(id int64, names ...string) NamespacedAttribute

	
	
	ConditionalAttribute(id int64, expr Interpretable, t, f Attribute) Attribute

	
	
	
	
	MaybeAttribute(id int64, name string) Attribute

	
	
	RelativeAttribute(id int64, operand Interpretable) Attribute

	
	
	
	
	
	
	
	NewQualifier(objType *types.Type, qualID int64, val any, opt bool) (Qualifier, error)
}

AttributeFactory provides methods creating Attribute and Qualifier values.

NewAttributeFactory returns a default AttributeFactory which is produces Attribute values capable of resolving types by simple names and qualify the values using the supported qualifier types: bool, int, string, and uint.

NewPartialAttributeFactory returns an AttributeFactory implementation capable of performing AttributePattern matches with PartialActivation inputs.

type AttributePattern struct {
	
}

AttributePattern represents a top-level variable with an optional set of qualifier patterns.

When using a CEL expression within a container, e.g. a package or namespace, the variable name in the pattern must match the qualified name produced during the variable namespace resolution. For example, if variable `c` appears in an expression whose container is `a.b`, the variable name supplied to the pattern must be `a.b.c`

The qualifier patterns for attribute matching must be one of the following:

Examples:

  1. ns.myvar["complex-value"]
  2. ns.myvar["complex-value"][0]
  3. ns.myvar["complex-value"].*.name

The first example is simple: match an attribute where the variable is 'ns.myvar' with a field access on 'complex-value'. The second example expands the match to indicate that only a specific index `0` should match. And lastly, the third example matches any indexed access that later selects the 'name' field.

NewAttributePattern produces a new mutable AttributePattern based on a variable name.

QualBool adds a bool qualifier pattern for a map index operation to the AttributePattern.

QualInt adds an int qualifier pattern to the AttributePattern. The index may be either a map or list index.

QualString adds a string qualifier pattern to the AttributePattern. The string may be a valid identifier, or string map key including empty string.

QualUint adds an uint qualifier pattern for a map index operation to the AttributePattern.

QualifierPatterns returns the set of AttributeQualifierPattern values on the AttributePattern.

VariableMatches returns true if the fully qualified variable matches the AttributePattern fully qualified variable name.

Wildcard adds a special sentinel qualifier pattern that will match any single qualifier.

type AttributeQualifierPattern struct {
	
}

AttributeQualifierPattern holds a wildcard or valued qualifier pattern.

Matches returns true if the qualifier pattern is a wildcard, or the Qualifier implements the qualifierValueEquator interface and its IsValueEqualTo returns true for the qualifier pattern.

type CancellationCause int

CancellationCause enumerates the ways a program evaluation operation can be cancelled.

ConstantQualifier interface embeds the Qualifier interface and provides an option to inspect the qualifier's constant value.

Non-constant qualifiers are of Attribute type.

CostTracker represents the information needed for tracking runtime cost.

NewCostTracker creates a new CostTracker with a given estimator and a set of functional CostTrackerOption values.

ActualCost returns the runtime cost

CostTrackerOption configures the behavior of CostTracker objects.

CostTrackerLimit sets the runtime limit on the evaluation cost during execution and will terminate the expression evaluation if the limit is exceeded.

OverloadCostTracker binds an overload ID to a runtime FunctionTracker implementation.

OverloadCostTracker instances augment or override ActualCostEstimator decisions, allowing for versioned and/or optional cost tracking changes.

PresenceTestHasCost determines whether presence testing has a cost of one or zero. Defaults to presence test has a cost of one.

Dispatcher resolves function calls to their appropriate overload.

ExtendDispatcher returns a Dispatcher which inherits the overloads of its parent, and provides an isolation layer between built-ins and extension functions which is useful for forward compatibility.

NewDispatcher returns an empty Dispatcher instance.

EvalCancelledError represents a cancelled program evaluation operation.

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.

EvalState tracks the values associated with expression ids during execution.

NewEvalState returns an EvalState instanced used to observe the intermediate evaluations of an expression.

FunctionTracker computes the actual cost of evaluating the functions with the given arguments and result.

Interpretable can accept a given Activation and produce a value along with an accompanying EvalState which can be used to inspect whether additional data might be necessary to complete the evaluation.

InterpretableAttribute interface for tracking whether the Interpretable is an attribute.

InterpretableCall interface for inspecting Interpretable instructions related to function calls.

NewCall creates a new call Interpretable.

InterpretableConst interface for tracking whether the Interpretable is a constant value.

NewConstValue creates a new constant valued Interpretable.

InterpretableConstructor interface for inspecting Interpretable instructions that initialize a list, map or struct.

InterpretableDecorator is a functional interface for decorating or replacing Interpretable expression nodes at construction time.

Interpreter generates a new Interpretable from a checked or unchecked expression.

NewInterpreter builds an Interpreter from a Dispatcher and TypeProvider which will be used throughout the Eval of all Interpretable instances generated from it.

NamespacedAttribute values are a variable within a namespace, and an optional set of qualifiers such as field, key, or index accesses.

ObservableInterpretable is an Interpretable which supports stateful observation, such as tracing or cost-tracking.

Eval proxies to the ObserveEval method while invoking a no-op callback to report the observations.

ID implements the Interpretable method to get the expression id associated with the step.

ObserveEval evaluates an interpretable and performs per-evaluation state-tracking.

This method is concurrency safe and the expectation is that the observer function will use a switch statement to determine the type of the state which has been reported back from the call.

PartialActivation extends the Activation interface with a set of UnknownAttributePatterns.

AsPartialActivation walks the activation hierarchy and returns the first PartialActivation, if found.

NewPartialActivation returns an Activation which contains a list of AttributePattern values representing field and index operations that should result in a 'types.Unknown' result.

The `bindings` value may be any value type supported by the interpreter.NewActivation call, but is typically either an existing Activation or map[string]any.

type PlannerOption func(*planner) (*planner, error)

PlannerOption configures the program plan options during interpretable setup.

CompileRegexConstants compiles regex pattern string constants at program creation time and reports any regex pattern compile errors.

CostObserver provides an observer that tracks runtime cost.

CustomDecorator configures a custom interpretable decorator for the program.

EvalStateObserver provides an observer which records the value associated with the given expression id. EvalState must be provided to the observer.

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.

InterruptableEval annotates comprehension loops with information that indicates they should check the `#interrupted` state within a custom Activation.

The custom activation is currently managed higher up in the stack within the 'cel' package and should not require any custom support on behalf of callers.

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.

Qualifier marker interface for designating different qualifier values and where they appear within field selections and index call expressions (`_[_]`).

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.

StatefulObserver observes evaluation while tracking or utilizing stateful behavior.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4