@@ -1302,16 +1302,28 @@ func (e *Evaluator) Process(cmd Cmder) (string, bool, error) {
13021302 }
13031303 return prototext .Format (pAST ), false , nil
13041304 case * evalCmd :
1305- val , resultT , err := e .Evaluate (cmd .expr )
1305+ var (
1306+ val ref.Val
1307+ resultT * exprpb.Type
1308+ err error
1309+ )
1310+ if cmd .parseOnly {
1311+ val , resultT , err = e .EvaluateParseOnly (cmd .expr )
1312+ } else {
1313+ val , resultT , err = e .Evaluate (cmd .expr )
1314+ }
13061315 if err != nil {
13071316 return "" , false , fmt .Errorf ("expr failed:\n %v" , err )
13081317 }
13091318 if val != nil {
1310- t := UnparseType (resultT )
13111319 unknown , ok := val .Value ().(* types.Unknown )
13121320 if ok {
13131321 return fmt .Sprintf ("Unknown %v" , unknown ), false , nil
13141322 }
1323+ if cmd .parseOnly {
1324+ return fmt .Sprintf ("%s" , types .Format (val )), false , nil
1325+ }
1326+ t := UnparseType (resultT )
13151327 return fmt .Sprintf ("%s : %s" , types .Format (val ), t ), false , nil
13161328 }
13171329 case * letVarCmd :
@@ -1394,6 +1406,29 @@ func (e *Evaluator) Evaluate(expr string) (ref.Val, *exprpb.Type, error) {
13941406 return val , ast .ResultType (), err
13951407}
13961408
1409+ // EvaluateParseOnly evalutes the CEL expression using the current REPL context without type checking.
1410+ func (e * Evaluator ) EvaluateParseOnly (expr string ) (ref.Val , * exprpb.Type , error ) {
1411+ env , act , err := e .applyContext ()
1412+ if err != nil {
1413+ return nil , nil , err
1414+ }
1415+
1416+ ast , iss := env .Parse (expr )
1417+ if iss .Err () != nil {
1418+ return nil , nil , iss .Err ()
1419+ }
1420+
1421+ p , err := env .Program (ast , e .ctx .programOptions ()... )
1422+ if err != nil {
1423+ return nil , nil , err
1424+ }
1425+
1426+ act , _ = env .PartialVars (act )
1427+ val , _ , err := p .Eval (act )
1428+ // expression can be well-formed and result in an error
1429+ return val , ast .ResultType (), err
1430+ }
1431+
13971432// Compile compiles the input expression using the current REPL context.
13981433func (e * Evaluator ) Compile (expr string ) (* cel.Ast , error ) {
13991434 env , _ , err := e .applyContext ()
0 commit comments