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

Method configure

cel/env.go:892–967  ·  view source on GitHub ↗

configure applies a series of EnvOptions to the current environment.

(opts []EnvOption)

Source from the content-addressed store, hash-verified

890
891// configure applies a series of EnvOptions to the current environment.
892func (e *Env) configure(opts []EnvOption) (*Env, error) {
893 // Customized the environment using the provided EnvOption values. If an error is
894 // generated at any step this, will be returned as a nil Env with a non-nil error.
895 var err error
896 for _, opt := range opts {
897 e, err = opt(e)
898 if err != nil {
899 return nil, err
900 }
901 }
902
903 // If the default UTC timezone has been disabled, configure the legacy overloads
904 if utcTime, isSet := e.features[featureDefaultUTCTimeZone]; isSet && !utcTime {
905 if !e.appliedFeatures[featureDefaultUTCTimeZone] {
906 e.ensureMutableAppliedFeatures()
907 e.appliedFeatures[featureDefaultUTCTimeZone] = true
908 e, err = Lib(timeLegacyLibrary{})(e)
909 if err != nil {
910 return nil, err
911 }
912 }
913 }
914
915 // Configure the parser.
916 prsrOpts := []parser.Option{}
917 prsrOpts = append(prsrOpts, e.prsrOpts...)
918 prsrOpts = append(prsrOpts, parser.Macros(e.macros...))
919
920 if e.HasFeature(featureEnableMacroCallTracking) {
921 prsrOpts = append(prsrOpts, parser.PopulateMacroCalls(true))
922 }
923 if e.HasFeature(featureVariadicLogicalASTs) {
924 prsrOpts = append(prsrOpts, parser.EnableVariadicOperatorASTs(true))
925 }
926 if e.HasFeature(featureIdentEscapeSyntax) {
927 prsrOpts = append(prsrOpts, parser.EnableIdentEscapeSyntax(true))
928 }
929 if l := e.limits[limitParseErrorRecovery]; l != 0 {
930 prsrOpts = append(prsrOpts, parser.ErrorRecoveryLimit(l))
931 }
932 if l := e.limits[limitCodePointSize]; l != 0 {
933 prsrOpts = append(prsrOpts, parser.ExpressionSizeCodePointLimit(l))
934 }
935 if l := e.limits[limitParseRecursionDepth]; l != 0 {
936 prsrOpts = append(prsrOpts, parser.MaxRecursionDepth(l))
937 }
938 if l := e.limits[limitExpressionNodeCount]; l != 0 {
939 prsrOpts = append(prsrOpts, parser.MaxExpressionNodeCount(l))
940 }
941 e.prsr, err = parser.NewParser(prsrOpts...)
942 if err != nil {
943 return nil, err
944 }
945
946 // Enable JSON field names is using a proto-based *types.Registry
947 if e.HasFeature(featureJSONFieldNames) {
948 reg, isReg := e.provider.(*types.Registry)
949 if !isReg {

Callers 2

ExtendMethod · 0.95
NewCustomEnvFunction · 0.80

Calls 14

HasFeatureMethod · 0.95
initCheckerMethod · 0.95
MacrosFunction · 0.92
PopulateMacroCallsFunction · 0.92
EnableIdentEscapeSyntaxFunction · 0.92
ErrorRecoveryLimitFunction · 0.92
MaxRecursionDepthFunction · 0.92
MaxExpressionNodeCountFunction · 0.92
NewParserFunction · 0.92

Tested by

no test coverage detected