MCPcopy Create free account
hub / github.com/ForestHubAI/edge-agents / Eval

Function Eval

go/engine/expr/expression.go:21–44  ·  view source on GitHub ↗

Eval evaluates an workflow.Expression against resolved references, returning a typed Value.

(expr workflow.Expression, resolve VarResolver)

Source from the content-addressed store, hash-verified

19// Eval evaluates an workflowapi.Expression against resolved references,
20// returning a typed Value.
21func Eval(expr workflowapi.Expression, resolve VarResolver) (Value, error) {
22 plCount := len(placeholderRE.FindAllStringIndex(expr.Expression, -1))
23 refCount := len(expr.References)
24 if plCount != refCount {
25 return Value{}, fmt.Errorf(
26 "expression placeholders (%d) do not match references (%d)",
27 plCount, refCount,
28 )
29 }
30
31 refs := make([]Value, refCount)
32 for i, ref := range expr.References {
33 v, err := resolve.Resolve(ref)
34 if err != nil {
35 return Value{}, err
36 }
37 // An image has no text or scalar form; using one in an expression
38 // would silently coerce the frame to an empty/zero value.
39 if v.Type == workflowapi.Image {
40 return Value{}, fmt.Errorf("an image value cannot be used in an expression")
41 }
42 refs[i] = v
43 }
44
45 if expr.DataType == workflowapi.String {
46 return evalStringExpr(expr.Expression, refs)
47 }

Callers 15

TestEval_EmptyStringFunction · 0.85
TestEval_LiteralStringFunction · 0.85
TestEval_ArithmeticFunction · 0.85
TestEval_ComparisonFunction · 0.85
TestEval_BooleanFunction · 0.85
TestEval_NegationFunction · 0.85
TestEval_CastInStringFunction · 0.85
TestEval_CastInCodeFunction · 0.85

Calls 3

evalStringExprFunction · 0.85
evalCodeExprFunction · 0.85
ResolveMethod · 0.65

Tested by 15

TestEval_EmptyStringFunction · 0.68
TestEval_LiteralStringFunction · 0.68
TestEval_ArithmeticFunction · 0.68
TestEval_ComparisonFunction · 0.68
TestEval_BooleanFunction · 0.68
TestEval_NegationFunction · 0.68
TestEval_CastInStringFunction · 0.68
TestEval_CastInCodeFunction · 0.68