Skip to content

Commit

Permalink
chore: Simplify residual expression
Browse files Browse the repository at this point in the history
CEL 0.18.2 [added a method](google/cel-go#789 (comment)) to get the native AST object from the AST wrapper.

Signed-off-by: Charith Ellawala <charith@cerbos.dev>
  • Loading branch information
charithe committed Nov 16, 2023
1 parent 12354c3 commit 9d58a39
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions internal/engine/planner/planner.go
Original file line number Diff line number Diff line change
Expand Up @@ -671,22 +671,8 @@ func evalComprehensionBodyImpl(env *cel.Env, pvars interpreter.PartialActivation
}

func ResidualExpr(a *cel.Ast, details *cel.EvalDetails) (*exprpb.Expr, error) {
pe, err := cel.AstToParsedExpr(a)
if err != nil {
return nil, fmt.Errorf("failed to get parsed expression from AST: %w", err)
}

expr, err := celast.ProtoToExpr(pe.Expr)
if err != nil {
return nil, fmt.Errorf("failed to convert proto to expr: %w", err)
}

sourceInfo, err := celast.ProtoToSourceInfo(pe.SourceInfo)
if err != nil {
return nil, fmt.Errorf("failed to convert sourceInfo: %w", err)
}

prunedAST := interpreter.PruneAst(expr, sourceInfo.MacroCalls(), details.State())
ast := a.NativeRep()
prunedAST := interpreter.PruneAst(ast.Expr(), ast.SourceInfo().MacroCalls(), details.State())
return celast.ExprToProto(prunedAST.Expr())
}

Expand Down

0 comments on commit 9d58a39

Please sign in to comment.