-
Notifications
You must be signed in to change notification settings - Fork 227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate to a native AST and Expr representation #789
Comments
As part of the optimizer work, it's clear that the split between |
Apologies if this is not the right place to ask this. Is the plan to unify the two AST data types into one in a future release? I am a bit confused by how we are supposed to use the new native types right now. Most of the methods to work with parsed expressions take arguments of type celAST, _ := env.Compile(exprString)
checkedExpr, _ := cel.AstToCheckedExpr(celAST)
astAST, _ := ast.ToAST(checkedExpr)
expr := astAST.Expr() // finally have an `ast.Expr` that I can use with `ast.PreOrderVisit` etc. Is there a better way to do this with the current version of CEL (0.18.1) or should I wait for the AST types to be unified? |
@TristonianJones apologies for pinging you directly. I am stuck on the above issue of not being able to access the underlying diff --git a/cel/io.go b/cel/io.go
index 3133fb9..50bb878 100644
--- a/cel/io.go
+++ b/cel/io.go
@@ -101,22 +101,36 @@ func AstToString(a *Ast) (string, error) {
return parser.Unparse(a.impl.Expr(), a.impl.SourceInfo())
}
+// AstToExpr returns the underlying expr of this Ast
+func AstToExpr(a *Ast) ast.Expr {
+ return a.impl.Expr()
+}
+
+// AstToSourceInfo returns the underlying source information of this Ast
+func AstToSourceInfo(a *Ast) *ast.SourceInfo {
+ return a.impl.SourceInfo()
+} |
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>
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>
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> Signed-off-by: Charith Ellawala <charith@cerbos.dev>
@TristonianJones Thank you so much! A little more performant for straight iterating than creating a new optimizer. Appreciate you and all of the work on cel-go! |
Migrate to a native AST and Expr representation.
The original cel-go implementation was heavily based on protobuf definitions
for types, declarations, and expressions. While this was expedient, it has also
been cumbersome. With PR #568, the types and declarations were replaced
by Go-native structs. This issue tracks the migration of the
Expr
,SourceInfo
,and
AST
objects.The motives for making this change are many:
The text was updated successfully, but these errors were encountered: