# Extensions
CEL extensions are a related set of constants, functions, macros, or other
features which may not be covered by the core CEL spec.
## Bindings
Returns a cel.EnvOption to configure support for local variable bindings
in expressions.
### Cel.Bind
Binds a simple identifier to an initialization expression which may be used
in a subsequenct result expression. Bindings may also be nested within each
other.
cel.bind(<varName>, <initExpr>, <resultExpr>)
Examples:
cel.bind(a, 'hello',
cel.bind(b, 'world', a + b + b + a)) // "helloworldworldhello"
// Avoid a list allocation within the exists comprehension.
cel.bind(valid_values, [a, b, c],
[d, e, f].exists(elem, elem in valid_values))
Local bindings are not guaranteed to be evaluated before use.
## Encoders
Encoding utilies for marshalling data into standardized representations.
### Base64.Decode
Decodes base64-encoded string to bytes.
This function will return an error if the string input is not
base64-encoded.
base64.decode(<string>) -> <bytes>
Examples:
base64.decode('aGVsbG8=') // return b'hello'
base64.decode('aGVsbG8') // error
### Base64.Encode
Encodes bytes to a base64-encoded string.
base64.encode(<bytes>) -> <string>
Example:
base64.encode(b'hello') // return 'aGVsbG8='
## Math
Math helper macros and functions.
Note, all macros use the 'math' namespace; however, at the time of macro
expansion the namespace looks just like any other identifier. If you are
currently using a variable named 'math', the macro will likely work just as
intended; however, there is some chance for collision.
### Math.Greatest
Returns the greatest valued number present in the arguments to the macro.
Greatest is a variable argument count macro which must take at least one
argument. Simple numeric and list literals are supported as valid argument
types; however, other literals will be flagged as errors during macro
expansion. If the argument expression does not resolve to a numeric or
list(numeric) type during type-checking, or during runtime then an error
will be produced. If a list argument is empty, this too will produce an
error.
math.greatest(<arg>, ...) -> <double|int|uint>
Examples:
math.greatest(1) // 1
math.greatest(1u, 2u) // 2u
math.greatest(-42.0, -21.5, -100.0) // -21.5
math.greatest([-42.0, -21.5, -100.0]) // -21.5
math.greatest(numbers) // numbers must be list(numeric)
math.greatest() // parse error
math.greatest('string') // parse error
math.greatest(a, b) // check-time error if a or b is non-numeric
math.greatest(dyn('string')) // runtime error
### Math.Least
Returns the least valued number present in the arguments to the macro.
Least is a variable argument count macro which must take at least one
argument. Simple numeric and list literals are supported as valid argument
types; however, other literals will be flagged as errors during macro
expansion. If the argument expression does not resolve to a numeric or
list(numeric) type during type-checking, or during runtime then an error
will be produced. If a list argument is empty, this too will produce an
error.
math.least(<arg>, ...) -> <double|int|uint>
Examples:
math.least(1) // 1
math.least(1u, 2u) // 1u
math.least(-42.0, -21.5, -100.0) // -100.0
math.least([-42.0, -21.5, -100.0]) // -100.0
math.least(numbers) // numbers must be list(numeric)
math.least() // parse error
math.least('string') // parse error
math.least(a, b) // check-time error if a or b is non-numeric
math.least(dyn('string')) // runtime error
### Math.BitOr
Introduced at version: 1
Performs a bitwise-OR operation over two int or uint values.
math.bitOr(<int>, <int>) -> <int>
math.bitOr(<uint>, <uint>) -> <uint>
Examples:
math.bitOr(1u, 2u) // returns 3u
math.bitOr(-2, -4) // returns -2
### Math.BitAnd
Introduced at version: 1
Performs a bitwise-AND operation over two int or uint values.
math.bitAnd(<int>, <int>) -> <int>
math.bitAnd(<uint>, <uint>) -> <uint>
Examples:
math.bitAnd(3u, 2u) // return 2u
math.bitAnd(3, 5) // returns 3
math.bitAnd(-3, -5) // returns -7
### Math.BitXor
Introduced at version: 1
math.bitXor(<int>, <int>) -> <int>
math.bitXor(<uint>, <uint>) -> <uint>
Performs a bitwise-XOR operation over two int or uint values.
Examples:
math.bitXor(3u, 5u) // returns 6u
math.bitXor(1, 3) // returns 2
### Math.BitNot
Introduced at version: 1
Function which accepts a single int or uint and performs a bitwise-NOT
ones-complement of the given binary value.
math.bitNot(<int>) -> <int>
math.bitNot(<uint>) -> <uint>
Examples
math.bitNot(1) // returns -1
math.bitNot(-1) // return 0
math.bitNot(0u) // returns 18446744073709551615u
### Math.BitShiftLeft
Introduced at version: 1
Perform a left shift of bits on the first parameter, by the amount of bits
specified in the second parameter. The first parameter is either a uint or
an int. The second parameter must be an int.
When the second parameter is 64 or greater, 0 will be always be returned
since the number of bits shifted is greater than or equal to the total bit
length of the number being shifted. Negative valued bit shifts will result
in a runtime error.
math.bitShiftLeft(<int>, <int>) -> <int>
math.bitShiftLeft(<uint>, <int>) -> <uint>
Examples
math.bitShiftLeft(1, 2) // returns 4
math.bitShiftLeft(-1, 2) // returns -4
math.bitShiftLeft(1u, 2) // return 4u
math.bitShiftLeft(1u, 200) // returns 0u
### Math.BitShiftRight
Introduced at version: 1
Perform a right shift of bits on the first parameter, by the amount of bits
specified in the second parameter. The first parameter is either a uint or
an int. The second parameter must be an int.
When the second parameter is 64 or greater, 0 will always be returned since
the number of bits shifted is greater than or equal to the total bit length
of the number being shifted. Negative valued bit shifts will result in a
runtime error.
The sign bit extension will not be preserved for this operation: vacant bits
on the left are filled with 0.
math.bitShiftRight(<int>, <int>) -> <int>
math.bitShiftRight(<uint>, <int>) -> <uint>
Examples
math.bitShiftRight(1024, 2) // returns 256
math.bitShiftRight(1024u, 2) // returns 256u
math.bitShiftRight(1024u, 64) // returns 0u
### Math.Ceil
Introduced at version: 1
Compute the ceiling of a double value.
math.ceil(<double>) -> <double>
Examples:
math.ceil(1.2) // returns 2.0
math.ceil(-1.2) // returns -1.0
### Math.Floor
Introduced at version: 1
Compute the floor of a double value.
math.floor(<double>) -> <double>
Examples:
math.floor(1.2) // returns 1.0
math.floor(-1.2) // returns -2.0
### Math.Round
Introduced at version: 1
Rounds the double value to the nearest whole number with ties rounding away
from zero, e.g. 1.5 -> 2.0, -1.5 -> -2.0.
math.round(<double>) -> <double>
Examples:
math.round(1.2) // returns 1.0
math.round(1.5) // returns 2.0
math.round(-1.5) // returns -2.0
### Math.Trunc
Introduced at version: 1
Truncates the fractional portion of the double value.
math.trunc(<double>) -> <double>
Examples:
math.trunc(-1.3) // returns -1.0
math.trunc(1.3) // returns 1.0
### Math.Abs
Introduced at version: 1
Returns the absolute value of the numeric type provided as input. If the
value is NaN, the output is NaN. If the input is int64 min, the function
will result in an overflow error.
math.abs(<double>) -> <double>
math.abs(<int>) -> <int>
math.abs(<uint>) -> <uint>
Examples:
math.abs(-1) // returns 1
math.abs(1) // returns 1
math.abs(-9223372036854775808) // overlflow error
### Math.Sign
Introduced at version: 1
Returns the sign of the numeric type,
没有合适的资源?快使用搜索试试~ 我知道了~
快速、可移植、非图灵完备的渐进式表达式评估(Go).zip
共709个文件
go:508个
bazel:38个
yaml:34个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 31 浏览量
2024-12-03
03:18:45
上传
评论
收藏 1.71MB ZIP 举报
温馨提示
通用表达语言 通用表达式语言 (CEL) 是一种非图灵完备语言,旨在实现简单、快速、安全和可移植性。CEL 的 C 类语法与 C++、Go、Java 和 TypeScript 中的等效表达式几乎完全相同。// Check whether a resource name starts with a group name.resource.name.startsWith("/groups/" + auth.claims.group)// Determine whether the request is in the permitted time window.request.time - resource.age < duration("24h")// Check whether all resource names in a list match a given filter.auth.claims.email_verified && resources.all(r, r.startsWith(auth.claims.email))CEL“程序”是一个单一表达式
资源推荐
资源详情
资源评论
收起资源包目录
快速、可移植、非图灵完备的渐进式表达式评估(Go).zip (709个子文件)
BUILD.bazel 4KB
BUILD.bazel 3KB
BUILD.bazel 3KB
BUILD.bazel 3KB
BUILD.bazel 2KB
MODULE.bazel 2KB
BUILD.bazel 2KB
BUILD.bazel 2KB
BUILD.bazel 2KB
BUILD.bazel 2KB
BUILD.bazel 2KB
BUILD.bazel 2KB
BUILD.bazel 2KB
BUILD.bazel 2KB
MODULE.bazel 1KB
BUILD.bazel 1KB
BUILD.bazel 1KB
BUILD.bazel 1KB
BUILD.bazel 1KB
BUILD.bazel 1KB
BUILD.bazel 1KB
BUILD.bazel 853B
BUILD.bazel 730B
BUILD.bazel 674B
BUILD.bazel 645B
BUILD.bazel 642B
BUILD.bazel 611B
BUILD.bazel 596B
BUILD.bazel 586B
BUILD.bazel 570B
BUILD.bazel 498B
BUILD.bazel 474B
BUILD.bazel 399B
BUILD.bazel 385B
BUILD.bazel 379B
BUILD.bazel 321B
BUILD.bazel 310B
BUILD.bazel 118B
.bazelversion 55B
.bazelversion 6B
editions_defaults.binpb 93B
conformance_test.bzl 2KB
WORKSPACE.bzlmod 0B
WORKSPACE.bzlmod 0B
.editorconfig 316B
team.fds 290B
CEL.g4 5KB
Commands.g4 2KB
.gcloudignore 723B
.gitattributes 53B
.gitignore 548B
.gitignore 200B
.gitignore 174B
.gitignore 147B
.gitignore 26B
.gitkeep 0B
descriptor.pb.go 243KB
commands_parser.go 230KB
codec_gen.go 163KB
tables.go 153KB
cel_parser.go 141KB
cel_test.go 82KB
syntax.pb.go 77KB
descriptor_gen.go 71KB
checker_test.go 66KB
test_all_types.pb.go 64KB
checked.pb.go 64KB
interpreter_test.go 63KB
strings_test.go 61KB
parser_atn_simulator.go 61KB
syntax.pb.go 57KB
parser_test.go 56KB
test_all_types.pb.go 54KB
tables.go 52KB
checked.pb.go 49KB
attributes.go 43KB
interpretable.go 39KB
map_test.go 36KB
decls_test.go 34KB
attributes_test.go 33KB
tables.go 31KB
env.go 30KB
parser.go 30KB
decls.go 29KB
native_test.go 28KB
provider_test.go 28KB
evaluator.go 28KB
formatting.go 28KB
standard.go 28KB
struct.pb.go 27KB
error_strategy.go 27KB
desc.go 27KB
map.go 27KB
type.go 26KB
strings.go 26KB
math.go 26KB
library.go 26KB
codec_field.go 26KB
well_known_types.go 25KB
list_test.go 25KB
共 709 条
- 1
- 2
- 3
- 4
- 5
- 6
- 8
资源评论
赵闪闪168
- 粉丝: 1677
- 资源: 5392
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功