MCPcopy Create free account
hub / github.com/cel-expr/cel-go / Process

Method Process

repl/evaluator.go:1356–1458  ·  view source on GitHub ↗

Process processes the command provided.

(cmd Cmder)

Source from the content-addressed store, hash-verified

1354
1355// Process processes the command provided.
1356func (e *Evaluator) Process(cmd Cmder) (string, bool, error) {
1357 switch cmd := cmd.(type) {
1358 case *compileCmd:
1359 ast, err := e.Compile(cmd.expr)
1360 if err != nil {
1361 return "", false, fmt.Errorf("compile failed:\n%v", err)
1362 }
1363 cAST, err := cel.AstToCheckedExpr(ast)
1364 if err != nil {
1365 return "", false, fmt.Errorf("compile failed:\n%v", err)
1366 }
1367 return prototext.Format(cAST), false, nil
1368 case *parseCmd:
1369 ast, err := e.Parse(cmd.expr)
1370 if err != nil {
1371 return "", false, fmt.Errorf("parse failed:\n%v", err)
1372 }
1373 pAST, err := cel.AstToParsedExpr(ast)
1374 if err != nil {
1375 return "", false, fmt.Errorf("parse failed:\n%v", err)
1376 }
1377 return prototext.Format(pAST), false, nil
1378 case *evalCmd:
1379 var (
1380 val ref.Val
1381 resultT *types.Type
1382 err error
1383 )
1384 if cmd.parseOnly {
1385 val, resultT, err = e.EvaluateParseOnly(cmd.expr)
1386 } else {
1387 val, resultT, err = e.Evaluate(cmd.expr)
1388 }
1389 if err != nil {
1390 return "", false, fmt.Errorf("expr failed:\n%v", err)
1391 }
1392 if val != nil {
1393 unknown, ok := val.Value().(*types.Unknown)
1394 if ok {
1395 return fmt.Sprintf("Unknown %v", unknown), false, nil
1396 }
1397 if cmd.parseOnly {
1398 return fmt.Sprintf("%s", types.Format(val)), false, nil
1399 }
1400 t := envlib.SerializeTypeDesc(resultT).SpecifierFormat()
1401 return fmt.Sprintf("%s : %s", types.Format(val), t), false, nil
1402 }
1403 case *letVarCmd:
1404 var err error
1405 if cmd.src != "" {
1406 err = e.AddLetVar(cmd.identifier, cmd.src, cmd.typeHint)
1407 } else {
1408 // declare only
1409 err = e.AddDeclVar(cmd.identifier, cmd.typeHint)
1410 }
1411 if err != nil {
1412 return "", false, fmt.Errorf("adding variable failed:\n%v", err)
1413 }

Callers 4

TestProcessFunction · 0.95
TestProcessOptionErrorFunction · 0.95
parseYAMLConfigMethod · 0.95
mainFunction · 0.95

Calls 15

CompileMethod · 0.95
ParseMethod · 0.95
EvaluateParseOnlyMethod · 0.95
EvaluateMethod · 0.95
AddLetVarMethod · 0.95
AddDeclVarMethod · 0.95
AddLetFnMethod · 0.95
DelLetVarMethod · 0.95
DelLetFnMethod · 0.95
handleConfigMethod · 0.95
handleStatusMethod · 0.95
loadDescriptorsMethod · 0.95

Tested by 2

TestProcessFunction · 0.76
TestProcessOptionErrorFunction · 0.76