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

Function ToAST

common/ast/conversion.go:78–105  ·  view source on GitHub ↗

ToAST converts a CheckedExpr protobuf to an AST instance.

(checked *exprpb.CheckedExpr)

Source from the content-addressed store, hash-verified

76
77// ToAST converts a CheckedExpr protobuf to an AST instance.
78func ToAST(checked *exprpb.CheckedExpr) (*AST, error) {
79 refMap := make(map[int64]*ReferenceInfo, len(checked.GetReferenceMap()))
80 for id, ref := range checked.GetReferenceMap() {
81 r, err := ProtoToReferenceInfo(ref)
82 if err != nil {
83 return nil, err
84 }
85 refMap[id] = r
86 }
87 typeMap := make(map[int64]*types.Type, len(checked.GetTypeMap()))
88 for id, typ := range checked.GetTypeMap() {
89 t, err := types.ExprTypeToType(typ)
90 if err != nil {
91 return nil, err
92 }
93 typeMap[id] = t
94 }
95 info, err := ProtoToSourceInfo(checked.GetSourceInfo())
96 if err != nil {
97 return nil, err
98 }
99 root, err := ProtoToExpr(checked.GetExpr())
100 if err != nil {
101 return nil, err
102 }
103 ast := NewCheckedAST(NewAST(root, info), typeMap, refMap)
104 return ast, nil
105}
106
107// ProtoToExpr converts a protobuf Expr value to an ast.Expr value.
108func ProtoToExpr(e *exprpb.Expr) (Expr, error) {

Callers 4

TestASTCopyFunction · 0.92
TestASTJsonNamesFunction · 0.92
TestConvertASTFunction · 0.92

Calls 6

ExprTypeToTypeFunction · 0.92
ProtoToReferenceInfoFunction · 0.85
ProtoToSourceInfoFunction · 0.85
ProtoToExprFunction · 0.85
NewCheckedASTFunction · 0.85
NewASTFunction · 0.85

Tested by 3

TestASTCopyFunction · 0.74
TestASTJsonNamesFunction · 0.74
TestConvertASTFunction · 0.74