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

Function initStandard

common/stdlib/standard.go:43–905  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

41)
42
43func initStandard() {
44 paramA := types.NewTypeParamType("A")
45 paramB := types.NewTypeParamType("B")
46 listOfA := types.NewListType(paramA)
47 mapOfAB := types.NewMapType(paramA, paramB)
48
49 stdTypes = []*decls.VariableDecl{
50 decls.TypeVariable(types.BoolType),
51 decls.TypeVariable(types.BytesType),
52 decls.TypeVariable(types.DoubleType),
53 decls.TypeVariable(types.DurationType),
54 decls.TypeVariable(types.IntType),
55 decls.TypeVariable(listOfA),
56 decls.TypeVariable(mapOfAB),
57 decls.TypeVariable(types.NullType),
58 decls.TypeVariable(types.StringType),
59 decls.TypeVariable(types.TimestampType),
60 decls.TypeVariable(types.TypeType),
61 decls.TypeVariable(types.UintType),
62 }
63
64 stdFunctions = []*decls.FunctionDecl{
65 // Logical operators. Special-cased within the interpreter.
66 // Note, the singleton binding prevents extensions from overriding the operator behavior.
67 function(operators.Conditional,
68 decls.FunctionDocs(
69 `The ternary operator tests a boolean predicate and returns the left-hand side `+
70 `(truthy) expression if true, or the right-hand side (falsy) expression if false`),
71 decls.Overload(overloads.Conditional, argTypes(types.BoolType, paramA, paramA), paramA,
72 decls.OverloadIsNonStrict(),
73 decls.OverloadExamples(
74 `'hello'.contains('lo') ? 'hi' : 'bye' // 'hi'`,
75 `32 % 3 == 0 ? 'divisible' : 'not divisible' // 'not divisible'`)),
76 decls.SingletonFunctionBinding(noFunctionOverrides)),
77
78 function(operators.LogicalAnd,
79 decls.FunctionDocs(
80 `logically AND two boolean values. Errors and unknown values`,
81 `are valid inputs and will not halt evaluation.`),
82 decls.Overload(overloads.LogicalAnd, argTypes(types.BoolType, types.BoolType), types.BoolType,
83 decls.OverloadIsNonStrict(),
84 decls.OverloadExamples(
85 `true && true // true`,
86 `true && false // false`,
87 `error && true // error`,
88 `error && false // false`)),
89 decls.SingletonBinaryBinding(noBinaryOverrides)),
90
91 function(operators.LogicalOr,
92 decls.FunctionDocs(
93 `logically OR two boolean values. Errors and unknown values`,
94 `are valid inputs and will not halt evaluation.`),
95 decls.Overload(overloads.LogicalOr, argTypes(types.BoolType, types.BoolType), types.BoolType,
96 decls.OverloadIsNonStrict(),
97 decls.OverloadExamples(
98 `true || false // true`,
99 `false || false // false`,
100 `error || true // true`,

Callers

nothing calls this directly

Calls 15

NewTypeParamTypeFunction · 0.92
NewListTypeFunction · 0.92
NewMapTypeFunction · 0.92
TypeVariableFunction · 0.92
FunctionDocsFunction · 0.92
OverloadFunction · 0.92
OverloadIsNonStrictFunction · 0.92
OverloadExamplesFunction · 0.92
SingletonFunctionBindingFunction · 0.92
SingletonBinaryBindingFunction · 0.92
SingletonUnaryBindingFunction · 0.92
MaybeNoSuchOverloadErrFunction · 0.92

Tested by

no test coverage detected