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

Method initChecker

cel/env.go:1058–1138  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1056}
1057
1058func (e *Env) initChecker() (*checker.Env, error) {
1059 e.chkOnce.Do(func() {
1060 chkOpts := []checker.Option{}
1061 chkOpts = append(chkOpts, e.chkOpts...)
1062 chkOpts = append(chkOpts,
1063 checker.CrossTypeNumericComparisons(
1064 e.HasFeature(featureCrossTypeNumericComparisons)))
1065 chkOpts = append(chkOpts,
1066 checker.JSONFieldNames(e.HasFeature(featureJSONFieldNames)))
1067
1068 chkOpts = append(chkOpts, checker.Catalog(func() *env.Catalog {
1069 conf, err := e.ToConfig("")
1070 if err != nil {
1071 return env.NewCatalog()
1072 }
1073 cat := conf.ToCatalog()
1074 for _, f := range e.functions {
1075 cat.Add(&env.CatalogSymbol{
1076 Name: f.Name(),
1077 Kind: env.FunctionKind,
1078 })
1079 }
1080 for _, t := range stdlib.Types() {
1081 cat.Add(&env.CatalogSymbol{
1082 Name: t.Name(),
1083 Kind: env.TypeKind,
1084 })
1085 }
1086 for _, m := range e.macros {
1087 cat.Add(&env.CatalogSymbol{
1088 Name: m.Function(),
1089 Kind: env.MacroKind,
1090 })
1091 }
1092 // TODO: Come up with a better mechanism to dynamically populate catalog symbols
1093 // for un-enabled libraries (e.g. leaning on the introspection and serialization
1094 // properties used by ToConfig).
1095 if !e.HasLibrary("cel.lib.optional") {
1096 cat.Add((&optionalLib{}).CatalogSymbols()...)
1097 }
1098 return cat
1099 }))
1100
1101 if e.parent != nil && e.funcsShared {
1102 parentChk, err := e.parent.initChecker()
1103 if err != nil {
1104 e.setCheckerOrError(nil, err)
1105 return
1106 }
1107 chkOpts = append(chkOpts, checker.ValidatedDeclarations(parentChk))
1108 }
1109
1110 ce, err := checker.NewEnv(e.Container, e.provider, chkOpts...)
1111 if err != nil {
1112 e.setCheckerOrError(nil, err)
1113 return
1114 }
1115 // Add the statically configured declarations.

Callers 2

CheckMethod · 0.95
configureMethod · 0.95

Calls 15

HasFeatureMethod · 0.95
ToConfigMethod · 0.95
HasLibraryMethod · 0.95
setCheckerOrErrorMethod · 0.95
AddIdentsMethod · 0.95
AddFunctionsMethod · 0.95
getCheckerOrErrorMethod · 0.95
JSONFieldNamesFunction · 0.92
CatalogFunction · 0.92
NewCatalogFunction · 0.92
TypesFunction · 0.92

Tested by

no test coverage detected