MCPcopy
hub / github.com/expr-lang/expr / Eval

Function Eval

expr.go:269–290  ·  view source on GitHub ↗

Eval parses, compiles and runs given input.

(input string, env any)

Source from the content-addressed store, hash-verified

267
268// Eval parses, compiles and runs given input.
269func Eval(input string, env any) (any, error) {
270 if _, ok := env.(Option); ok {
271 return nil, fmt.Errorf("misused expr.Eval: second argument (env) should be passed without expr.Env")
272 }
273
274 tree, err := parser.Parse(input)
275 if err != nil {
276 return nil, err
277 }
278
279 program, err := compiler.Compile(tree, nil)
280 if err != nil {
281 return nil, err
282 }
283
284 output, err := Run(program, env)
285 if err != nil {
286 return nil, err
287 }
288
289 return output, nil
290}

Callers 15

Benchmark_expr_evalFunction · 0.92
ExampleEvalFunction · 0.92
TestExprFunction · 0.92
TestExpr_eval_with_envFunction · 0.92
TestExpr_fetch_from_funcFunction · 0.92
TestEval_exposed_errorFunction · 0.92
TestEnv_keywordFunction · 0.92

Calls 4

ParseFunction · 0.92
CompileFunction · 0.92
RunFunction · 0.70
ErrorfMethod · 0.65

Tested by 15

Benchmark_expr_evalFunction · 0.74
ExampleEvalFunction · 0.74
TestExprFunction · 0.74
TestExpr_eval_with_envFunction · 0.74
TestExpr_fetch_from_funcFunction · 0.74
TestEval_exposed_errorFunction · 0.74
TestEnv_keywordFunction · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…