مرجع API زبان عبارت مشترک (CEL)

این سند به عنوان مرجع یکپارچه API Doc برای زبان عبارات مشترک (CEL) عمل می‌کند. این سند تمام ماکروها، عملگرها و توابع استاندارد را فهرست می‌کند و امضاها، رفتارها و وضعیت پشتیبانی آنها را در پشته‌های رسمی CEL نشان می‌دهد.

برای جزئیات بیشتر در مورد رفتار و مشخصات زبان، به تعریف زبان CEL مراجعه کنید.

نسخه‌های پشته‌ای

این سند مرجع بر اساس نسخه‌های زیر از پشته‌های CEL تهیه شده است:

  • CEL Go : v0.32.0 (و جدیدتر)
  • سل سی++ : v0.16.1
  • جاوا CEL : v0.14.0
  • زبان برنامه‌نویسی پایتون (CEL) : v0.1.3
  • CEL C : تصویر لحظه‌ای از توسعه (منتشر نشده)

آینه‌های گیت‌هاب

پیاده‌سازی‌های رسمی CEL در GitHub تحت سازمان cel-expr منعکس شده‌اند:


۱. ماکروهای اصلی

اینها ماکروهای داخلی هستند که در زمان کامپایل گسترش می‌یابند.

ماکرو توضیحات برو سی++ جاوا پایتون سی
has(container.field) بررسی می‌کند که آیا یک فیلد در یک پیام یا یک کلید در یک نقشه وجود دارد یا خیر.

امضاها:
has(container.field) -> bool

مثال‌ها:
has(request.auth.claims.email)
list.all(var, predicate) بررسی می‌کند که آیا همه عناصر موجود در یک لیست، یک گزاره را برآورده می‌کنند یا خیر.

امضاها:
list.all(var, predicate) -> bool

مثال‌ها:
[1, 2, 3].all(x, x > 0) // true
¹
list.exists(var, predicate) بررسی می‌کند که آیا حداقل یک عنصر در یک لیست، یک گزاره را برآورده می‌کند یا خیر.

امضاها:
list.exists(var, predicate) -> bool

مثال‌ها:
[1, 2, 3].exists(x, x > 2) // true
¹
list.exists_one(var, predicate) بررسی می‌کند که آیا دقیقاً یک عنصر در یک لیست، یک گزاره را برآورده می‌کند یا خیر.

امضاها:
list.exists_one(var, predicate) -> bool

مثال‌ها:
[1, 2, 3].exists_one(x, x == 2) // true
¹
list.filter(var, predicate) عناصر یک لیست را بر اساس یک گزاره فیلتر می‌کند.

امضاها:
list.filter(var, predicate) -> list

مثال‌ها:
[1, 2, 3].filter(x, x > 1) // [2, 3]
¹
list.map(var, transform) هر عنصر یک لیست را با استفاده از یک عبارت تبدیل می‌کند.

امضاها:
list.map(var, transform) -> list

مثال‌ها:
[1, 2, 3].map(x, x * 2) // [2, 4, 6]
¹
list.map(var, filter, transform) عناصری از یک لیست را که در گزاره فیلتر صدق می‌کنند، تبدیل می‌کند.

امضاها:
list.map(var, filter, transform) -> list

مثال‌ها:
[1, 2, 3].map(x, x > 1, x * 2) // [4, 6]
¹

¹ در زمان اجرای C پشتیبانی می‌شود زیرا ماکروها در حین کامپایل توسط کامپایلر میزبان به درک متقابل گسترش می‌یابند.


۲. اپراتورهای اصلی

اپراتور توضیحات برو سی++ جاوا پایتون سی
محاسبات ( + ، - ، * ، / ، % ) عملیات حسابی استاندارد. نفی ( -x ) و هویت ( +x ). الحاق لیست ( list + list ) در Go، C++، Java و Python پشتیبانی می‌شود.

امضاها:
T + T -> T
T - T -> T
T * T -> T
T / T -> T
T % T -> T
-T -> T
+T -> T
list + list -> list

مثال‌ها:
1 + 2 * 3 // 7
[1] + [2] // [1, 2]
²
مقایسه ( == ، != ، < ، <= ، > ، >= ) مقایسه استاندارد. مقایسه‌های عددی ناهمگن هستند (مثلاً 1 == 1.0 ).

امضاها:
T == T -> bool
T != T -> bool
T < T -> bool
T <= T -> bool
T > T -> bool
T >= T -> bool

مثال‌ها:
x < 42.0
1 == 1.0 // true
منطقی ( ! ، && ، || ، ? : :) توابع منطقی NOT، AND، OR و شرطی سه‌تایی. AND/OR از ارزیابی اتصال کوتاه استفاده می‌کنند.

امضاها:
!bool -> bool
bool && bool -> bool
bool || bool -> bool
bool ? T : T -> T

مثال‌ها:
x > 0 ? "positive" : "non-positive"
فهرست بندی ( [] ) دسترسی به عنصر یک لیست از طریق اندیس یا کلید جستجو در نقشه.

امضاها:
list[int] -> T
map[K] -> V

مثال‌ها:
tags[0]
users['john']
عضویت ( in ) بررسی می‌کند که آیا عنصر در یک لیست است یا کلید در یک نقشه قرار دارد.

امضاها:
T in list -> bool
K in map -> bool

مثال‌ها:
'admin' in roles

² الحاق لیست ( list + list ) در زمان اجرای C پشتیبانی نمی‌شود ، اگرچه سایر عملگرهای حسابی پشتیبانی می‌شوند.


۳. کارکردهای اصلی

توابع عمومی و رشته‌ای

عملکرد توضیحات برو سی++ جاوا پایتون سی
size اندازه یک رشته (کاراکتر)، بایت، لیست یا نقشه را برمی‌گرداند.

امضاها:
size(T) -> int (که در آن T می‌تواند string ، bytes ، list یا map باشد)

مثال‌ها:
size("hello") // 5
contains برمی‌گرداند که آیا رشته شامل زیررشته است یا خیر.

امضاها:
string.contains(string) -> bool

مثال‌ها:
"hello".contains("ell") // true
startsWith برمی‌گرداند که آیا رشته با پیشوند شروع می‌شود یا خیر.

امضاها:
string.startsWith(string) -> bool

مثال‌ها:
"hello".startsWith("he") // true
endsWith برمی‌گرداند که آیا رشته با پسوند به پایان می‌رسد یا خیر.

امضاها:
string.endsWith(string) -> bool

مثال‌ها:
"hello".endsWith("lo") // true
matches برمی‌گرداند که آیا رشته با عبارت منظم RE2 مطابقت دارد یا خیر.

امضاها:
string.matches(string) -> bool

مثال‌ها:
"123".matches(r"^\d+$") // true

توابع انتخابگر تاریخ و زمان

این توابع، کامپوننت‌ها را از google.protobuf.Timestamp یا google.protobuf.Duration استخراج می‌کنند.

عملکرد توضیحات برو سی++ جاوا پایتون سی
getFullYear سال را به صورت ۴ رقمی برمی‌گرداند.

امضاها:
timestamp.getFullYear([tz]) -> int

مثال‌ها:
timestamp("2026-07-23T00:00:00Z").getFullYear() // 2026
getMonth ماه (0-11) را برمی‌گرداند.

امضاها:
timestamp.getMonth([tz]) -> int

مثال‌ها:
timestamp("2026-07-23T00:00:00Z").getMonth() // 6
getDayOfMonth روز ماه (۱-۳۱) را برمی‌گرداند.

امضاها:
timestamp.getDayOfMonth([tz]) -> int

مثال‌ها:
timestamp("2026-07-23T00:00:00Z").getDayOfMonth() // 23
getDayOfWeek روز هفته را برمی‌گرداند (0 = یکشنبه).

امضاها:
timestamp.getDayOfWeek([tz]) -> int

مثال‌ها:
timestamp("2026-07-23T00:00:00Z").getDayOfWeek() // 4
getDayOfYear روز سال (0-365) را برمی‌گرداند.

امضاها:
timestamp.getDayOfYear([tz]) -> int

مثال‌ها:
timestamp("2026-07-23T00:00:00Z").getDayOfYear() // 203
getHours ساعت (0-23) را برمی‌گرداند.

امضاها:
timestamp.getHours([tz]) -> int
duration.getHours() -> int

مثال‌ها:
duration("1h30m").getHours() // 1
getMinutes دقیقه (0-59) را برمی‌گرداند.

امضاها:
timestamp.getMinutes([tz]) -> int
duration.getMinutes() -> int

مثال‌ها:
duration("1h30m").getMinutes() // 30
getSeconds ثانیه‌ها (0-59) را برمی‌گرداند.

امضاها:
timestamp.getSeconds([tz]) -> int
duration.getSeconds() -> int

مثال‌ها:
duration("1h30m45s").getSeconds() // 45
getMilliseconds میلی ثانیه (0-999) را برمی‌گرداند.

امضاها:
timestamp.getMilliseconds([tz]) -> int
duration.getMilliseconds() -> int

مثال‌ها:
duration("1.5s").getMilliseconds() // 500

تبدیل نوع

نوع هدف توضیحات برو سی++ جاوا پایتون سی
bool به بولی تبدیل می‌کند.

امضاها:
bool(bool) -> bool
bool(string) -> bool

مثال‌ها:
bool("true") // true
bytes به بایت تبدیل می‌کند.

امضاها:
bytes(bytes) -> bytes
bytes(string) -> bytes

مثال‌ها:
bytes("hello") // b"hello"
double به نوع اعشاری با دقت مضاعف تبدیل می‌کند.

امضاها:
double(double) -> double
double(int) -> double
double(uint) -> double
double(string) -> double

مثال‌ها:
double(1) // 1.0
duration به مدت زمان تبدیل می‌کند.

امضاها:
duration(duration) -> duration
duration(string) -> duration

مثال‌ها:
duration("1.5s") // 1.5s duration
int به عدد صحیح علامت‌دار ۶۴ بیتی تبدیل می‌کند.

امضاها:
int(int) -> int
int(uint) -> int
int(double) -> int (به صفر گرد می‌کند)
int(string) -> int
int(timestamp) -> int (ثانیه از زمان شروع)

مثال‌ها:
int(1.5) // 1
string به رشته تبدیل می‌کند.

امضاها:
string(T) -> string ( bool ، int ، uint ، double ، bytes ، timestamp ، duration پشتیبانی می‌کند)

مثال‌ها:
string(1.5) // "1.5"
timestamp به برچسب زمانی تبدیل می‌شود.

امضاها:
timestamp(timestamp) -> timestamp
timestamp(string) -> timestamp (RFC3339)

مثال‌ها:
timestamp("2026-07-23T00:00:00Z")
uint به عدد صحیح بدون علامت ۶۴ بیتی تبدیل می‌کند.

امضاها:
uint(uint) -> uint
uint(int) -> uint
uint(double) -> uint
uint(string) -> uint

مثال‌ها:
uint(1) // 1u
dyn برای بررسی نوع، مقدار را به نوع پویا تبدیل می‌کند.

امضاها:
dyn(T) -> dyn

مثال‌ها:
dyn([1, "two"])
type نوع مقدار را برمی‌گرداند.

امضاها:
type(T) -> type

مثال‌ها:
type(1) // int

۴. افزونه‌ها (کتابخانه‌ها)

کتابخانه صحافی

عملکرد توضیحات برو سی++ جاوا پایتون سی
cel.bind برای جلوگیری از ارزیابی تکراری، یک متغیر محلی را مقید می‌کند.

امضاها:
cel.bind(varName, initExpr, resultExpr) -> T

مثال‌ها:
cel.bind(x, a + b, x * x)
(نسخه ۰.۱۵.۰) (نسخه ۰.۱۰.۰) (نسخه ۰.۲.۰) (نسخه ۰.۱.۱)

نحوه فعال کردن

  • برو: ext.Bindings() را به cel.NewEnv() ارسال کن.
  • ++C: تابع BindingsCompilerLibrary() را به CompilerBuilder اضافه کنید. (زمان اجرا به صورت خودکار مدیریت می‌شود).
  • جاوا: CelExtensions.bindings() را به سازندگان CelCompiler و CelRuntime اضافه کنید.
  • پایتون: cel_expr_python.ext.ext_bindings وارد کنید و ExtBindings() در cel.NewEnv(extensions=[...]) استفاده کنید.

کتابخانه انکودرها

عملکرد توضیحات برو سی++ جاوا پایتون سی
base64.encode بایت‌ها را به رشته‌ی base64 کدگذاری می‌کند.

امضاها:
base64.encode(bytes) -> string

مثال‌ها:
base64.encode(b"hello") // "aGVsbG8="
(نسخه ۰.۶.۰) (نسخه ۰.۱۰.۰) (نسخه ۰.۲.۰) (نسخه ۰.۱.۱)
base64.decode رشته‌ی base64 را به بایت تبدیل می‌کند. در صورت ورود اطلاعات نامعتبر، خطا می‌دهد.

امضاها:
base64.decode(string) -> bytes

مثال‌ها:
base64.decode("aGVsbG8=") // b"hello"
(نسخه ۰.۶.۰) (نسخه ۰.۱۰.۰) (نسخه ۰.۲.۰) (نسخه ۰.۱.۱)
json.encode یک مقدار CEL را به رشته JSON سریالی می‌کند.

امضاها:
json.encode(dyn) -> string

مثال‌ها:
json.encode([1, 2]) // "[1,2]"
(نسخه ۰.۲۹.۰)

نحوه فعال کردن

  • برو: تابع ext.Encoders() را به cel.NewEnv() ارسال کن.
  • سی++:
  • جاوا: CelExtensions.encoders() را به سازندگان CelCompiler و CelRuntime اضافه کنید.
  • پایتون: cel_expr_python.ext.ext_encoders را وارد کنید و ExtEncoders() در cel.NewEnv(extensions=[...]) استفاده کنید.

کتابخانه ریاضی

عملکرد توضیحات برو سی++ جاوا پایتون سی
math.greatest بزرگترین آرگومان عددی (یا لیستی از اعداد) را برمی‌گرداند.

امضاها:
math.greatest(arg, ...) -> T

مثال‌ها:
math.greatest(1, 3, 2) // 3
(نسخه ۰.۱۳.۰) (نسخه ۰.۱۰.۰) (نسخه ۰.۲.۰) (نسخه ۰.۱.۱)
math.least کمترین تعداد آرگومان‌های عددی (یا لیستی از اعداد) را برمی‌گرداند.

امضاها:
math.least(arg, ...) -> T

مثال‌ها:
math.least([1, 3, 2]) // 1
(نسخه ۰.۱۳.۰) (نسخه ۰.۱۰.۰) (نسخه ۰.۲.۰) (نسخه ۰.۱.۱)
math.abs ارزش مطلق.

امضاها:
math.abs(T) -> T ( int ، uint ، double پشتیبانی می‌کند)

مثال‌ها:
math.abs(-1) // 1
(نسخه ۰.۲۱.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱۰.۱) (نسخه ۰.۱.۱)
math.sqrt جذر.

امضاها:
math.sqrt(T) -> double ( int ، uint ، double پشتیبانی می‌کند)

مثال‌ها:
math.sqrt(9) // 3.0
(نسخه ۰.۲۵.۱) (نسخه ۰.۱۲.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱.۱)
math.bitAnd بیتی و.

امضاها:
math.bitAnd(T, T) -> T ( int و uint پشتیبانی می‌کند)

مثال‌ها:
math.bitAnd(5, 3) // 1
(نسخه ۰.۲۱.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱۰.۱) (نسخه ۰.۱.۱)
math.bitOr یای بیتی.

امضاها:
math.bitOr(T, T) -> T ( int و uint پشتیبانی می‌کند)

مثال‌ها:
math.bitOr(5, 3) // 7
(نسخه ۰.۲۱.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱۰.۱) (نسخه ۰.۱.۱)
math.bitXor XOR بیتی

امضاها:
math.bitXor(T, T) -> T ( int و uint پشتیبانی می‌کند)

مثال‌ها:
math.bitXor(5, 3) // 6
(نسخه ۰.۲۱.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱۰.۱) (نسخه ۰.۱.۱)
math.bitNot بیتی نیست.

امضاها:
math.bitNot(T) -> T ( int و uint پشتیبانی می‌کند)

مثال‌ها:
math.bitNot(1) // -2
(نسخه ۰.۲۱.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱۰.۱) (نسخه ۰.۱.۱)
math.bitShiftLeft شیفت بیتی به چپ.

امضاها:
math.bitShiftLeft(T, int) -> T ( int و uint پشتیبانی می‌کند)

مثال‌ها:
math.bitShiftLeft(1, 2) // 4
(نسخه ۰.۲۱.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱۰.۱) (نسخه ۰.۱.۱)
math.bitShiftRight شیفت بیتی به راست.

امضاها:
math.bitShiftRight(T, int) -> T ( int و uint پشتیبانی می‌کند)

مثال‌ها:
math.bitShiftRight(4, 2) // 1
(نسخه ۰.۲۱.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱۰.۱) (نسخه ۰.۱.۱)
math.ceil گرد کردن سقف.

امضاها:
math.ceil(double) -> double

مثال‌ها:
math.ceil(1.2) // 2.0
(نسخه ۰.۲۱.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱۰.۱) (نسخه ۰.۱.۱)
math.floor گرد کردن کف.

امضاها:
math.floor(double) -> double

مثال‌ها:
math.floor(1.8) // 1.0
(نسخه ۰.۲۱.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱۰.۱) (نسخه ۰.۱.۱)
math.round گرد کردن نزدیکترین عدد صحیح.

امضاها:
math.round(double) -> double

مثال‌ها:
math.round(1.5) // 2.0
(نسخه ۰.۲۱.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱۰.۱) (نسخه ۰.۱.۱)
math.trunc گرد کردن با برش (به سمت صفر).

امضاها:
math.trunc(double) -> double

مثال‌ها:
math.trunc(-1.8) // -1.0
(نسخه ۰.۲۱.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱۰.۱) (نسخه ۰.۱.۱)
math.isInf بررسی می‌کند که آیا double مثبت است یا منفی بی‌نهایت.

امضاها:
math.isInf(double) -> bool

مثال‌ها:
math.isInf(1.0/0.0) // true
(نسخه ۰.۲۱.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱۰.۱) (نسخه ۰.۱.۱)
math.isNaN بررسی می‌کند که آیا double برابر با NaN است یا خیر.

امضاها:
math.isNaN(double) -> bool

مثال‌ها:
math.isNaN(0.0/0.0) // true
(نسخه ۰.۲۱.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱۰.۱) (نسخه ۰.۱.۱)
math.isFinite بررسی می‌کند که آیا double متناهی است یا خیر.

امضاها:
math.isFinite(double) -> bool

مثال‌ها:
math.isFinite(1.2) // true
(نسخه ۰.۲۱.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱۰.۱) (نسخه ۰.۱.۱)
math.sign علامت مقدار (-1، 0، یا 1) را برمی‌گرداند.

امضاها:
math.sign(T) -> T ( int ، uint ، double پشتیبانی می‌کند)

مثال‌ها:
math.sign(-42) // -1
(نسخه ۰.۲۱.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱۰.۱) (نسخه ۰.۱.۱)

نحوه فعال کردن

  • برو: تابع ext.Math() را به cel.NewEnv() ارسال کن.
  • سی++:
  • جاوا: CelExtensions.math() را به سازندگان CelCompiler و CelRuntime اضافه کنید.
  • پایتون: cel_expr_python.ext.ext_math را وارد کنید و ExtMath() در cel.NewEnv(extensions=[...]) استفاده کنید.

کتابخانه پروتوس

عملکرد توضیحات برو سی++ جاوا پایتون سی
proto.getExt فیلد افزونه proto2 را برمی‌گرداند، یا اگر تنظیم نشده باشد، پیش‌فرض است.

امضاها:
proto.getExt(msg, extName) -> T

مثال‌ها:
proto.getExt(msg, google.api.expr.test.int32_ext)
(نسخه ۰.۱۳.۰) (نسخه ۰.۱۰.۰) (نسخه ۰.۲.۰) (نسخه ۰.۱.۱)
proto.hasExt بررسی می‌کند که آیا فیلد افزونه‌ی proto2 تنظیم شده است یا خیر.

امضاها:
proto.hasExt(msg, extName) -> bool

مثال‌ها:
proto.hasExt(msg, google.api.expr.test.int32_ext)
(نسخه ۰.۱۳.۰) (نسخه ۰.۱۰.۰) (نسخه ۰.۲.۰) (نسخه ۰.۱.۱)

نحوه فعال کردن

  • برو: ext.Protos() را به cel.NewEnv() ارسال کن.
  • ++C: اضافه کردن ProtoExtCompilerLibrary() به CompilerBuilder . (زمان اجرا به صورت خودکار مدیریت می‌شود).
  • جاوا: CelExtensions.protos() را به سازندگان CelCompiler و CelRuntime اضافه کنید.
  • پایتون: cel_expr_python.ext.ext_proto را وارد کنید و ExtProto() در cel.NewEnv(extensions=[...]) استفاده کنید.

کتابخانه لیست‌ها

عملکرد توضیحات برو سی++ جاوا پایتون سی
distinct عناصر متمایز را برمی‌گرداند.

امضاها:
list.distinct() -> list

مثال‌ها:
[1, 2, 2].distinct() // [1, 2]
(نسخه ۰.۲۲.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱.۱)
flatten لیست‌های تو در تو را مسطح می‌کند.

امضاها:
list.flatten([depth]) -> list

مثال‌ها:
[[1], [2, 3]].flatten() // [1, 2, 3]
(نسخه ۰.۲۲.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۷.۱) (نسخه ۰.۱.۱)
lists.range لیستی از اعداد صحیح [0, ..., n-1] را برمی‌گرداند.

امضاها:
lists.range(int) -> list(int)

مثال‌ها:
lists.range(3) // [0, 1, 2]
(نسخه ۰.۲۲.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱۰.۱) (نسخه ۰.۱.۱)
reverse لیست را برعکس می‌کند.

امضاها:
list.reverse() -> list

مثال‌ها:
[1, 2].reverse() // [2, 1]
(نسخه ۰.۲۲.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱.۱)
slice زیرلیست (شامل شروع، شامل پایان) را برمی‌گرداند.

امضاها:
list.slice(start, end) -> list

مثال‌ها:
[1, 2, 3].slice(1, 3) // [2, 3]
(نسخه ۰.۱۷.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱.۱)
sort فهرست عناصر قابل مقایسه را مرتب می‌کند.

امضاها:
list.sort() -> list

مثال‌ها:
[3, 1, 2].sort() // [1, 2, 3]
(نسخه ۰.۲۲.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱.۱)
sortBy لیست را بر اساس کلید ارزیابی شده از عبارت مرتب می‌کند.

امضاها:
list.sortBy(var, expr) -> list

مثال‌ها:
[{"val": 2}, {"val": 1}].sortBy(x, x.val) // [{"val": 1}, {"val": 2}]
(نسخه ۰.۲۲.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱.۱)
first عنصر اول را به عنوان اختیاری برمی‌گرداند. به افزونه‌ی Optional نیاز دارد.

امضاها:
list.first() -> optional

مثال‌ها:
[1, 2].first() // optional(1)
(نسخه ۰.۲۳.۰) (نسخه ۰.۱۵.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱.۲)
last آخرین عنصر را به عنوان اختیاری برمی‌گرداند. به افزونه‌ی Optional نیاز دارد.

امضاها:
list.last() -> optional

مثال‌ها:
[1, 2].last() // optional(2)
(نسخه ۰.۲۳.۰) (نسخه ۰.۱۵.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱.۲)

نحوه فعال کردن

  • برو: تابع ext.Lists() را به cel.NewEnv() ارسال کن.
  • سی++:
  • جاوا: CelExtensions.lists() را به سازندگان CelCompiler و CelRuntime اضافه کنید.
  • پایتون: با افزودن lists به فهرست extensions ، از طریق cel.EnvConfig فعال کنید.

کتابخانه مجموعه‌ها

عملکرد توضیحات برو سی++ جاوا پایتون سی
sets.contains بررسی می‌کند که آیا list1 شامل تمام عناصر list2 است یا خیر.

امضاها:
sets.contains(list1, list2) -> bool

مثال‌ها:
sets.contains([1, 2], [1]) // true
(نسخه ۰.۱۵.۰) (نسخه ۰.۱۰.۰) (نسخه ۰.۶.۰) (نسخه ۰.۱.۱)
sets.equivalent بررسی می‌کند که آیا لیست‌ها معادل مجموعه هستند (شامل عناصر منحصر به فرد یکسان هستند).

امضاها:
sets.equivalent(list1, list2) -> bool

مثال‌ها:
sets.equivalent([1, 2], [2, 1, 1]) // true
(نسخه ۰.۱۵.۰) (نسخه ۰.۱۰.۰) (نسخه ۰.۶.۰) (نسخه ۰.۱.۱)
sets.intersects بررسی می‌کند که آیا لیست‌ها حداقل یک عنصر مشترک دارند یا خیر.

امضاها:
sets.intersects(list1, list2) -> bool

مثال‌ها:
sets.intersects([1, 2], [2, 3]) // true
(نسخه ۰.۱۵.۰) (نسخه ۰.۱۰.۰) (نسخه ۰.۶.۰) (نسخه ۰.۱.۱)

نحوه فعال کردن

  • برو: تابع ext.Sets() را به cel.NewEnv() ارسال کن.
  • سی++:
  • جاوا: CelExtensions.sets() را به سازندگان CelCompiler و CelRuntime اضافه کنید.
  • پایتون: با افزودن sets به لیست extensions ، از طریق cel.EnvConfig فعال کنید.

کتابخانه رشته‌ها

عملکرد توضیحات برو سی++ جاوا پایتون سی
charAt کاراکتر را در اندیس برمی‌گرداند.

امضاها:
string.charAt(int) -> string

مثال‌ها:
"hello".charAt(1) // "e"
(نسخه ۰.۴.۰) (نسخه ۰.۱۰.۰) (نسخه ۰.۲.۰) (نسخه ۰.۱.۱)
indexOf اندیس اولین وقوع زیررشته یا -۱ را برمی‌گرداند.

امضاها:
string.indexOf(substr, [start]) -> int

مثال‌ها:
"hello".indexOf("l") // 2
(نسخه ۰.۴.۰) (نسخه ۰.۱۰.۰) (نسخه ۰.۲.۰) (نسخه ۰.۱.۱)
lastIndexOf اندیس آخرین وقوع زیررشته یا -۱ را برمی‌گرداند.

امضاها:
string.lastIndexOf(substr, [end]) -> int

مثال‌ها:
"hello".lastIndexOf("l") // 3
(نسخه ۰.۴.۰) (نسخه ۰.۱۰.۰) (نسخه ۰.۲.۰) (نسخه ۰.۱.۱)
join رشته‌ها را به هم متصل می‌کند.

امضاها:
list(string).join([separator]) -> string

مثال‌ها:
["a", "b"].join("-") // "ab"
(نسخه ۰.۱۰.۰) (نسخه ۰.۱۰.۰) (نسخه ۰.۲.۰) (نسخه ۰.۱.۱)
split رشته را با استفاده از جداکننده تقسیم می‌کند.

امضاها:
string.split(separator, [limit]) -> list(string)

مثال‌ها:
"ab".split("-") // ["a", "b"]
(نسخه ۰.۴.۰) (نسخه ۰.۱۰.۰) (نسخه ۰.۲.۰) (نسخه ۰.۱.۱)
substring زیررشته (شامل شروع، شامل پایان) را برمی‌گرداند.

امضاها:
string.substring(start, [end]) -> string

مثال‌ها:
"hello".substring(1, 3) // "el"
(نسخه ۰.۴.۰) (نسخه ۰.۱۰.۰) (نسخه ۰.۲.۰) (نسخه ۰.۱.۱)
trim فاصله‌های خالی یونیکد را حذف می‌کند.

امضاها:
string.trim() -> string

مثال‌ها:
" hello ".trim() // "hello"
(نسخه ۰.۴.۰) (نسخه ۰.۱۰.۰) (نسخه ۰.۲.۰) (نسخه ۰.۱.۱)
replace موارد قدیمی را با موارد جدید جایگزین می‌کند.

امضاها:
string.replace(old, new, [limit]) -> string

مثال‌ها:
"hello".replace("l", "w") // "hewwo"
(نسخه ۰.۴.۰) (نسخه ۰.۱۰.۰) (نسخه ۰.۲.۰) (نسخه ۰.۱.۱)
reverse نقاط کد یونیکد را معکوس می‌کند.

امضاها:
string.reverse() -> string

مثال‌ها:
"abc".reverse() // "cba"
(نسخه ۰.۱۸.۰) (نسخه ۰.۱۴.۰) (نسخه ۰.۱۳.۰) (نسخه ۰.۱.۱)
lowerAscii کاراکترهای ASCII را به حروف کوچک تبدیل می‌کند.

امضاها:
string.lowerAscii() -> string

مثال‌ها:
"Hello".lowerAscii() // "hello"
(نسخه ۰.۶.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۲.۰) (نسخه ۰.۱.۱)
upperAscii کاراکترهای ASCII را به حروف بزرگ تبدیل می‌کند.

امضاها:
string.upperAscii() -> string

مثال‌ها:
"Hello".upperAscii() // "HELLO"
(نسخه ۰.۶.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۲.۰) (نسخه ۰.۱.۱)
quote رشته را برای چاپ ایمن escape می‌کند.

امضاها:
strings.quote(string) -> string

مثال‌ها:
strings.quote("a\tb") // "\"a\\tb\""
(نسخه ۰.۱۴.۰) (نسخه ۰.۱۴.۰) (نسخه ۰.۱۳.۰) (نسخه ۰.۱.۱)
format رشته را با استفاده از متغیرهایی به سبک printf قالب‌بندی می‌کند.

امضاها:
string.format(list) -> string

مثال‌ها:
"str: %s, int: %d".format(["a", 1]) // "str: a, int: 1"
(نسخه ۰.۱۴.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱.۱)

نحوه فعال کردن

  • برو: تابع ext.Strings() را به cel.NewEnv() ارسال کن.
  • سی++:
  • جاوا: CelExtensions.strings() را به سازندگان CelCompiler و CelRuntime اضافه کنید.
  • پایتون: cel_expr_python.ext.ext_strings وارد کنید و ExtStrings() در cel.NewEnv(extensions=[...]) استفاده کنید.

کتابخانه عبارات منظم

عملکرد توضیحات برو سی++ جاوا پایتون سی
regex.replace موارد منطبق را با رشته جایگزین جایگزین می‌کند (از ارجاعات معکوس پشتیبانی می‌کند).

امضاها:
regex.replace(target, pat, repl, [limit]) -> string

مثال‌ها:
regex.replace("123-456", r"(\d+)-(\d+)", r"\2-\1") // "456-123"
(نسخه ۰.۲۵.۱) (نسخه ۰.۱۳.۰) (نسخه ۰.۱۰.۱) (نسخه ۰.۱.۱)
regex.extract اولین تطابق الگو را برمی‌گرداند (باید یک گروه ضبط داشته باشد).

امضاها:
regex.extract(target, pat) -> optional(string)

مثال‌ها:
regex.extract("a123b", r"(\d+)") // optional("123")
(نسخه ۰.۲۵.۱) (نسخه ۰.۱۳.۰) (نسخه ۰.۱۰.۱) (نسخه ۰.۱.۱)
regex.extractAll تمام تطابق‌های الگو را برمی‌گرداند (باید یک گروه ضبط داشته باشد).

امضاها:
regex.extractAll(target, pat) -> list(string)

مثال‌ها:
regex.extractAll("a1b2", r"(\d+)") // ["1", "2"]
(نسخه ۰.۲۵.۱) (نسخه ۰.۱۳.۰) (نسخه ۰.۱۰.۱) (نسخه ۰.۱.۱)

نحوه فعال کردن

  • برو: تابع ext.Regex() را به cel.NewEnv() ارسال کن.
  • سی++:
  • جاوا: CelExtensions.regex() را به سازندگان CelCompiler و CelRuntime اضافه کنید.
  • پایتون: با افزودن regex و optional به لیست extensions ، از طریق cel.EnvConfig فعال کنید.

درک مفاهیم دو متغیره

ماکرو توضیحات برو سی++ جاوا پایتون سی
all اتصال کوتاه منطقی AND روی کلید/شاخص و مقدار.

امضاها:
list.all(i, v, pred) -> bool
map.all(k, v, pred) -> bool

مثال‌ها:
[1, 2].all(i, v, v > 0) // true
(نسخه ۰.۲۲.۰) (نسخه ۰.۱۴.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱.۱)
exists اتصال کوتاه OR منطقی روی کلید/شاخص و مقدار.

امضاها:
list.exists(i, v, pred) -> bool
map.exists(k, v, pred) -> bool

مثال‌ها:
[1, 2].exists(i, v, v == 2) // true
(نسخه ۰.۲۲.۰) (نسخه ۰.۱۴.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱.۱)
existsOne بررسی می‌کند که آیا دقیقاً یک جفت، گزاره را ارضا می‌کند یا خیر.

امضاها:
list.existsOne(i, v, pred) -> bool
map.existsOne(k, v, pred) -> bool

مثال‌ها:
[1, 2].existsOne(i, v, v == 2) // true
(نسخه ۰.۲۲.۰) (نسخه ۰.۱۴.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱.۱)
transformList لیست/نقشه را به یک لیست تبدیل/فیلتر می‌کند.

امضاها:
list.transformList(i, v, [filter], transform) -> list
map.transformList(k, v, [filter], transform) -> list

مثال‌ها:
[1, 2].transformList(i, v, v * 2) // [2, 4]
(نسخه ۰.۲۲.۰) (نسخه ۰.۱۴.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱.۱)
transformMap مقادیر لیست/نقشه را به یک نقشه تبدیل می‌کند (کلیدها ثابت می‌مانند).

امضاها:
list.transformMap(i, v, [filter], transform) -> map
map.transformMap(k, v, [filter], transform) -> map

مثال‌ها:
[1, 2].transformMap(i, v, v * 2) // {0: 2, 1: 4}
(نسخه ۰.۲۲.۰) (نسخه ۰.۱۴.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱.۱)
transformMapEntry تبدیل به نقشه می‌شود.

امضاها:
list.transformMapEntry(i, v, [filter], transform_entry) -> map
map.transformMapEntry(k, v, [filter], transform_entry) -> map

مثال‌ها:
[1, 2].transformMapEntry(i, v, {string(v): v * 2}) // {"1": 2, "2": 4}
(نسخه ۰.۲۲.۰) (نسخه ۰.۱۴.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱.۱)

نحوه فعال کردن

کتابخانه انواع بومی

ویژگی توضیحات برو سی++ جاوا پایتون سی
سازه‌های بومی ثبت و نمونه‌سازی انواع بومی میزبان (ساختارهای Go / POJOهای جاوا) در CEL.

مثال‌ها:
Account{id: 123} (جاوا POJO در CEL نمونه‌سازی شده است)
(نسخه ۰.۱۳.۰) (نسخه ۰.۱۳.۰)

نحوه فعال کردن

  • برو: cel.NativeTypes(...) یا ext.NativeTypes(...) (با ارائه انواع منعکس کننده) را به cel.NewEnv() ارسال کن.
  • سی پلاس پلاس: پشتیبانی نمی‌شود.
  • جاوا: CelExtensions.nativeTypes() (که کلاس‌های جاوا را ارائه می‌دهد) را به سازندگان CelCompiler و CelRuntime اضافه کنید.
  • پایتون: پشتیبانی نمی‌شود.

کتابخانه شبکه

کتابخانه شبکه توابعی را برای تجزیه، اعتبارسنجی و دستکاری آدرس‌های IP و بلوک‌های CIDR ارائه می‌دهد.

عملکرد توضیحات برو سی++ جاوا پایتون سی
ip یک رشته را به آدرس IP تجزیه می‌کند، یا IP را از CIDR استخراج می‌کند.

امضاها:
ip(string) -> IP
CIDR.ip() -> IP

مثال‌ها:
ip("192.168.0.1")
cidr("192.168.0.0/24").ip()
(نسخه ۰.۲۹.۰)
isIP بررسی می‌کند که آیا یک رشته، یک آدرس IP معتبر است یا خیر.

امضاها:
isIP(string) -> bool

مثال‌ها:
isIP("192.168.0.1") // true
(نسخه ۰.۲۹.۰)
ip.isCanonical بررسی می‌کند که آیا یک رشته آدرس IP در قالب متعارف خود قرار دارد یا خیر.

امضاها:
ip.isCanonical(string) -> bool

مثال‌ها:
ip.isCanonical("192.168.0.1") // true
(نسخه ۰.۲۹.۰)
cidr یک رشته را به یک بلوک CIDR تجزیه می‌کند.

امضاها:
cidr(string) -> CIDR

مثال‌ها:
cidr("192.168.0.0/24")
(نسخه ۰.۲۹.۰)
isCIDR بررسی می‌کند که آیا یک رشته، یک بلوک CIDR معتبر است یا خیر.

امضاها:
isCIDR(string) -> bool

مثال‌ها:
isCIDR("192.168.0.0/24") // true
(نسخه ۰.۲۹.۰)
containsIP بررسی می‌کند که آیا یک بلوک CIDR حاوی آدرس IP است یا خیر.

امضاها:
CIDR.containsIP(IP) -> bool
CIDR.containsIP(string) -> bool

مثال‌ها:
cidr("192.168.0.0/24").containsIP(ip("192.168.0.1")) // true
(نسخه ۰.۲۹.۰)
containsCIDR بررسی می‌کند که آیا یک بلوک CIDR حاوی بلوک CIDR دیگری است یا خیر.

امضاها:
CIDR.containsCIDR(CIDR) -> bool
CIDR.containsCIDR(string) -> bool

مثال‌ها:
cidr("192.168.0.0/16").containsCIDR(cidr("192.168.1.0/24")) // true
(نسخه ۰.۲۹.۰)
family خانواده IP را برمی‌گرداند (۴ برای IPv4، ۶ برای IPv6).

امضاها:
IP.family() -> int

مثال‌ها:
ip("192.168.0.1").family() // 4
(نسخه ۰.۲۹.۰)
isGlobalUnicast بررسی می‌کند که آیا IP یک آدرس یونی‌کَست سراسری است یا خیر.

امضاها:
IP.isGlobalUnicast() -> bool

مثال‌ها:
ip("192.168.0.1").isGlobalUnicast() // true
(نسخه ۰.۲۹.۰)
isLinkLocalMulticast بررسی می‌کند که آیا IP یک آدرس چندپخشی لینک-محلی است یا خیر.

امضاها:
IP.isLinkLocalMulticast() -> bool

مثال‌ها:
ip("224.0.0.1").isLinkLocalMulticast() // true
(نسخه ۰.۲۹.۰)
isLinkLocalUnicast بررسی می‌کند که آیا IP یک آدرس تک پخشی لینک-لوکال است یا خیر.

امضاها:
IP.isLinkLocalUnicast() -> bool

مثال‌ها:
ip("169.254.0.1").isLinkLocalUnicast() // true
(نسخه ۰.۲۹.۰)
isLoopback بررسی می‌کند که آیا IP یک آدرس loopback است یا خیر.

امضاها:
IP.isLoopback() -> bool

مثال‌ها:
ip("127.0.0.1").isLoopback() // true
(نسخه ۰.۲۹.۰)
isMask بررسی می‌کند که آیا CIDR یک subnet mask معتبر است یا خیر.

امضاها:
CIDR.isMask() -> bool

مثال‌ها:
cidr("255.255.255.0/24").isMask() // true
(نسخه ۰.۲۹.۰)
isUnspecified بررسی می‌کند که آیا IP یک آدرس نامشخص است یا خیر (مثلاً 0.0.0.0 ).

امضاها:
IP.isUnspecified() -> bool

مثال‌ها:
ip("0.0.0.0").isUnspecified() // true
(نسخه ۰.۲۹.۰)
masked بلوک CIDR ماسک‌شده را برمی‌گرداند.

امضاها:
CIDR.masked() -> CIDR

مثال‌ها:
cidr("192.168.0.1/24").masked() // 192.168.0.0/24
(نسخه ۰.۲۹.۰)
prefixLength طول پیشوند بلوک CIDR را برمی‌گرداند.

امضاها:
CIDR.prefixLength() -> int

مثال‌ها:
cidr("192.168.0.0/24").prefixLength() // 24
(نسخه ۰.۲۹.۰)
string IP یا CIDR را به رشته تبدیل می‌کند.

امضاها:
string(IP) -> string
string(CIDR) -> string

مثال‌ها:
string(ip("192.168.0.1")) // "192.168.0.1"
(نسخه ۰.۲۹.۰)

نحوه فعال کردن

  • برو: تابع ext.Network() را به cel.NewEnv() ارسال کن.
  • سی پلاس پلاس: پشتیبانی نمی‌شود.
  • جاوا: پشتیبانی نمی‌شود.
  • پایتون: پشتیبانی نمی‌شود.

کتابخانه JWT

کتابخانه JWT انواع داده و توابع کمکی را برای تجزیه توکن‌های وب JSON (JWT) و بررسی ادعاهای استاندارد و سفارشی ارائه می‌دهد.

عملکرد توضیحات برو سی++ جاوا پایتون سی
jwt.parse یک رشته توکن خام را به یک jwt.Token ساختاریافته که در یک optional پیچیده شده است، تجزیه می‌کند.

امضاها:
jwt.parse(string) -> optional(jwt.Token)

مثال‌ها:
jwt.parse(token_string).hasValue()
(نسخه ۰.۳۲.۰)
claim یک مقدار ادعای سفارشی را بر اساس نام کلید از payload توکن جستجو می‌کند.

امضاها:
jwt.Token.claim(string) -> optional(dyn)
optional(jwt.Token).claim(string) -> optional(dyn)

مثال‌ها:
jwt.parse(token).claim("tenant").orValue("")
(نسخه ۰.۳۲.۰)
presentedBy تأیید می‌کند که صادرکننده و مخاطب توکن با مقادیر مورد انتظار مطابقت دارند.

امضاها:
jwt.Token.presentedBy(string, string) -> bool
optional(jwt.Token).presentedBy(string, string) -> bool

مثال‌ها:
jwt.parse(token).presentedBy("https://auth.example.com", "https://api.example.com")
(نسخه ۰.۳۲.۰)

نحوه فعال کردن

  • برو: cel.dev/cel-go/ext/security/jwt را وارد کن و jwt.Library() را به cel.NewEnv() منتقل کن.
  • سی پلاس پلاس: پشتیبانی نمی‌شود.
  • جاوا: پشتیبانی نمی‌شود.
  • پایتون: پشتیبانی نمی‌شود.

کتابخانه HMAC

کتابخانه HMAC توابع رمزنگاری را برای محاسبه و تأیید کدهای تأیید هویت پیام مبتنی بر هش (HMAC) روی رشته‌ها و توالی‌های بایت ارائه می‌دهد.

عملکرد توضیحات برو سی++ جاوا پایتون سی
hmac.compute بایت‌های امضای خام HMAC را با استفاده از الگوریتم و کلید مخفی مشخص شده محاسبه می‌کند.

امضاها:
hmac.compute(string, string|bytes, string|bytes) -> bytes

مثال‌ها:
hmac.compute(hmac.SHA256, "secret", "message")
(نسخه ۰.۳۲.۰)
hmac.verify تأیید می‌کند که آیا امضای HMAC با خلاصه مورد انتظار مطابقت دارد یا خیر.

امضاها:
hmac.verify(string, string|bytes, string|bytes, string|bytes) -> bool

مثال‌ها:
hmac.verify(hmac.SHA256, secret, msg, expected_sig) // true
(نسخه ۰.۳۲.۰)

نحوه فعال کردن

  • برو: cel.dev/cel-go/ext/security/hmac را وارد کنید و hmac.Library() را به cel.NewEnv() منتقل کنید.
  • سی پلاس پلاس: پشتیبانی نمی‌شود.
  • جاوا: پشتیبانی نمی‌شود.
  • پایتون: پشتیبانی نمی‌شود.

۵. ویژگی‌های پیشرفته

خلاصه ویژگی‌های پیشرفته

ویژگی توضیحات برو سی++ جاوا پایتون سی
ارزیابی جزئی با ورودی‌های ناموجود ارزیابی کنید؛ مقادیر مجهول یا یک عبارت ساده‌شده را برمی‌گرداند. ³
ارزیابی ناهمزمان اجرای همزمان توابع افزونه بدون انسداد. ✓⁶
اعتبارسنج‌های AST تحلیل استاتیک پس از بررسی نوع، AST بررسی‌شده را بررسی می‌کند.
بهینه‌سازهای AST بازنویسی‌های AST (تا کردن مداوم، درون‌خطی کردن، CSE) برای بهبود عملکرد.
کامپایلر سیاست CEL ساختارهای سیاست مبتنی بر YAML را در ASTهای استاندارد CEL کامپایل می‌کند.
تأیید رسمی ثابت‌های ایمنی، ارضاپذیری، اعتبار و هم‌ارزی AST را اثبات می‌کند. (نسخه ۰.۱۴.۰)

³ زبان Go از تولید یک AST باقیمانده (AST هرس شده) پشتیبانی می‌کند. ⁴ زبان‌های C++ و Java از برگرداندن UnknownSet / CelUnknownSet در زمان اجرا پشتیبانی می‌کنند، اما APIهای عمومی را برای تولید AST باقیمانده در معرض نمایش قرار نمی‌دهند. ⁵ زبان Go از کانال‌های برگشتی AsyncBinding / AsyncOp استفاده می‌کند. ⁶ زبان جاوا CelAsyncRuntime برای برگرداندن ListenableFuture استفاده می‌کند.

ارزیابی جزئی (نامشخص‌ها)

ارزیابی جزئی امکان ارزیابی یک عبارت را زمانی فراهم می‌کند که فقط زیرمجموعه‌ای از متغیرهای ورودی (آرگومان‌ها) شناخته شده باشند. به جای شکست، ارزیابی نتیجه‌ای را تولید می‌کند که نشان می‌دهد چه چیزی از قلم افتاده است، یا یک عبارت ساده شده.

  • Go: پشتیبانی کامل. امکان تعریف یک PartialActivation با الگوهایی از ویژگی‌های ناشناخته را فراهم می‌کند. ارزیابی مقدار types.Unknown را برمی‌گرداند. Go از تولید یک AST باقیمانده ( Env.ResidualAst ) پشتیبانی می‌کند که یک AST هرس شده و ساده شده است که فقط شامل بخش‌هایی از عبارت است که نمی‌توانند ارزیابی شوند.
  • ++C: از مقادیر Unknown پشتیبانی می‌کند. الگوهای ویژگی ناشناخته از طریق Activation::set_unknown_attribute_patterns پیکربندی می‌شوند. ارزیابی یک UnknownSet را برمی‌گرداند. API عمومی در حال حاضر نسل AST باقیمانده را در معرض نمایش قرار نمی‌دهد.
  • جاوا: از ارزیابی جزئی از طریق PartialVars ارسال شده به Program.eval() پشتیبانی می‌کند. ارزیابی یک CelUnknownSet برمی‌گرداند. API عمومی در حال حاضر نسل AST باقیمانده را افشا نمی‌کند.
  • پایتون / سی: پشتیبانی بومی ندارد.

ارزیابی ناهمزمان

ارزیابی ناهمگام به عبارات CEL اجازه می‌دهد تا توابعی را که به صورت ناهمگام اجرا می‌شوند (مثلاً ایجاد RPC یا پرس‌وجوهای پایگاه داده) فراخوانی کنند و ارزیابی را تا زمان در دسترس بودن نتایج مسدود کنند، بدون اینکه نخ اجرای اصلی مسدود شود.

  • Go: از سربارگذاری توابع غیرهمزمان از طریق AsyncBinding و AsyncOp پشتیبانی می‌کند. توابع غیرهمزمان یک کانال Go ( <-chan ref.Val ) برمی‌گردانند و مفسر، اجرای همزمان و همگام‌سازی را مدیریت می‌کند.
  • جاوا: از ارزیابی غیرهمزمان (async) از طریق CelAsyncRuntime و AsyncProgram پشتیبانی می‌کند. از ListenableFuture برای نمایش مقادیر در حال انتظار استفاده می‌کند و به طور خودکار ارزیابی را به سمت تکمیل همزمان با حل و فصل آینده هدایت می‌کند.
  • سی‌پلاس‌پلاس / پایتون / سی: پشتیبانی داخلی ندارد.

اعتبارسنج‌های AST

اعتبارسنج‌ها پس از بررسی نوع، تحلیل استاتیکی روی Checked AST انجام می‌دهند تا محدودیت‌های خاص دامنه را قبل از اجرای برنامه اعمال کنند.

  • Go: از رابط ASTValidator پشتیبانی می‌کند. اعتبارسنج‌های متعارف شامل cel.validator.duration ، cel.validator.timestamp ، cel.validator.matches (regex)، cel.validator.homogeneous_literals و cel.validator.comprehension_nesting_limit هستند.
  • ++C: از cel::Validator پشتیبانی می‌کند. اعتبارسنجی‌های متعارف شامل AstDepthValidator ، ComprehensionNestingLimitValidator ، DurationLiteralValidator ، HomogeneousLiteralValidator ، MatchesValidator و TimestampLiteralValidator می‌شوند.
  • جاوا: CelValidator و CelAstValidator پشتیبانی می‌کند. اعتبارسنج‌های متعارف شامل AstDepthLimitValidator ، ComprehensionNestingLimitValidator ، DurationLiteralValidator ، HomogeneousLiteralValidator ، RegexLiteralValidator و TimestampLiteralValidator هستند.
  • پایتون / سی: پشتیبانی مستقیمی وجود ندارد.

بهینه‌سازهای AST

بهینه‌سازها AST را برای بهبود عملکرد اجرا بازنویسی می‌کنند. بهینه‌سازها در یکی از دو دسته قرار می‌گیرند: بهینه‌سازهای ایستا و زمان اجرا. ++C، جاوا و Go از بهینه‌سازی زمان اجرا پشتیبانی می‌کنند. CEL جاوا و Go نیز از بهینه‌سازهای ایستا پشتیبانی می‌کنند.

بهینه‌سازی‌های معمول شامل تاخوردگی ثابت (پیش‌ارزیابی زیرعبارات با ورودی‌های ثابت) و حذف زیرعبارات مشترک (CSE) می‌شوند.

  • Go: از تا کردن AST در حین کامپایل/برنامه‌ریزی پشتیبانی می‌کند.
  • سی پلاس پلاس: از تا شدن مداوم (constant folding) از طریق افزونه‌ی cel::extensions::EnableConstantFolding در زمان برنامه‌ریزی پشتیبانی می‌کند.
  • جاوا: از رابط CelOptimizer پشتیبانی می‌کند. بهینه‌سازهای متعارف شامل ConstantFoldingOptimizer (که از پیمایش پیش‌ترتیب، تا کردن ثابت پیام در Protobuf و هرس کردن تجمعی یا اختیاری پشتیبانی می‌کند)، InliningOptimizer و SubexpressionOptimizer (CSE) هستند.
  • پایتون / سی: پشتیبانی مستقیمی وجود ندارد.

کامپایلر سیاست CEL

سیاست CEL یک قالب مبتنی بر YAML برای ترکیب چندین عبارت CEL به همراه متغیرها، بلوک‌های تطبیق، خروجی‌های شرطی و قوانین تو در تو است. این سیاست برای موتورهای سیاست پیچیده (مانند کنترل پذیرش Kubernetes) طراحی شده است که در آنها عبارات CEL منفرد غیرقابل خواندن می‌شوند.

برای تعریف رسمی زبان، نحو و مجموعه انطباق، به مشخصات سیاست CEL مراجعه کنید.

کامپایلر سیاست، این سیاست‌های YAML را در یک استاندارد واحد CEL AST کامپایل می‌کند، به این معنی که آنها کاملاً با زمان‌های اجرای استاندارد CEL سازگار هستند و تمام ضمانت‌های عملکرد و ایمنی را به ارث می‌برند.

  • برو: از طریق سیاست Go پشتیبانی می‌شود (شامل معانی ارزیابی قوانین کلی).
  • سی++: از طریق خط‌مشی سی++ پشتیبانی می‌شود.
  • جاوا: از طریق سیاست جاوا پشتیبانی می‌شود (شامل معانی ارزیابی قوانین کلی و مشخص‌کننده‌های نوع مختصر در پیکربندی‌های سیاست).
  • پایتون / سی: مستقیماً پشتیبانی نمی‌شود.

چارچوب تأیید رسمی

چارچوب تأیید رسمی به کاربران اجازه می‌دهد تا به صورت ریاضی، ثابت‌های ایمنی، هم‌ارزی منطقی، قابلیت اطمینان و اعتبار را در عبارات CEL و سیاست‌های ساختاریافته CEL اثبات کنند.

  • جاوا: از طریق تأییدکننده جاوا CEL ( dev.cel:verifier و dev.cel:verifier-cli ) پشتیبانی می‌شود. قابلیت‌ها شامل رضایت‌بخشی ( isSatisfiable ) با تولید ورودی شاهد، اعتبارسنجی ( isAlwaysTrue ) با تولید مثال نقض، بررسی مدل محدود (BMC) برای درک، اثبات‌های هم‌ارزی منطقی در ASTها و تأیید ثابت بودن سیاست assume / assert سفارشی است.
  • Go / C++ / Python / C: به طور غیرمستقیم از طریق ابزار خط فرمان جاوا پشتیبانی می‌شوند.

برای مقدمه و مثال‌های دنیای واقعی، به پست وبلاگ منبع باز گوگل با عنوان « ایمن‌سازی دوران عاملیت: معرفی تأیید رسمی برای CEL» مراجعه کنید.

،

این سند به عنوان مرجع یکپارچه API Doc برای زبان عبارات مشترک (CEL) عمل می‌کند. این سند تمام ماکروها، عملگرها و توابع استاندارد را فهرست می‌کند و امضاها، رفتارها و وضعیت پشتیبانی آنها را در پشته‌های رسمی CEL نشان می‌دهد.

برای جزئیات بیشتر در مورد رفتار و مشخصات زبان، به تعریف زبان CEL مراجعه کنید.

نسخه‌های پشته‌ای

این سند مرجع بر اساس نسخه‌های زیر از پشته‌های CEL تهیه شده است:

  • CEL Go : v0.32.0 (و جدیدتر)
  • سل سی++ : v0.16.1
  • جاوا CEL : v0.14.0
  • زبان برنامه‌نویسی پایتون (CEL) : v0.1.3
  • CEL C : تصویر لحظه‌ای از توسعه (منتشر نشده)

آینه‌های گیت‌هاب

پیاده‌سازی‌های رسمی CEL در GitHub تحت سازمان cel-expr منعکس شده‌اند:


۱. ماکروهای اصلی

اینها ماکروهای داخلی هستند که در زمان کامپایل گسترش می‌یابند.

ماکرو توضیحات برو سی++ جاوا پایتون سی
has(container.field) بررسی می‌کند که آیا یک فیلد در یک پیام یا یک کلید در یک نقشه وجود دارد یا خیر.

امضاها:
has(container.field) -> bool

مثال‌ها:
has(request.auth.claims.email)
list.all(var, predicate) بررسی می‌کند که آیا همه عناصر موجود در یک لیست، یک گزاره را برآورده می‌کنند یا خیر.

امضاها:
list.all(var, predicate) -> bool

مثال‌ها:
[1, 2, 3].all(x, x > 0) // true
¹
list.exists(var, predicate) بررسی می‌کند که آیا حداقل یک عنصر در یک لیست، یک گزاره را برآورده می‌کند یا خیر.

امضاها:
list.exists(var, predicate) -> bool

مثال‌ها:
[1, 2, 3].exists(x, x > 2) // true
¹
list.exists_one(var, predicate) بررسی می‌کند که آیا دقیقاً یک عنصر در یک لیست، یک گزاره را برآورده می‌کند یا خیر.

امضاها:
list.exists_one(var, predicate) -> bool

مثال‌ها:
[1, 2, 3].exists_one(x, x == 2) // true
¹
list.filter(var, predicate) عناصر یک لیست را بر اساس یک گزاره فیلتر می‌کند.

امضاها:
list.filter(var, predicate) -> list

مثال‌ها:
[1, 2, 3].filter(x, x > 1) // [2, 3]
¹
list.map(var, transform) هر عنصر یک لیست را با استفاده از یک عبارت تبدیل می‌کند.

امضاها:
list.map(var, transform) -> list

مثال‌ها:
[1, 2, 3].map(x, x * 2) // [2, 4, 6]
¹
list.map(var, filter, transform) عناصری از یک لیست را که در گزاره فیلتر صدق می‌کنند، تبدیل می‌کند.

امضاها:
list.map(var, filter, transform) -> list

مثال‌ها:
[1, 2, 3].map(x, x > 1, x * 2) // [4, 6]
¹

¹ در زمان اجرای C پشتیبانی می‌شود زیرا ماکروها در حین کامپایل توسط کامپایلر میزبان به درک متقابل گسترش می‌یابند.


۲. اپراتورهای اصلی

اپراتور توضیحات برو سی++ جاوا پایتون سی
محاسبات ( + ، - ، * ، / ، % ) عملیات حسابی استاندارد. نفی ( -x ) و هویت ( +x ). الحاق لیست ( list + list ) در Go، C++، Java و Python پشتیبانی می‌شود.

امضاها:
T + T -> T
T - T -> T
T * T -> T
T / T -> T
T % T -> T
-T -> T
+T -> T
list + list -> list

مثال‌ها:
1 + 2 * 3 // 7
[1] + [2] // [1, 2]
²
مقایسه ( == ، != ، < ، <= ، > ، >= ) مقایسه استاندارد. مقایسه‌های عددی ناهمگن هستند (مثلاً 1 == 1.0 ).

امضاها:
T == T -> bool
T != T -> bool
T < T -> bool
T <= T -> bool
T > T -> bool
T >= T -> bool

مثال‌ها:
x < 42.0
1 == 1.0 // true
منطقی ( ! ، && ، || ، ? : :) توابع منطقی NOT، AND، OR و شرطی سه‌تایی. AND/OR از ارزیابی اتصال کوتاه استفاده می‌کنند.

امضاها:
!bool -> bool
bool && bool -> bool
bool || bool -> bool
bool ? T : T -> T

مثال‌ها:
x > 0 ? "positive" : "non-positive"
فهرست بندی ( [] ) دسترسی به عنصر یک لیست از طریق اندیس یا کلید جستجو در نقشه.

امضاها:
list[int] -> T
map[K] -> V

مثال‌ها:
tags[0]
users['john']
عضویت ( in ) بررسی می‌کند که آیا عنصر در یک لیست است یا کلید در یک نقشه قرار دارد.

امضاها:
T in list -> bool
K in map -> bool

مثال‌ها:
'admin' in roles

² الحاق لیست ( list + list ) در زمان اجرای C پشتیبانی نمی‌شود ، اگرچه سایر عملگرهای حسابی پشتیبانی می‌شوند.


۳. کارکردهای اصلی

توابع عمومی و رشته‌ای

عملکرد توضیحات برو سی++ جاوا پایتون سی
size اندازه یک رشته (کاراکتر)، بایت، لیست یا نقشه را برمی‌گرداند.

امضاها:
size(T) -> int (که در آن T می‌تواند string ، bytes ، list یا map باشد)

مثال‌ها:
size("hello") // 5
contains برمی‌گرداند که آیا رشته شامل زیررشته است یا خیر.

امضاها:
string.contains(string) -> bool

مثال‌ها:
"hello".contains("ell") // true
startsWith برمی‌گرداند که آیا رشته با پیشوند شروع می‌شود یا خیر.

امضاها:
string.startsWith(string) -> bool

مثال‌ها:
"hello".startsWith("he") // true
endsWith برمی‌گرداند که آیا رشته با پسوند به پایان می‌رسد یا خیر.

امضاها:
string.endsWith(string) -> bool

مثال‌ها:
"hello".endsWith("lo") // true
matches برمی‌گرداند که آیا رشته با عبارت منظم RE2 مطابقت دارد یا خیر.

امضاها:
string.matches(string) -> bool

مثال‌ها:
"123".matches(r"^\d+$") // true

توابع انتخابگر تاریخ و زمان

این توابع، کامپوننت‌ها را از google.protobuf.Timestamp یا google.protobuf.Duration استخراج می‌کنند.

عملکرد توضیحات برو سی++ جاوا پایتون سی
getFullYear سال را به صورت ۴ رقمی برمی‌گرداند.

امضاها:
timestamp.getFullYear([tz]) -> int

مثال‌ها:
timestamp("2026-07-23T00:00:00Z").getFullYear() // 2026
getMonth ماه (0-11) را برمی‌گرداند.

امضاها:
timestamp.getMonth([tz]) -> int

مثال‌ها:
timestamp("2026-07-23T00:00:00Z").getMonth() // 6
getDayOfMonth روز ماه (۱-۳۱) را برمی‌گرداند.

امضاها:
timestamp.getDayOfMonth([tz]) -> int

مثال‌ها:
timestamp("2026-07-23T00:00:00Z").getDayOfMonth() // 23
getDayOfWeek روز هفته را برمی‌گرداند (0 = یکشنبه).

امضاها:
timestamp.getDayOfWeek([tz]) -> int

مثال‌ها:
timestamp("2026-07-23T00:00:00Z").getDayOfWeek() // 4
getDayOfYear روز سال (0-365) را برمی‌گرداند.

امضاها:
timestamp.getDayOfYear([tz]) -> int

مثال‌ها:
timestamp("2026-07-23T00:00:00Z").getDayOfYear() // 203
getHours ساعت (0-23) را برمی‌گرداند.

امضاها:
timestamp.getHours([tz]) -> int
duration.getHours() -> int

مثال‌ها:
duration("1h30m").getHours() // 1
getMinutes دقیقه (0-59) را برمی‌گرداند.

امضاها:
timestamp.getMinutes([tz]) -> int
duration.getMinutes() -> int

مثال‌ها:
duration("1h30m").getMinutes() // 30
getSeconds ثانیه‌ها (0-59) را برمی‌گرداند.

امضاها:
timestamp.getSeconds([tz]) -> int
duration.getSeconds() -> int

مثال‌ها:
duration("1h30m45s").getSeconds() // 45
getMilliseconds میلی ثانیه (0-999) را برمی‌گرداند.

امضاها:
timestamp.getMilliseconds([tz]) -> int
duration.getMilliseconds() -> int

مثال‌ها:
duration("1.5s").getMilliseconds() // 500

تبدیل نوع

نوع هدف توضیحات برو سی++ جاوا پایتون سی
bool به بولی تبدیل می‌کند.

امضاها:
bool(bool) -> bool
bool(string) -> bool

مثال‌ها:
bool("true") // true
bytes به بایت تبدیل می‌کند.

امضاها:
bytes(bytes) -> bytes
bytes(string) -> bytes

مثال‌ها:
bytes("hello") // b"hello"
double به نوع اعشاری با دقت مضاعف تبدیل می‌کند.

امضاها:
double(double) -> double
double(int) -> double
double(uint) -> double
double(string) -> double

مثال‌ها:
double(1) // 1.0
duration به مدت زمان تبدیل می‌کند.

امضاها:
duration(duration) -> duration
duration(string) -> duration

مثال‌ها:
duration("1.5s") // 1.5s duration
int به عدد صحیح علامت‌دار ۶۴ بیتی تبدیل می‌کند.

امضاها:
int(int) -> int
int(uint) -> int
int(double) -> int (به صفر گرد می‌کند)
int(string) -> int
int(timestamp) -> int (ثانیه از زمان شروع)

مثال‌ها:
int(1.5) // 1
string به رشته تبدیل می‌کند.

امضاها:
string(T) -> string ( bool ، int ، uint ، double ، bytes ، timestamp ، duration پشتیبانی می‌کند)

مثال‌ها:
string(1.5) // "1.5"
timestamp به برچسب زمانی تبدیل می‌شود.

امضاها:
timestamp(timestamp) -> timestamp
timestamp(string) -> timestamp (RFC3339)

مثال‌ها:
timestamp("2026-07-23T00:00:00Z")
uint به عدد صحیح بدون علامت ۶۴ بیتی تبدیل می‌کند.

امضاها:
uint(uint) -> uint
uint(int) -> uint
uint(double) -> uint
uint(string) -> uint

مثال‌ها:
uint(1) // 1u
dyn برای بررسی نوع، مقدار را به نوع پویا تبدیل می‌کند.

امضاها:
dyn(T) -> dyn

مثال‌ها:
dyn([1, "two"])
type نوع مقدار را برمی‌گرداند.

امضاها:
type(T) -> type

مثال‌ها:
type(1) // int

۴. افزونه‌ها (کتابخانه‌ها)

کتابخانه صحافی

عملکرد توضیحات برو سی++ جاوا پایتون سی
cel.bind برای جلوگیری از ارزیابی تکراری، یک متغیر محلی را مقید می‌کند.

امضاها:
cel.bind(varName, initExpr, resultExpr) -> T

مثال‌ها:
cel.bind(x, a + b, x * x)
(نسخه ۰.۱۵.۰) (نسخه ۰.۱۰.۰) (نسخه ۰.۲.۰) (نسخه ۰.۱.۱)

نحوه فعال کردن

  • برو: ext.Bindings() را به cel.NewEnv() ارسال کن.
  • ++C: تابع BindingsCompilerLibrary() را به CompilerBuilder اضافه کنید. (زمان اجرا به صورت خودکار مدیریت می‌شود).
  • جاوا: CelExtensions.bindings() را به سازندگان CelCompiler و CelRuntime اضافه کنید.
  • پایتون: cel_expr_python.ext.ext_bindings وارد کنید و ExtBindings() در cel.NewEnv(extensions=[...]) استفاده کنید.

کتابخانه انکودرها

عملکرد توضیحات برو سی++ جاوا پایتون سی
base64.encode بایت‌ها را به رشته‌ی base64 کدگذاری می‌کند.

امضاها:
base64.encode(bytes) -> string

مثال‌ها:
base64.encode(b"hello") // "aGVsbG8="
(نسخه ۰.۶.۰) (نسخه ۰.۱۰.۰) (نسخه ۰.۲.۰) (نسخه ۰.۱.۱)
base64.decode رشته‌ی base64 را به بایت تبدیل می‌کند. در صورت ورود اطلاعات نامعتبر، خطا می‌دهد.

امضاها:
base64.decode(string) -> bytes

مثال‌ها:
base64.decode("aGVsbG8=") // b"hello"
(نسخه ۰.۶.۰) (نسخه ۰.۱۰.۰) (نسخه ۰.۲.۰) (نسخه ۰.۱.۱)
json.encode یک مقدار CEL را به رشته JSON سریالی می‌کند.

امضاها:
json.encode(dyn) -> string

مثال‌ها:
json.encode([1, 2]) // "[1,2]"
(نسخه ۰.۲۹.۰)

نحوه فعال کردن

  • برو: تابع ext.Encoders() را به cel.NewEnv() ارسال کن.
  • سی++:
  • جاوا: CelExtensions.encoders() را به سازندگان CelCompiler و CelRuntime اضافه کنید.
  • پایتون: cel_expr_python.ext.ext_encoders را وارد کنید و ExtEncoders() در cel.NewEnv(extensions=[...]) استفاده کنید.

کتابخانه ریاضی

عملکرد توضیحات برو سی++ جاوا پایتون سی
math.greatest بزرگترین آرگومان عددی (یا لیستی از اعداد) را برمی‌گرداند.

امضاها:
math.greatest(arg, ...) -> T

مثال‌ها:
math.greatest(1, 3, 2) // 3
(نسخه ۰.۱۳.۰) (نسخه ۰.۱۰.۰) (نسخه ۰.۲.۰) (نسخه ۰.۱.۱)
math.least کمترین تعداد آرگومان‌های عددی (یا لیستی از اعداد) را برمی‌گرداند.

امضاها:
math.least(arg, ...) -> T

مثال‌ها:
math.least([1, 3, 2]) // 1
(نسخه ۰.۱۳.۰) (نسخه ۰.۱۰.۰) (نسخه ۰.۲.۰) (نسخه ۰.۱.۱)
math.abs ارزش مطلق.

امضاها:
math.abs(T) -> T ( int ، uint ، double پشتیبانی می‌کند)

مثال‌ها:
math.abs(-1) // 1
(نسخه ۰.۲۱.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱۰.۱) (نسخه ۰.۱.۱)
math.sqrt جذر.

امضاها:
math.sqrt(T) -> double ( int ، uint ، double پشتیبانی می‌کند)

مثال‌ها:
math.sqrt(9) // 3.0
(نسخه ۰.۲۵.۱) (نسخه ۰.۱۲.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱.۱)
math.bitAnd بیتی و.

امضاها:
math.bitAnd(T, T) -> T ( int و uint پشتیبانی می‌کند)

مثال‌ها:
math.bitAnd(5, 3) // 1
(نسخه ۰.۲۱.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱۰.۱) (نسخه ۰.۱.۱)
math.bitOr یای بیتی.

امضاها:
math.bitOr(T, T) -> T ( int و uint پشتیبانی می‌کند)

مثال‌ها:
math.bitOr(5, 3) // 7
(نسخه ۰.۲۱.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱۰.۱) (نسخه ۰.۱.۱)
math.bitXor XOR بیتی

امضاها:
math.bitXor(T, T) -> T ( int و uint پشتیبانی می‌کند)

مثال‌ها:
math.bitXor(5, 3) // 6
(نسخه ۰.۲۱.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱۰.۱) (نسخه ۰.۱.۱)
math.bitNot بیتی نیست.

امضاها:
math.bitNot(T) -> T ( int و uint پشتیبانی می‌کند)

مثال‌ها:
math.bitNot(1) // -2
(نسخه ۰.۲۱.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱۰.۱) (نسخه ۰.۱.۱)
math.bitShiftLeft شیفت بیتی به چپ.

امضاها:
math.bitShiftLeft(T, int) -> T ( int و uint پشتیبانی می‌کند)

مثال‌ها:
math.bitShiftLeft(1, 2) // 4
(نسخه ۰.۲۱.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱۰.۱) (نسخه ۰.۱.۱)
math.bitShiftRight شیفت بیتی به راست.

امضاها:
math.bitShiftRight(T, int) -> T ( int و uint پشتیبانی می‌کند)

مثال‌ها:
math.bitShiftRight(4, 2) // 1
(نسخه ۰.۲۱.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱۰.۱) (نسخه ۰.۱.۱)
math.ceil گرد کردن سقف.

امضاها:
math.ceil(double) -> double

مثال‌ها:
math.ceil(1.2) // 2.0
(نسخه ۰.۲۱.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱۰.۱) (نسخه ۰.۱.۱)
math.floor گرد کردن کف.

امضاها:
math.floor(double) -> double

مثال‌ها:
math.floor(1.8) // 1.0
(نسخه ۰.۲۱.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱۰.۱) (نسخه ۰.۱.۱)
math.round گرد کردن نزدیکترین عدد صحیح.

امضاها:
math.round(double) -> double

مثال‌ها:
math.round(1.5) // 2.0
(نسخه ۰.۲۱.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱۰.۱) (نسخه ۰.۱.۱)
math.trunc گرد کردن با برش (به سمت صفر).

امضاها:
math.trunc(double) -> double

مثال‌ها:
math.trunc(-1.8) // -1.0
(نسخه ۰.۲۱.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱۰.۱) (نسخه ۰.۱.۱)
math.isInf بررسی می‌کند که آیا double مثبت است یا منفی بی‌نهایت.

امضاها:
math.isInf(double) -> bool

مثال‌ها:
math.isInf(1.0/0.0) // true
(نسخه ۰.۲۱.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱۰.۱) (نسخه ۰.۱.۱)
math.isNaN بررسی می‌کند که آیا double برابر با NaN است یا خیر.

امضاها:
math.isNaN(double) -> bool

مثال‌ها:
math.isNaN(0.0/0.0) // true
(نسخه ۰.۲۱.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱۰.۱) (نسخه ۰.۱.۱)
math.isFinite بررسی می‌کند که آیا double متناهی است یا خیر.

امضاها:
math.isFinite(double) -> bool

مثال‌ها:
math.isFinite(1.2) // true
(نسخه ۰.۲۱.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱۰.۱) (نسخه ۰.۱.۱)
math.sign علامت مقدار (-1، 0، یا 1) را برمی‌گرداند.

امضاها:
math.sign(T) -> T ( int ، uint ، double پشتیبانی می‌کند)

مثال‌ها:
math.sign(-42) // -1
(نسخه ۰.۲۱.۰) (نسخه ۰.۱۱.۰) (نسخه ۰.۱۰.۱) (نسخه ۰.۱.۱)

نحوه فعال کردن

  • برو: تابع ext.Math() را به cel.NewEnv() ارسال کن.
  • سی++:
  • جاوا: CelExtensions.math() را به سازندگان CelCompiler و CelRuntime اضافه کنید.
  • پایتون: cel_expr_python.ext.ext_math را وارد کنید و ExtMath() در cel.NewEnv(extensions=[...]) استفاده کنید.

کتابخانه پروتوس

عملکرد توضیحات برو سی++ جاوا پایتون سی
proto.getExt فیلد افزونه proto2 را برمی‌گرداند، یا اگر تنظیم نشده باشد، پیش‌فرض است.

امضاها:
proto.getExt(msg, extName) -> T

مثال‌ها:
proto.getExt(msg, google.api.expr.test.int32_ext)
(نسخه ۰.۱۳.۰) (نسخه ۰.۱۰.۰) (نسخه ۰.۲.۰) (نسخه ۰.۱.۱)
proto.hasExt بررسی می‌کند که آیا فیلد افزونه‌ی proto2 تنظیم شده است یا خیر.

امضاها:
proto.hasExt(msg, extName) -> bool

مثال‌ها:
proto.hasExt(msg, google.api.expr.test.int32_ext)
(نسخه ۰.۱۳.۰) (نسخه ۰.۱۰.۰) (نسخه ۰.۲.۰) (نسخه ۰.۱.۱)

نحوه فعال کردن

  • برو: ext.Protos() را به cel.NewEnv() ارسال کن.
  • ++C: اضافه کردن ProtoExtCompilerLibrary() به CompilerBuilder . (زمان اجرا به صورت خودکار مدیریت می‌شود).
  • جاوا: CelExtensions.protos() را به سازندگان CelCompiler و CelRuntime اضافه کنید.
  • پایتون: cel_expr_python.ext.ext_proto را وارد کنید و ExtProto() در cel.NewEnv(extensions=[...]) استفاده کنید.

کتابخانه لیست‌ها

عملکرد توضیحات برو سی++ جاوا پایتون سی
distinct عناصر متمایز را برمی‌گرداند.

امضاها:
list.distinct() -> list

مثال‌ها:
[1, 2, 2].distinct() // [1, 2]
(v0.22.0) (v0.11.0) (v0.11.0) (v0.1.1)
flatten Flattens nested lists.

Signatures:
list.flatten([depth]) -> list

Examples:
[[1], [2, 3]].flatten() // [1, 2, 3]
(v0.22.0) (v0.11.0) (v0.7.1) (v0.1.1)
lists.range Returns list of integers [0, ..., n-1] .

Signatures:
lists.range(int) -> list(int)

Examples:
lists.range(3) // [0, 1, 2]
(v0.22.0) (v0.11.0) (v0.10.1) (v0.1.1)
reverse Reverses the list.

Signatures:
list.reverse() -> list

Examples:
[1, 2].reverse() // [2, 1]
(v0.22.0) (v0.11.0) (v0.11.0) (v0.1.1)
slice Returns sub-list (start inclusive, end exclusive).

Signatures:
list.slice(start, end) -> list

Examples:
[1, 2, 3].slice(1, 3) // [2, 3]
(v0.17.0) (v0.11.0) (v0.11.0) (v0.1.1)
sort Sorts list of comparable elements.

Signatures:
list.sort() -> list

Examples:
[3, 1, 2].sort() // [1, 2, 3]
(v0.22.0) (v0.11.0) (v0.11.0) (v0.1.1)
sortBy Sorts list by key evaluated from expression.

Signatures:
list.sortBy(var, expr) -> list

Examples:
[{"val": 2}, {"val": 1}].sortBy(x, x.val) // [{"val": 1}, {"val": 2}]
(v0.22.0) (v0.11.0) (v0.11.0) (v0.1.1)
first Returns first element as optional. Requires the Optional extension.

Signatures:
list.first() -> optional

Examples:
[1, 2].first() // optional(1)
(v0.23.0) (v0.15.0) (v0.11.0) (v0.1.2)
last Returns last element as optional. Requires the Optional extension.

Signatures:
list.last() -> optional

Examples:
[1, 2].last() // optional(2)
(v0.23.0) (v0.15.0) (v0.11.0) (v0.1.2)

How to Enable

Sets Library

عملکرد توضیحات برو سی++ جاوا پایتون سی
sets.contains Checks if list1 contains all elements of list2.

Signatures:
sets.contains(list1, list2) -> bool

Examples:
sets.contains([1, 2], [1]) // true
(v0.15.0) (v0.10.0) (v0.6.0) (v0.1.1)
sets.equivalent Checks if lists are set-equivalent (contain same unique elements).

Signatures:
sets.equivalent(list1, list2) -> bool

Examples:
sets.equivalent([1, 2], [2, 1, 1]) // true
(v0.15.0) (v0.10.0) (v0.6.0) (v0.1.1)
sets.intersects Checks if lists share at least one element.

Signatures:
sets.intersects(list1, list2) -> bool

Examples:
sets.intersects([1, 2], [2, 3]) // true
(v0.15.0) (v0.10.0) (v0.6.0) (v0.1.1)

How to Enable

Strings Library

عملکرد توضیحات برو سی++ جاوا پایتون سی
charAt Returns character at index.

Signatures:
string.charAt(int) -> string

Examples:
"hello".charAt(1) // "e"
(v0.4.0) (v0.10.0) (v0.2.0) (v0.1.1)
indexOf Returns index of first occurrence of substring, or -1.

Signatures:
string.indexOf(substr, [start]) -> int

Examples:
"hello".indexOf("l") // 2
(v0.4.0) (v0.10.0) (v0.2.0) (v0.1.1)
lastIndexOf Returns index of last occurrence of substring, or -1.

Signatures:
string.lastIndexOf(substr, [end]) -> int

Examples:
"hello".lastIndexOf("l") // 3
(v0.4.0) (v0.10.0) (v0.2.0) (v0.1.1)
join Concatenates strings.

Signatures:
list(string).join([separator]) -> string

Examples:
["a", "b"].join("-") // "ab"
(v0.10.0) (v0.10.0) (v0.2.0) (v0.1.1)
split Splits string by separator.

Signatures:
string.split(separator, [limit]) -> list(string)

Examples:
"ab".split("-") // ["a", "b"]
(v0.4.0) (v0.10.0) (v0.2.0) (v0.1.1)
substring Returns substring (start inclusive, end exclusive).

Signatures:
string.substring(start, [end]) -> string

Examples:
"hello".substring(1, 3) // "el"
(v0.4.0) (v0.10.0) (v0.2.0) (v0.1.1)
trim Trims Unicode whitespace.

Signatures:
string.trim() -> string

Examples:
" hello ".trim() // "hello"
(v0.4.0) (v0.10.0) (v0.2.0) (v0.1.1)
replace Replaces occurrences of old with new.

Signatures:
string.replace(old, new, [limit]) -> string

Examples:
"hello".replace("l", "w") // "hewwo"
(v0.4.0) (v0.10.0) (v0.2.0) (v0.1.1)
reverse Reverses Unicode code points.

Signatures:
string.reverse() -> string

Examples:
"abc".reverse() // "cba"
(v0.18.0) (v0.14.0) (v0.13.0) (v0.1.1)
lowerAscii Converts ASCII characters to lowercase.

Signatures:
string.lowerAscii() -> string

Examples:
"Hello".lowerAscii() // "hello"
(v0.6.0) (v0.11.0) (v0.2.0) (v0.1.1)
upperAscii Converts ASCII characters to uppercase.

Signatures:
string.upperAscii() -> string

Examples:
"Hello".upperAscii() // "HELLO"
(v0.6.0) (v0.11.0) (v0.2.0) (v0.1.1)
quote Escapes string for safe printing.

Signatures:
strings.quote(string) -> string

Examples:
strings.quote("a\tb") // "\"a\\tb\""
(v0.14.0) (v0.14.0) (v0.13.0) (v0.1.1)
format Formats the string using printf-style placeholders.

Signatures:
string.format(list) -> string

Examples:
"str: %s, int: %d".format(["a", 1]) // "str: a, int: 1"
(v0.14.0) (v0.11.0) (v0.1.1)

How to Enable

Regular Expression Library

عملکرد توضیحات برو سی++ جاوا پایتون سی
regex.replace Replaces matches with replacement string (supports backreferences).

Signatures:
regex.replace(target, pat, repl, [limit]) -> string

Examples:
regex.replace("123-456", r"(\d+)-(\d+)", r"\2-\1") // "456-123"
(v0.25.1) (v0.13.0) (v0.10.1) (v0.1.1)
regex.extract Returns first match of pattern (must have one capture group).

Signatures:
regex.extract(target, pat) -> optional(string)

Examples:
regex.extract("a123b", r"(\d+)") // optional("123")
(v0.25.1) (v0.13.0) (v0.10.1) (v0.1.1)
regex.extractAll Returns all matches of pattern (must have one capture group).

Signatures:
regex.extractAll(target, pat) -> list(string)

Examples:
regex.extractAll("a1b2", r"(\d+)") // ["1", "2"]
(v0.25.1) (v0.13.0) (v0.10.1) (v0.1.1)

How to Enable

Two-Variable Comprehensions

ماکرو توضیحات برو سی++ جاوا پایتون سی
all Short-circuiting logical AND over key/index and value.

Signatures:
list.all(i, v, pred) -> bool
map.all(k, v, pred) -> bool

Examples:
[1, 2].all(i, v, v > 0) // true
(v0.22.0) (v0.14.0) (v0.11.0) (v0.1.1)
exists Short-circuiting logical OR over key/index and value.

Signatures:
list.exists(i, v, pred) -> bool
map.exists(k, v, pred) -> bool

Examples:
[1, 2].exists(i, v, v == 2) // true
(v0.22.0) (v0.14.0) (v0.11.0) (v0.1.1)
existsOne Checks if exactly one pair satisfies predicate.

Signatures:
list.existsOne(i, v, pred) -> bool
map.existsOne(k, v, pred) -> bool

Examples:
[1, 2].existsOne(i, v, v == 2) // true
(v0.22.0) (v0.14.0) (v0.11.0) (v0.1.1)
transformList Transforms/filters list/map into a list.

Signatures:
list.transformList(i, v, [filter], transform) -> list
map.transformList(k, v, [filter], transform) -> list

Examples:
[1, 2].transformList(i, v, v * 2) // [2, 4]
(v0.22.0) (v0.14.0) (v0.11.0) (v0.1.1)
transformMap Transforms values of list/map into a map (keys remain fixed).

Signatures:
list.transformMap(i, v, [filter], transform) -> map
map.transformMap(k, v, [filter], transform) -> map

Examples:
[1, 2].transformMap(i, v, v * 2) // {0: 2, 1: 4}
(v0.22.0) (v0.14.0) (v0.11.0) (v0.1.1)
transformMapEntry Transforms into a map.

Signatures:
list.transformMapEntry(i, v, [filter], transform_entry) -> map
map.transformMapEntry(k, v, [filter], transform_entry) -> map

Examples:
[1, 2].transformMapEntry(i, v, {string(v): v * 2}) // {"1": 2, "2": 4}
(v0.22.0) (v0.14.0) (v0.11.0) (v0.1.1)

How to Enable

Native Types Library

ویژگی توضیحات برو سی++ جاوا پایتون سی
Native Structs Registering and instantiating host native types (Go structs / Java POJOs) in CEL.

Examples:
Account{id: 123} (Java POJO instanced in CEL)
(v0.13.0) (v0.13.0)

How to Enable

Network Library

The Network library provides functions for parsing, validating, and manipulating IP addresses and CIDR blocks.

عملکرد توضیحات برو سی++ جاوا پایتون سی
ip Parses a string into an IP address, or extracts the IP from a CIDR.

Signatures:
ip(string) -> IP
CIDR.ip() -> IP

Examples:
ip("192.168.0.1")
cidr("192.168.0.0/24").ip()
(v0.29.0)
isIP Checks if a string is a valid IP address.

Signatures:
isIP(string) -> bool

Examples:
isIP("192.168.0.1") // true
(v0.29.0)
ip.isCanonical Checks if an IP address string is in its canonical format.

Signatures:
ip.isCanonical(string) -> bool

Examples:
ip.isCanonical("192.168.0.1") // true
(v0.29.0)
cidr Parses a string into a CIDR block.

Signatures:
cidr(string) -> CIDR

Examples:
cidr("192.168.0.0/24")
(v0.29.0)
isCIDR Checks if a string is a valid CIDR block.

Signatures:
isCIDR(string) -> bool

Examples:
isCIDR("192.168.0.0/24") // true
(v0.29.0)
containsIP Checks if a CIDR block contains an IP address.

Signatures:
CIDR.containsIP(IP) -> bool
CIDR.containsIP(string) -> bool

Examples:
cidr("192.168.0.0/24").containsIP(ip("192.168.0.1")) // true
(v0.29.0)
containsCIDR Checks if a CIDR block contains another CIDR block.

Signatures:
CIDR.containsCIDR(CIDR) -> bool
CIDR.containsCIDR(string) -> bool

Examples:
cidr("192.168.0.0/16").containsCIDR(cidr("192.168.1.0/24")) // true
(v0.29.0)
family Returns the IP family (4 for IPv4, 6 for IPv6).

Signatures:
IP.family() -> int

Examples:
ip("192.168.0.1").family() // 4
(v0.29.0)
isGlobalUnicast Checks if the IP is a global unicast address.

Signatures:
IP.isGlobalUnicast() -> bool

Examples:
ip("192.168.0.1").isGlobalUnicast() // true
(v0.29.0)
isLinkLocalMulticast Checks if the IP is a link-local multicast address.

Signatures:
IP.isLinkLocalMulticast() -> bool

Examples:
ip("224.0.0.1").isLinkLocalMulticast() // true
(v0.29.0)
isLinkLocalUnicast Checks if the IP is a link-local unicast address.

Signatures:
IP.isLinkLocalUnicast() -> bool

Examples:
ip("169.254.0.1").isLinkLocalUnicast() // true
(v0.29.0)
isLoopback Checks if the IP is a loopback address.

Signatures:
IP.isLoopback() -> bool

Examples:
ip("127.0.0.1").isLoopback() // true
(v0.29.0)
isMask Checks if the CIDR is a valid subnet mask.

Signatures:
CIDR.isMask() -> bool

Examples:
cidr("255.255.255.0/24").isMask() // true
(v0.29.0)
isUnspecified Checks if the IP is an unspecified address (eg 0.0.0.0 ).

Signatures:
IP.isUnspecified() -> bool

Examples:
ip("0.0.0.0").isUnspecified() // true
(v0.29.0)
masked Returns the masked CIDR block.

Signatures:
CIDR.masked() -> CIDR

Examples:
cidr("192.168.0.1/24").masked() // 192.168.0.0/24
(v0.29.0)
prefixLength Returns the prefix length of the CIDR block.

Signatures:
CIDR.prefixLength() -> int

Examples:
cidr("192.168.0.0/24").prefixLength() // 24
(v0.29.0)
string Converts IP or CIDR to string.

Signatures:
string(IP) -> string
string(CIDR) -> string

Examples:
string(ip("192.168.0.1")) // "192.168.0.1"
(v0.29.0)

How to Enable

  • Go: Pass ext.Network() to cel.NewEnv() .
  • C++: Not supported.
  • Java: Not supported.
  • Python: Not supported.

JWT Library

The JWT library provides data types and helper functions for parsing JSON Web Tokens (JWT) and inspecting standard and custom claims.

عملکرد توضیحات برو سی++ جاوا پایتون سی
jwt.parse Parses a raw token string into a structured jwt.Token wrapped in an optional.

Signatures:
jwt.parse(string) -> optional(jwt.Token)

Examples:
jwt.parse(token_string).hasValue()
(v0.32.0)
claim Queries a custom claim value by key name from the token payload.

Signatures:
jwt.Token.claim(string) -> optional(dyn)
optional(jwt.Token).claim(string) -> optional(dyn)

Examples:
jwt.parse(token).claim("tenant").orValue("")
(v0.32.0)
presentedBy Validates that the token's issuer and audience match expected values.

Signatures:
jwt.Token.presentedBy(string, string) -> bool
optional(jwt.Token).presentedBy(string, string) -> bool

Examples:
jwt.parse(token).presentedBy("https://auth.example.com", "https://api.example.com")
(v0.32.0)

How to Enable

  • Go: Import cel.dev/cel-go/ext/security/jwt and pass jwt.Library() to cel.NewEnv() .
  • C++: Not supported.
  • Java: Not supported.
  • Python: Not supported.

HMAC Library

The HMAC library provides cryptographic functions to compute and verify Hash-based Message Authentication Codes (HMAC) over strings and byte sequences.

عملکرد توضیحات برو سی++ جاوا پایتون سی
hmac.compute Computes raw HMAC signature bytes using the specified algorithm and secret key.

Signatures:
hmac.compute(string, string|bytes, string|bytes) -> bytes

Examples:
hmac.compute(hmac.SHA256, "secret", "message")
(v0.32.0)
hmac.verify Verifies whether an HMAC signature matches the expected digest.

Signatures:
hmac.verify(string, string|bytes, string|bytes, string|bytes) -> bool

Examples:
hmac.verify(hmac.SHA256, secret, msg, expected_sig) // true
(v0.32.0)

How to Enable

  • Go: Import cel.dev/cel-go/ext/security/hmac and pass hmac.Library() to cel.NewEnv() .
  • C++: Not supported.
  • Java: Not supported.
  • Python: Not supported.

5. Advanced Features

Advanced Features Summary

ویژگی توضیحات برو سی++ جاوا پایتون سی
Partial Evaluation Evaluate with missing inputs; returns unknowns or a simplified expression. ³
Async Evaluation Non-blocking concurrent execution of extension functions.
AST Validators Static analysis checks on the Checked AST after type-checking.
AST Optimizers AST rewrites (constant folding, inlining, CSE) to improve performance.
CEL Policy Compiler Compiles YAML-based policy structures into standard CEL ASTs.
Formal Verification Proves safety invariants, satisfiability, validity, and AST equivalence. (v0.14.0)

³ Go supports generating a Residual AST (pruned AST). ⁴ C++ and Java support returning UnknownSet / CelUnknownSet at runtime, but do not expose public APIs for residual AST generation. ⁵ Go uses AsyncBinding / AsyncOp returning channels. ⁶ Java uses CelAsyncRuntime returning ListenableFuture .

Partial Evaluation (Unknowns)

Partial evaluation allows evaluating an expression when only a subset of the input variables (arguments) are known. Instead of failing, the evaluation produces a result that indicates what is missing, or a simplified expression.

  • Go: Full support. Allows defining a PartialActivation with patterns of unknown attributes. Evaluation returns a types.Unknown value. Go supports generating a Residual AST ( Env.ResidualAst ) which is a pruned, simplified AST containing only the parts of the expression that could not be evaluated.
  • C++: Supports Unknown values. Unknown attribute patterns are configured via Activation::set_unknown_attribute_patterns . Evaluation returns an UnknownSet . Public API does not currently expose residual AST generation.
  • Java: Supports partial evaluation via PartialVars passed to Program.eval() . Evaluation returns a CelUnknownSet . Public API does not currently expose residual AST generation.
  • Python / C: No native support.

Async Evaluation

Async evaluation allows CEL expressions to call functions that execute asynchronously (eg, making RPCs or database queries) and block evaluation until the results are available, without blocking the main execution thread.

  • Go: Supports asynchronous function overloads via AsyncBinding and AsyncOp . Async functions return a Go channel ( <-chan ref.Val ), and the interpreter manages the concurrent execution and synchronization.
  • Java: Supports async evaluation via CelAsyncRuntime and AsyncProgram . It uses ListenableFuture to represent pending values and automatically drives evaluation to completion as futures resolve.
  • C++ / Python / C: No built-in support.

AST Validators

Validators perform static analysis on the Checked AST after type-checking to enforce domain-specific constraints before the program is executed.

  • Go: Supports ASTValidator interface. Canonical validators include cel.validator.duration , cel.validator.timestamp , cel.validator.matches (regex), cel.validator.homogeneous_literals , and cel.validator.comprehension_nesting_limit .
  • C++: Supports cel::Validator . Canonical validations include AstDepthValidator , ComprehensionNestingLimitValidator , DurationLiteralValidator , HomogeneousLiteralValidator , MatchesValidator , and TimestampLiteralValidator .
  • Java: Supports CelValidator and CelAstValidator . Canonical validators include AstDepthLimitValidator , ComprehensionNestingLimitValidator , DurationLiteralValidator , HomogeneousLiteralValidator , RegexLiteralValidator , and TimestampLiteralValidator .
  • Python / C: No direct support.

AST Optimizers

Optimizers rewrite the AST to improve execution performance. Optimizers fall into one of two categories: static and runtime optimizers. C++, Java, and Go support runtime optimization. CEL Java and Go also support static optimizers.

Typical optimizations include constant folding (pre-evaluating sub-expressions with constant inputs) and common subexpression elimination (CSE).

  • Go: Supports AST folding during compilation/planning.
  • C++: Supports constant folding via the cel::extensions::EnableConstantFolding extension at plan time.
  • Java: Supports CelOptimizer interface. Canonical optimizers include ConstantFoldingOptimizer (which supports pre-order traversal, Protobuf message constant folding, and aggregate or optional pruning), InliningOptimizer , and SubexpressionOptimizer (CSE).
  • Python / C: No direct support.

CEL Policy Compiler

CEL Policy is a YAML-based format for composing multiple CEL expressions together with variables, match blocks, conditional outputs, and nested rules. It is designed for complex policy engines (like Kubernetes Admission Control) where single CEL expressions would become unreadable.

For the formal language definition, syntax, and conformance suite, refer to the CEL Policy Specification .

The Policy Compiler compiles these YAML policies into a single standard CEL AST, meaning they are fully compatible with standard CEL runtimes and inherit all performance and safety guarantees.

  • Go: Supported via Go policy (including aggregate rule evaluation semantics).
  • C++: Supported via C++ policy .
  • Java: Supported via Java policy (including aggregate rule evaluation semantics and shorthand type specifiers in policy configs).
  • Python / C: Not directly supported.

Formal Verification Framework

The Formal Verification framework allows users to mathematically prove safety invariants, logical equivalence, satisfiability, and validity across CEL expressions and structured CEL Policies.

  • Java: Supported via the CEL Java Verifier ( dev.cel:verifier and dev.cel:verifier-cli ). Capabilities include satisfiability ( isSatisfiable ) with witness input generation, validity ( isAlwaysTrue ) with counterexample generation, bounded model checking (BMC) for comprehensions, logical equivalence proofs across ASTs, and custom assume / assert policy invariant verification.
  • Go / C++ / Python / C: Are supported indirectly via the Java command line toolchain.

For an introduction and real-world examples, see the Google Open Source blog post: Securing the agentic era: Introducing formal verification for CEL .

،

This document serves as the unified API Doc reference for the Common Expression Language (CEL). It lists all macros, operators, and standard functions, indicating their signatures, behaviors, and support status across the official CEL stacks.

For more details on language behavior and specifications, refer to the CEL Language Definition .

Stack Versions

This reference document is based on the following versions of the CEL stacks:

  • CEL Go : v0.32.0 (and newer)
  • CEL C++ : v0.16.1
  • CEL Java : v0.14.0
  • CEL Python : v0.1.3
  • CEL C : Development snapshot (unreleased)

GitHub Mirrors

The official implementations of CEL are mirrored on GitHub under the cel-expr organization:


1. Core Macros

These are built-in macros that are expanded at compile time.

ماکرو توضیحات برو سی++ جاوا پایتون سی
has(container.field) Tests whether a field is present in a message, or a key in a map.

Signatures:
has(container.field) -> bool

Examples:
has(request.auth.claims.email)
list.all(var, predicate) Tests whether all elements in a list satisfy a predicate.

Signatures:
list.all(var, predicate) -> bool

Examples:
[1, 2, 3].all(x, x > 0) // true
¹
list.exists(var, predicate) Tests whether at least one element in a list satisfies a predicate.

Signatures:
list.exists(var, predicate) -> bool

Examples:
[1, 2, 3].exists(x, x > 2) // true
¹
list.exists_one(var, predicate) Tests whether exactly one element in a list satisfies a predicate.

Signatures:
list.exists_one(var, predicate) -> bool

Examples:
[1, 2, 3].exists_one(x, x == 2) // true
¹
list.filter(var, predicate) Filters elements of a list according to a predicate.

Signatures:
list.filter(var, predicate) -> list

Examples:
[1, 2, 3].filter(x, x > 1) // [2, 3]
¹
list.map(var, transform) Transforms each element of a list using an expression.

Signatures:
list.map(var, transform) -> list

Examples:
[1, 2, 3].map(x, x * 2) // [2, 4, 6]
¹
list.map(var, filter, transform) Transforms elements of a list that satisfy a filter predicate.

Signatures:
list.map(var, filter, transform) -> list

Examples:
[1, 2, 3].map(x, x > 1, x * 2) // [4, 6]
¹

¹ Supported in C runtime because macros are expanded into comprehensions during compilation by the host compiler.


2. Core Operators

اپراتور توضیحات برو سی++ جاوا پایتون سی
Arithmetic ( + , - , * , / , % ) Standard arithmetic operations. Negation ( -x ) and Identity ( +x ). List concatenation ( list + list ) is supported in Go, C++, Java, and Python.

Signatures:
T + T -> T
T - T -> T
T * T -> T
T / T -> T
T % T -> T
-T -> T
+T -> T
list + list -> list

Examples:
1 + 2 * 3 // 7
[1] + [2] // [1, 2]
²
Comparison ( == , != , < , <= , > , >= ) Standard comparison. Numeric comparisons are heterogeneous (eg 1 == 1.0 ).

Signatures:
T == T -> bool
T != T -> bool
T < T -> bool
T <= T -> bool
T > T -> bool
T >= T -> bool

Examples:
x < 42.0
1 == 1.0 // true
Logical ( ! , && , || , ? : ) Logical NOT, AND, OR, and Ternary Conditional. AND/OR use short-circuit evaluation.

Signatures:
!bool -> bool
bool && bool -> bool
bool || bool -> bool
bool ? T : T -> T

Examples:
x > 0 ? "positive" : "non-positive"
Indexing ( [] ) Access element of a list by index, or lookup key in a map.

Signatures:
list[int] -> T
map[K] -> V

Examples:
tags[0]
users['john']
Membership ( in ) Check if element is in a list, or key is in a map.

Signatures:
T in list -> bool
K in map -> bool

Examples:
'admin' in roles

² List concatenation ( list + list ) is not supported in the C runtime, though other arithmetic operators are supported.


3. Core Functions

General & String Functions

عملکرد توضیحات برو سی++ جاوا پایتون سی
size Returns the size of a string (characters), bytes, list, or map.

Signatures:
size(T) -> int (where T is string , bytes , list , or map )

Examples:
size("hello") // 5
contains Returns whether string contains substring.

Signatures:
string.contains(string) -> bool

Examples:
"hello".contains("ell") // true
startsWith Returns whether string starts with prefix.

Signatures:
string.startsWith(string) -> bool

Examples:
"hello".startsWith("he") // true
endsWith Returns whether string ends with suffix.

Signatures:
string.endsWith(string) -> bool

Examples:
"hello".endsWith("lo") // true
matches Returns whether string matches RE2 regular expression.

Signatures:
string.matches(string) -> bool

Examples:
"123".matches(r"^\d+$") // true

Date and Time Selector Functions

These functions extract components from google.protobuf.Timestamp or google.protobuf.Duration .

عملکرد توضیحات برو سی++ جاوا پایتون سی
getFullYear Returns the 4-digit year.

Signatures:
timestamp.getFullYear([tz]) -> int

Examples:
timestamp("2026-07-23T00:00:00Z").getFullYear() // 2026
getMonth Returns the month (0-11).

Signatures:
timestamp.getMonth([tz]) -> int

Examples:
timestamp("2026-07-23T00:00:00Z").getMonth() // 6
getDayOfMonth Returns the day of the month (1-31).

Signatures:
timestamp.getDayOfMonth([tz]) -> int

Examples:
timestamp("2026-07-23T00:00:00Z").getDayOfMonth() // 23
getDayOfWeek Returns the day of the week (0 = Sunday).

Signatures:
timestamp.getDayOfWeek([tz]) -> int

Examples:
timestamp("2026-07-23T00:00:00Z").getDayOfWeek() // 4
getDayOfYear Returns the day of the year (0-365).

Signatures:
timestamp.getDayOfYear([tz]) -> int

Examples:
timestamp("2026-07-23T00:00:00Z").getDayOfYear() // 203
getHours Returns the hours (0-23).

Signatures:
timestamp.getHours([tz]) -> int
duration.getHours() -> int

Examples:
duration("1h30m").getHours() // 1
getMinutes Returns the minutes (0-59).

Signatures:
timestamp.getMinutes([tz]) -> int
duration.getMinutes() -> int

Examples:
duration("1h30m").getMinutes() // 30
getSeconds Returns the seconds (0-59).

Signatures:
timestamp.getSeconds([tz]) -> int
duration.getSeconds() -> int

Examples:
duration("1h30m45s").getSeconds() // 45
getMilliseconds Returns the milliseconds (0-999).

Signatures:
timestamp.getMilliseconds([tz]) -> int
duration.getMilliseconds() -> int

Examples:
duration("1.5s").getMilliseconds() // 500

Type Conversions

Target Type توضیحات برو سی++ جاوا پایتون سی
bool Converts to boolean.

Signatures:
bool(bool) -> bool
bool(string) -> bool

Examples:
bool("true") // true
bytes Converts to bytes.

Signatures:
bytes(bytes) -> bytes
bytes(string) -> bytes

Examples:
bytes("hello") // b"hello"
double Converts to double-precision float.

Signatures:
double(double) -> double
double(int) -> double
double(uint) -> double
double(string) -> double

Examples:
double(1) // 1.0
duration Converts to duration.

Signatures:
duration(duration) -> duration
duration(string) -> duration

Examples:
duration("1.5s") // 1.5s duration
int Converts to 64-bit signed integer.

Signatures:
int(int) -> int
int(uint) -> int
int(double) -> int (rounds to zero)
int(string) -> int
int(timestamp) -> int (seconds since epoch)

Examples:
int(1.5) // 1
string Converts to string.

Signatures:
string(T) -> string (supports bool , int , uint , double , bytes , timestamp , duration )

Examples:
string(1.5) // "1.5"
timestamp Converts to timestamp.

Signatures:
timestamp(timestamp) -> timestamp
timestamp(string) -> timestamp (RFC3339)

Examples:
timestamp("2026-07-23T00:00:00Z")
uint Converts to 64-bit unsigned integer.

Signatures:
uint(uint) -> uint
uint(int) -> uint
uint(double) -> uint
uint(string) -> uint

Examples:
uint(1) // 1u
dyn Casts value to dynamic type for type-checking.

Signatures:
dyn(T) -> dyn

Examples:
dyn([1, "two"])
type Returns the type of the value.

Signatures:
type(T) -> type

Examples:
type(1) // int

4. Extensions (Libraries)

Bindings Library

عملکرد توضیحات برو سی++ جاوا پایتون سی
cel.bind Binds a local variable to avoid duplicate evaluation.

Signatures:
cel.bind(varName, initExpr, resultExpr) -> T

Examples:
cel.bind(x, a + b, x * x)
(v0.15.0) (v0.10.0) (v0.2.0) (v0.1.1)

How to Enable

Encoders Library

عملکرد توضیحات برو سی++ جاوا پایتون سی
base64.encode Encodes bytes to base64 string.

Signatures:
base64.encode(bytes) -> string

Examples:
base64.encode(b"hello") // "aGVsbG8="
(v0.6.0) (v0.10.0) (v0.2.0) (v0.1.1)
base64.decode Decodes base64 string to bytes. Throws error on invalid input.

Signatures:
base64.decode(string) -> bytes

Examples:
base64.decode("aGVsbG8=") // b"hello"
(v0.6.0) (v0.10.0) (v0.2.0) (v0.1.1)
json.encode Serializes a CEL value to JSON string.

Signatures:
json.encode(dyn) -> string

Examples:
json.encode([1, 2]) // "[1,2]"
(v0.29.0)

How to Enable

Math Library

عملکرد توضیحات برو سی++ جاوا پایتون سی
math.greatest Returns greatest of numeric arguments (or list of numerics).

Signatures:
math.greatest(arg, ...) -> T

Examples:
math.greatest(1, 3, 2) // 3
(v0.13.0) (v0.10.0) (v0.2.0) (v0.1.1)
math.least Returns least of numeric arguments (or list of numerics).

Signatures:
math.least(arg, ...) -> T

Examples:
math.least([1, 3, 2]) // 1
(v0.13.0) (v0.10.0) (v0.2.0) (v0.1.1)
math.abs Absolute value.

Signatures:
math.abs(T) -> T (supports int , uint , double )

Examples:
math.abs(-1) // 1
(v0.21.0) (v0.11.0) (v0.10.1) (v0.1.1)
math.sqrt Square root.

Signatures:
math.sqrt(T) -> double (supports int , uint , double )

Examples:
math.sqrt(9) // 3.0
(v0.25.1) (v0.12.0) (v0.11.0) (v0.1.1)
math.bitAnd Bitwise AND.

Signatures:
math.bitAnd(T, T) -> T (supports int , uint )

Examples:
math.bitAnd(5, 3) // 1
(v0.21.0) (v0.11.0) (v0.10.1) (v0.1.1)
math.bitOr Bitwise OR.

Signatures:
math.bitOr(T, T) -> T (supports int , uint )

Examples:
math.bitOr(5, 3) // 7
(v0.21.0) (v0.11.0) (v0.10.1) (v0.1.1)
math.bitXor Bitwise XOR.

Signatures:
math.bitXor(T, T) -> T (supports int , uint )

Examples:
math.bitXor(5, 3) // 6
(v0.21.0) (v0.11.0) (v0.10.1) (v0.1.1)
math.bitNot Bitwise NOT.

Signatures:
math.bitNot(T) -> T (supports int , uint )

Examples:
math.bitNot(1) // -2
(v0.21.0) (v0.11.0) (v0.10.1) (v0.1.1)
math.bitShiftLeft Bitwise shift left.

Signatures:
math.bitShiftLeft(T, int) -> T (supports int , uint )

Examples:
math.bitShiftLeft(1, 2) // 4
(v0.21.0) (v0.11.0) (v0.10.1) (v0.1.1)
math.bitShiftRight Bitwise shift right.

Signatures:
math.bitShiftRight(T, int) -> T (supports int , uint )

Examples:
math.bitShiftRight(4, 2) // 1
(v0.21.0) (v0.11.0) (v0.10.1) (v0.1.1)
math.ceil Ceiling rounding.

Signatures:
math.ceil(double) -> double

Examples:
math.ceil(1.2) // 2.0
(v0.21.0) (v0.11.0) (v0.10.1) (v0.1.1)
math.floor Floor rounding.

Signatures:
math.floor(double) -> double

Examples:
math.floor(1.8) // 1.0
(v0.21.0) (v0.11.0) (v0.10.1) (v0.1.1)
math.round Nearest integer rounding.

Signatures:
math.round(double) -> double

Examples:
math.round(1.5) // 2.0
(v0.21.0) (v0.11.0) (v0.10.1) (v0.1.1)
math.trunc Truncation rounding (towards zero).

Signatures:
math.trunc(double) -> double

Examples:
math.trunc(-1.8) // -1.0
(v0.21.0) (v0.11.0) (v0.10.1) (v0.1.1)
math.isInf Checks if double is positive or negative infinity.

Signatures:
math.isInf(double) -> bool

Examples:
math.isInf(1.0/0.0) // true
(v0.21.0) (v0.11.0) (v0.10.1) (v0.1.1)
math.isNaN Checks if double is NaN.

Signatures:
math.isNaN(double) -> bool

Examples:
math.isNaN(0.0/0.0) // true
(v0.21.0) (v0.11.0) (v0.10.1) (v0.1.1)
math.isFinite Checks if double is finite.

Signatures:
math.isFinite(double) -> bool

Examples:
math.isFinite(1.2) // true
(v0.21.0) (v0.11.0) (v0.10.1) (v0.1.1)
math.sign Returns sign of value (-1, 0, or 1).

Signatures:
math.sign(T) -> T (supports int , uint , double )

Examples:
math.sign(-42) // -1
(v0.21.0) (v0.11.0) (v0.10.1) (v0.1.1)

How to Enable

Protos Library

عملکرد توضیحات برو سی++ جاوا پایتون سی
proto.getExt Gets proto2 extension field, or default if unset.

Signatures:
proto.getExt(msg, extName) -> T

Examples:
proto.getExt(msg, google.api.expr.test.int32_ext)
(v0.13.0) (v0.10.0) (v0.2.0) (v0.1.1)
proto.hasExt Checks if proto2 extension field is set.

Signatures:
proto.hasExt(msg, extName) -> bool

Examples:
proto.hasExt(msg, google.api.expr.test.int32_ext)
(v0.13.0) (v0.10.0) (v0.2.0) (v0.1.1)

How to Enable

Lists Library

عملکرد توضیحات برو سی++ جاوا پایتون سی
distinct Returns distinct elements.

Signatures:
list.distinct() -> list

Examples:
[1, 2, 2].distinct() // [1, 2]
(v0.22.0) (v0.11.0) (v0.11.0) (v0.1.1)
flatten Flattens nested lists.

Signatures:
list.flatten([depth]) -> list

Examples:
[[1], [2, 3]].flatten() // [1, 2, 3]
(v0.22.0) (v0.11.0) (v0.7.1) (v0.1.1)
lists.range Returns list of integers [0, ..., n-1] .

Signatures:
lists.range(int) -> list(int)

Examples:
lists.range(3) // [0, 1, 2]
(v0.22.0) (v0.11.0) (v0.10.1) (v0.1.1)
reverse Reverses the list.

Signatures:
list.reverse() -> list

Examples:
[1, 2].reverse() // [2, 1]
(v0.22.0) (v0.11.0) (v0.11.0) (v0.1.1)
slice Returns sub-list (start inclusive, end exclusive).

Signatures:
list.slice(start, end) -> list

Examples:
[1, 2, 3].slice(1, 3) // [2, 3]
(v0.17.0) (v0.11.0) (v0.11.0) (v0.1.1)
sort Sorts list of comparable elements.

Signatures:
list.sort() -> list

Examples:
[3, 1, 2].sort() // [1, 2, 3]
(v0.22.0) (v0.11.0) (v0.11.0) (v0.1.1)
sortBy Sorts list by key evaluated from expression.

Signatures:
list.sortBy(var, expr) -> list

Examples:
[{"val": 2}, {"val": 1}].sortBy(x, x.val) // [{"val": 1}, {"val": 2}]
(v0.22.0) (v0.11.0) (v0.11.0) (v0.1.1)
first Returns first element as optional. Requires the Optional extension.

Signatures:
list.first() -> optional

Examples:
[1, 2].first() // optional(1)
(v0.23.0) (v0.15.0) (v0.11.0) (v0.1.2)
last Returns last element as optional. Requires the Optional extension.

Signatures:
list.last() -> optional

Examples:
[1, 2].last() // optional(2)
(v0.23.0) (v0.15.0) (v0.11.0) (v0.1.2)

How to Enable

Sets Library

عملکرد توضیحات برو سی++ جاوا پایتون سی
sets.contains Checks if list1 contains all elements of list2.

Signatures:
sets.contains(list1, list2) -> bool

Examples:
sets.contains([1, 2], [1]) // true
(v0.15.0) (v0.10.0) (v0.6.0) (v0.1.1)
sets.equivalent Checks if lists are set-equivalent (contain same unique elements).

Signatures:
sets.equivalent(list1, list2) -> bool

Examples:
sets.equivalent([1, 2], [2, 1, 1]) // true
(v0.15.0) (v0.10.0) (v0.6.0) (v0.1.1)
sets.intersects Checks if lists share at least one element.

Signatures:
sets.intersects(list1, list2) -> bool

Examples:
sets.intersects([1, 2], [2, 3]) // true
(v0.15.0) (v0.10.0) (v0.6.0) (v0.1.1)

How to Enable

Strings Library

عملکرد توضیحات برو سی++ جاوا پایتون سی
charAt Returns character at index.

Signatures:
string.charAt(int) -> string

Examples:
"hello".charAt(1) // "e"
(v0.4.0) (v0.10.0) (v0.2.0) (v0.1.1)
indexOf Returns index of first occurrence of substring, or -1.

Signatures:
string.indexOf(substr, [start]) -> int

Examples:
"hello".indexOf("l") // 2
(v0.4.0) (v0.10.0) (v0.2.0) (v0.1.1)
lastIndexOf Returns index of last occurrence of substring, or -1.

Signatures:
string.lastIndexOf(substr, [end]) -> int

Examples:
"hello".lastIndexOf("l") // 3
(v0.4.0) (v0.10.0) (v0.2.0) (v0.1.1)
join Concatenates strings.

Signatures:
list(string).join([separator]) -> string

Examples:
["a", "b"].join("-") // "ab"
(v0.10.0) (v0.10.0) (v0.2.0) (v0.1.1)
split Splits string by separator.

Signatures:
string.split(separator, [limit]) -> list(string)

Examples:
"ab".split("-") // ["a", "b"]
(v0.4.0) (v0.10.0) (v0.2.0) (v0.1.1)
substring Returns substring (start inclusive, end exclusive).

Signatures:
string.substring(start, [end]) -> string

Examples:
"hello".substring(1, 3) // "el"
(v0.4.0) (v0.10.0) (v0.2.0) (v0.1.1)
trim Trims Unicode whitespace.

Signatures:
string.trim() -> string

Examples:
" hello ".trim() // "hello"
(v0.4.0) (v0.10.0) (v0.2.0) (v0.1.1)
replace Replaces occurrences of old with new.

Signatures:
string.replace(old, new, [limit]) -> string

Examples:
"hello".replace("l", "w") // "hewwo"
(v0.4.0) (v0.10.0) (v0.2.0) (v0.1.1)
reverse Reverses Unicode code points.

Signatures:
string.reverse() -> string

Examples:
"abc".reverse() // "cba"
(v0.18.0) (v0.14.0) (v0.13.0) (v0.1.1)
lowerAscii Converts ASCII characters to lowercase.

Signatures:
string.lowerAscii() -> string

Examples:
"Hello".lowerAscii() // "hello"
(v0.6.0) (v0.11.0) (v0.2.0) (v0.1.1)
upperAscii Converts ASCII characters to uppercase.

Signatures:
string.upperAscii() -> string

Examples:
"Hello".upperAscii() // "HELLO"
(v0.6.0) (v0.11.0) (v0.2.0) (v0.1.1)
quote Escapes string for safe printing.

Signatures:
strings.quote(string) -> string

Examples:
strings.quote("a\tb") // "\"a\\tb\""
(v0.14.0) (v0.14.0) (v0.13.0) (v0.1.1)
format Formats the string using printf-style placeholders.

Signatures:
string.format(list) -> string

Examples:
"str: %s, int: %d".format(["a", 1]) // "str: a, int: 1"
(v0.14.0) (v0.11.0) (v0.1.1)

How to Enable

Regular Expression Library

عملکرد توضیحات برو سی++ جاوا پایتون سی
regex.replace Replaces matches with replacement string (supports backreferences).

Signatures:
regex.replace(target, pat, repl, [limit]) -> string

Examples:
regex.replace("123-456", r"(\d+)-(\d+)", r"\2-\1") // "456-123"
(v0.25.1) (v0.13.0) (v0.10.1) (v0.1.1)
regex.extract Returns first match of pattern (must have one capture group).

Signatures:
regex.extract(target, pat) -> optional(string)

Examples:
regex.extract("a123b", r"(\d+)") // optional("123")
(v0.25.1) (v0.13.0) (v0.10.1) (v0.1.1)
regex.extractAll Returns all matches of pattern (must have one capture group).

Signatures:
regex.extractAll(target, pat) -> list(string)

Examples:
regex.extractAll("a1b2", r"(\d+)") // ["1", "2"]
(v0.25.1) (v0.13.0) (v0.10.1) (v0.1.1)

How to Enable

Two-Variable Comprehensions

ماکرو توضیحات برو سی++ جاوا پایتون سی
all Short-circuiting logical AND over key/index and value.

Signatures:
list.all(i, v, pred) -> bool
map.all(k, v, pred) -> bool

Examples:
[1, 2].all(i, v, v > 0) // true
(v0.22.0) (v0.14.0) (v0.11.0) (v0.1.1)
exists Short-circuiting logical OR over key/index and value.

Signatures:
list.exists(i, v, pred) -> bool
map.exists(k, v, pred) -> bool

Examples:
[1, 2].exists(i, v, v == 2) // true
(v0.22.0) (v0.14.0) (v0.11.0) (v0.1.1)
existsOne Checks if exactly one pair satisfies predicate.

Signatures:
list.existsOne(i, v, pred) -> bool
map.existsOne(k, v, pred) -> bool

Examples:
[1, 2].existsOne(i, v, v == 2) // true
(v0.22.0) (v0.14.0) (v0.11.0) (v0.1.1)
transformList Transforms/filters list/map into a list.

Signatures:
list.transformList(i, v, [filter], transform) -> list
map.transformList(k, v, [filter], transform) -> list

Examples:
[1, 2].transformList(i, v, v * 2) // [2, 4]
(v0.22.0) (v0.14.0) (v0.11.0) (v0.1.1)
transformMap Transforms values of list/map into a map (keys remain fixed).

Signatures:
list.transformMap(i, v, [filter], transform) -> map
map.transformMap(k, v, [filter], transform) -> map

Examples:
[1, 2].transformMap(i, v, v * 2) // {0: 2, 1: 4}
(v0.22.0) (v0.14.0) (v0.11.0) (v0.1.1)
transformMapEntry Transforms into a map.

Signatures:
list.transformMapEntry(i, v, [filter], transform_entry) -> map
map.transformMapEntry(k, v, [filter], transform_entry) -> map

Examples:
[1, 2].transformMapEntry(i, v, {string(v): v * 2}) // {"1": 2, "2": 4}
(v0.22.0) (v0.14.0) (v0.11.0) (v0.1.1)

How to Enable

Native Types Library

ویژگی توضیحات برو سی++ جاوا پایتون سی
Native Structs Registering and instantiating host native types (Go structs / Java POJOs) in CEL.

Examples:
Account{id: 123} (Java POJO instanced in CEL)
(v0.13.0) (v0.13.0)

How to Enable

Network Library

The Network library provides functions for parsing, validating, and manipulating IP addresses and CIDR blocks.

عملکرد توضیحات برو سی++ جاوا پایتون سی
ip Parses a string into an IP address, or extracts the IP from a CIDR.

Signatures:
ip(string) -> IP
CIDR.ip() -> IP

Examples:
ip("192.168.0.1")
cidr("192.168.0.0/24").ip()
(v0.29.0)
isIP Checks if a string is a valid IP address.

Signatures:
isIP(string) -> bool

Examples:
isIP("192.168.0.1") // true
(v0.29.0)
ip.isCanonical Checks if an IP address string is in its canonical format.

Signatures:
ip.isCanonical(string) -> bool

Examples:
ip.isCanonical("192.168.0.1") // true
(v0.29.0)
cidr Parses a string into a CIDR block.

Signatures:
cidr(string) -> CIDR

Examples:
cidr("192.168.0.0/24")
(v0.29.0)
isCIDR Checks if a string is a valid CIDR block.

Signatures:
isCIDR(string) -> bool

Examples:
isCIDR("192.168.0.0/24") // true
(v0.29.0)
containsIP Checks if a CIDR block contains an IP address.

Signatures:
CIDR.containsIP(IP) -> bool
CIDR.containsIP(string) -> bool

Examples:
cidr("192.168.0.0/24").containsIP(ip("192.168.0.1")) // true
(v0.29.0)
containsCIDR Checks if a CIDR block contains another CIDR block.

Signatures:
CIDR.containsCIDR(CIDR) -> bool
CIDR.containsCIDR(string) -> bool

Examples:
cidr("192.168.0.0/16").containsCIDR(cidr("192.168.1.0/24")) // true
(v0.29.0)
family Returns the IP family (4 for IPv4, 6 for IPv6).

Signatures:
IP.family() -> int

Examples:
ip("192.168.0.1").family() // 4
(v0.29.0)
isGlobalUnicast Checks if the IP is a global unicast address.

Signatures:
IP.isGlobalUnicast() -> bool

Examples:
ip("192.168.0.1").isGlobalUnicast() // true
(v0.29.0)
isLinkLocalMulticast Checks if the IP is a link-local multicast address.

Signatures:
IP.isLinkLocalMulticast() -> bool

Examples:
ip("224.0.0.1").isLinkLocalMulticast() // true
(v0.29.0)
isLinkLocalUnicast Checks if the IP is a link-local unicast address.

Signatures:
IP.isLinkLocalUnicast() -> bool

Examples:
ip("169.254.0.1").isLinkLocalUnicast() // true
(v0.29.0)
isLoopback Checks if the IP is a loopback address.

Signatures:
IP.isLoopback() -> bool

Examples:
ip("127.0.0.1").isLoopback() // true
(v0.29.0)
isMask Checks if the CIDR is a valid subnet mask.

Signatures:
CIDR.isMask() -> bool

Examples:
cidr("255.255.255.0/24").isMask() // true
(v0.29.0)
isUnspecified Checks if the IP is an unspecified address (eg 0.0.0.0 ).

Signatures:
IP.isUnspecified() -> bool

Examples:
ip("0.0.0.0").isUnspecified() // true
(v0.29.0)
masked Returns the masked CIDR block.

Signatures:
CIDR.masked() -> CIDR

Examples:
cidr("192.168.0.1/24").masked() // 192.168.0.0/24
(v0.29.0)
prefixLength Returns the prefix length of the CIDR block.

Signatures:
CIDR.prefixLength() -> int

Examples:
cidr("192.168.0.0/24").prefixLength() // 24
(v0.29.0)
string Converts IP or CIDR to string.

Signatures:
string(IP) -> string
string(CIDR) -> string

Examples:
string(ip("192.168.0.1")) // "192.168.0.1"
(v0.29.0)

How to Enable

  • Go: Pass ext.Network() to cel.NewEnv() .
  • C++: Not supported.
  • Java: Not supported.
  • Python: Not supported.

JWT Library

The JWT library provides data types and helper functions for parsing JSON Web Tokens (JWT) and inspecting standard and custom claims.

عملکرد توضیحات برو سی++ جاوا پایتون سی
jwt.parse Parses a raw token string into a structured jwt.Token wrapped in an optional.

Signatures:
jwt.parse(string) -> optional(jwt.Token)

Examples:
jwt.parse(token_string).hasValue()
(v0.32.0)
claim Queries a custom claim value by key name from the token payload.

Signatures:
jwt.Token.claim(string) -> optional(dyn)
optional(jwt.Token).claim(string) -> optional(dyn)

Examples:
jwt.parse(token).claim("tenant").orValue("")
(v0.32.0)
presentedBy Validates that the token's issuer and audience match expected values.

Signatures:
jwt.Token.presentedBy(string, string) -> bool
optional(jwt.Token).presentedBy(string, string) -> bool

Examples:
jwt.parse(token).presentedBy("https://auth.example.com", "https://api.example.com")
(v0.32.0)

How to Enable

  • Go: Import cel.dev/cel-go/ext/security/jwt and pass jwt.Library() to cel.NewEnv() .
  • C++: Not supported.
  • Java: Not supported.
  • Python: Not supported.

HMAC Library

The HMAC library provides cryptographic functions to compute and verify Hash-based Message Authentication Codes (HMAC) over strings and byte sequences.

عملکرد توضیحات برو سی++ جاوا پایتون سی
hmac.compute Computes raw HMAC signature bytes using the specified algorithm and secret key.

Signatures:
hmac.compute(string, string|bytes, string|bytes) -> bytes

Examples:
hmac.compute(hmac.SHA256, "secret", "message")
(v0.32.0)
hmac.verify Verifies whether an HMAC signature matches the expected digest.

Signatures:
hmac.verify(string, string|bytes, string|bytes, string|bytes) -> bool

Examples:
hmac.verify(hmac.SHA256, secret, msg, expected_sig) // true
(v0.32.0)

How to Enable

  • Go: Import cel.dev/cel-go/ext/security/hmac and pass hmac.Library() to cel.NewEnv() .
  • C++: Not supported.
  • Java: Not supported.
  • Python: Not supported.

5. Advanced Features

Advanced Features Summary

ویژگی توضیحات برو سی++ جاوا پایتون سی
Partial Evaluation Evaluate with missing inputs; returns unknowns or a simplified expression. ³
Async Evaluation Non-blocking concurrent execution of extension functions.
AST Validators Static analysis checks on the Checked AST after type-checking.
AST Optimizers AST rewrites (constant folding, inlining, CSE) to improve performance.
CEL Policy Compiler Compiles YAML-based policy structures into standard CEL ASTs.
Formal Verification Proves safety invariants, satisfiability, validity, and AST equivalence. (v0.14.0)

³ Go supports generating a Residual AST (pruned AST). ⁴ C++ and Java support returning UnknownSet / CelUnknownSet at runtime, but do not expose public APIs for residual AST generation. ⁵ Go uses AsyncBinding / AsyncOp returning channels. ⁶ Java uses CelAsyncRuntime returning ListenableFuture .

Partial Evaluation (Unknowns)

Partial evaluation allows evaluating an expression when only a subset of the input variables (arguments) are known. Instead of failing, the evaluation produces a result that indicates what is missing, or a simplified expression.

  • Go: Full support. Allows defining a PartialActivation with patterns of unknown attributes. Evaluation returns a types.Unknown value. Go supports generating a Residual AST ( Env.ResidualAst ) which is a pruned, simplified AST containing only the parts of the expression that could not be evaluated.
  • C++: Supports Unknown values. Unknown attribute patterns are configured via Activation::set_unknown_attribute_patterns . Evaluation returns an UnknownSet . Public API does not currently expose residual AST generation.
  • Java: Supports partial evaluation via PartialVars passed to Program.eval() . Evaluation returns a CelUnknownSet . Public API does not currently expose residual AST generation.
  • Python / C: No native support.

Async Evaluation

Async evaluation allows CEL expressions to call functions that execute asynchronously (eg, making RPCs or database queries) and block evaluation until the results are available, without blocking the main execution thread.

  • Go: Supports asynchronous function overloads via AsyncBinding and AsyncOp . Async functions return a Go channel ( <-chan ref.Val ), and the interpreter manages the concurrent execution and synchronization.
  • Java: Supports async evaluation via CelAsyncRuntime and AsyncProgram . It uses ListenableFuture to represent pending values and automatically drives evaluation to completion as futures resolve.
  • C++ / Python / C: No built-in support.

AST Validators

Validators perform static analysis on the Checked AST after type-checking to enforce domain-specific constraints before the program is executed.

  • Go: Supports ASTValidator interface. Canonical validators include cel.validator.duration , cel.validator.timestamp , cel.validator.matches (regex), cel.validator.homogeneous_literals , and cel.validator.comprehension_nesting_limit .
  • C++: Supports cel::Validator . Canonical validations include AstDepthValidator , ComprehensionNestingLimitValidator , DurationLiteralValidator , HomogeneousLiteralValidator , MatchesValidator , and TimestampLiteralValidator .
  • Java: Supports CelValidator and CelAstValidator . Canonical validators include AstDepthLimitValidator , ComprehensionNestingLimitValidator , DurationLiteralValidator , HomogeneousLiteralValidator , RegexLiteralValidator , and TimestampLiteralValidator .
  • Python / C: No direct support.

AST Optimizers

Optimizers rewrite the AST to improve execution performance. Optimizers fall into one of two categories: static and runtime optimizers. C++, Java, and Go support runtime optimization. CEL Java and Go also support static optimizers.

Typical optimizations include constant folding (pre-evaluating sub-expressions with constant inputs) and common subexpression elimination (CSE).

  • Go: Supports AST folding during compilation/planning.
  • C++: Supports constant folding via the cel::extensions::EnableConstantFolding extension at plan time.
  • Java: Supports CelOptimizer interface. Canonical optimizers include ConstantFoldingOptimizer (which supports pre-order traversal, Protobuf message constant folding, and aggregate or optional pruning), InliningOptimizer , and SubexpressionOptimizer (CSE).
  • Python / C: No direct support.

CEL Policy Compiler

CEL Policy is a YAML-based format for composing multiple CEL expressions together with variables, match blocks, conditional outputs, and nested rules. It is designed for complex policy engines (like Kubernetes Admission Control) where single CEL expressions would become unreadable.

For the formal language definition, syntax, and conformance suite, refer to the CEL Policy Specification .

The Policy Compiler compiles these YAML policies into a single standard CEL AST, meaning they are fully compatible with standard CEL runtimes and inherit all performance and safety guarantees.

  • Go: Supported via Go policy (including aggregate rule evaluation semantics).
  • C++: Supported via C++ policy .
  • Java: Supported via Java policy (including aggregate rule evaluation semantics and shorthand type specifiers in policy configs).
  • Python / C: Not directly supported.

Formal Verification Framework

The Formal Verification framework allows users to mathematically prove safety invariants, logical equivalence, satisfiability, and validity across CEL expressions and structured CEL Policies.

  • Java: Supported via the CEL Java Verifier ( dev.cel:verifier and dev.cel:verifier-cli ). Capabilities include satisfiability ( isSatisfiable ) with witness input generation, validity ( isAlwaysTrue ) with counterexample generation, bounded model checking (BMC) for comprehensions, logical equivalence proofs across ASTs, and custom assume / assert policy invariant verification.
  • Go / C++ / Python / C: Are supported indirectly via the Java command line toolchain.

For an introduction and real-world examples, see the Google Open Source blog post: Securing the agentic era: Introducing formal verification for CEL .

،

This document serves as the unified API Doc reference for the Common Expression Language (CEL). It lists all macros, operators, and standard functions, indicating their signatures, behaviors, and support status across the official CEL stacks.

For more details on language behavior and specifications, refer to the CEL Language Definition .

Stack Versions

This reference document is based on the following versions of the CEL stacks:

  • CEL Go : v0.32.0 (and newer)
  • CEL C++ : v0.16.1
  • CEL Java : v0.14.0
  • CEL Python : v0.1.3
  • CEL C : Development snapshot (unreleased)

GitHub Mirrors

The official implementations of CEL are mirrored on GitHub under the cel-expr organization:


1. Core Macros

These are built-in macros that are expanded at compile time.

ماکرو توضیحات برو سی++ جاوا پایتون سی
has(container.field) Tests whether a field is present in a message, or a key in a map.

Signatures:
has(container.field) -> bool

Examples:
has(request.auth.claims.email)
list.all(var, predicate) Tests whether all elements in a list satisfy a predicate.

Signatures:
list.all(var, predicate) -> bool

Examples:
[1, 2, 3].all(x, x > 0) // true
¹
list.exists(var, predicate) Tests whether at least one element in a list satisfies a predicate.

Signatures:
list.exists(var, predicate) -> bool

Examples:
[1, 2, 3].exists(x, x > 2) // true
¹
list.exists_one(var, predicate) Tests whether exactly one element in a list satisfies a predicate.

Signatures:
list.exists_one(var, predicate) -> bool

Examples:
[1, 2, 3].exists_one(x, x == 2) // true
¹
list.filter(var, predicate) Filters elements of a list according to a predicate.

Signatures:
list.filter(var, predicate) -> list

Examples:
[1, 2, 3].filter(x, x > 1) // [2, 3]
¹
list.map(var, transform) Transforms each element of a list using an expression.

Signatures:
list.map(var, transform) -> list

Examples:
[1, 2, 3].map(x, x * 2) // [2, 4, 6]
¹
list.map(var, filter, transform) Transforms elements of a list that satisfy a filter predicate.

Signatures:
list.map(var, filter, transform) -> list

Examples:
[1, 2, 3].map(x, x > 1, x * 2) // [4, 6]
¹

¹ Supported in C runtime because macros are expanded into comprehensions during compilation by the host compiler.


2. Core Operators

اپراتور توضیحات برو سی++ جاوا پایتون سی
Arithmetic ( + , - , * , / , % ) Standard arithmetic operations. Negation ( -x ) and Identity ( +x ). List concatenation ( list + list ) is supported in Go, C++, Java, and Python.

Signatures:
T + T -> T
T - T -> T
T * T -> T
T / T -> T
T % T -> T
-T -> T
+T -> T
list + list -> list

Examples:
1 + 2 * 3 // 7
[1] + [2] // [1, 2]
²
Comparison ( == , != , < , <= , > , >= ) Standard comparison. Numeric comparisons are heterogeneous (eg 1 == 1.0 ).

Signatures:
T == T -> bool
T != T -> bool
T < T -> bool
T <= T -> bool
T > T -> bool
T >= T -> bool

Examples:
x < 42.0
1 == 1.0 // true
Logical ( ! , && , || , ? : ) Logical NOT, AND, OR, and Ternary Conditional. AND/OR use short-circuit evaluation.

Signatures:
!bool -> bool
bool && bool -> bool
bool || bool -> bool
bool ? T : T -> T

Examples:
x > 0 ? "positive" : "non-positive"
Indexing ( [] ) Access element of a list by index, or lookup key in a map.

Signatures:
list[int] -> T
map[K] -> V

Examples:
tags[0]
users['john']
Membership ( in ) Check if element is in a list, or key is in a map.

Signatures:
T in list -> bool
K in map -> bool

Examples:
'admin' in roles

² List concatenation ( list + list ) is not supported in the C runtime, though other arithmetic operators are supported.


3. Core Functions

General & String Functions

عملکرد توضیحات برو سی++ جاوا پایتون سی
size Returns the size of a string (characters), bytes, list, or map.

Signatures:
size(T) -> int (where T is string , bytes , list , or map )

Examples:
size("hello") // 5
contains Returns whether string contains substring.

Signatures:
string.contains(string) -> bool

Examples:
"hello".contains("ell") // true
startsWith Returns whether string starts with prefix.

Signatures:
string.startsWith(string) -> bool

Examples:
"hello".startsWith("he") // true
endsWith Returns whether string ends with suffix.

Signatures:
string.endsWith(string) -> bool

Examples:
"hello".endsWith("lo") // true
matches Returns whether string matches RE2 regular expression.

Signatures:
string.matches(string) -> bool

Examples:
"123".matches(r"^\d+$") // true

Date and Time Selector Functions

These functions extract components from google.protobuf.Timestamp or google.protobuf.Duration .

عملکرد توضیحات برو سی++ جاوا پایتون سی
getFullYear Returns the 4-digit year.

Signatures:
timestamp.getFullYear([tz]) -> int

Examples:
timestamp("2026-07-23T00:00:00Z").getFullYear() // 2026
getMonth Returns the month (0-11).

Signatures:
timestamp.getMonth([tz]) -> int

Examples:
timestamp("2026-07-23T00:00:00Z").getMonth() // 6
getDayOfMonth Returns the day of the month (1-31).

Signatures:
timestamp.getDayOfMonth([tz]) -> int

Examples:
timestamp("2026-07-23T00:00:00Z").getDayOfMonth() // 23
getDayOfWeek Returns the day of the week (0 = Sunday).

Signatures:
timestamp.getDayOfWeek([tz]) -> int

Examples:
timestamp("2026-07-23T00:00:00Z").getDayOfWeek() // 4
getDayOfYear Returns the day of the year (0-365).

Signatures:
timestamp.getDayOfYear([tz]) -> int

Examples:
timestamp("2026-07-23T00:00:00Z").getDayOfYear() // 203
getHours Returns the hours (0-23).

Signatures:
timestamp.getHours([tz]) -> int
duration.getHours() -> int

Examples:
duration("1h30m").getHours() // 1
getMinutes Returns the minutes (0-59).

Signatures:
timestamp.getMinutes([tz]) -> int
duration.getMinutes() -> int

Examples:
duration("1h30m").getMinutes() // 30
getSeconds Returns the seconds (0-59).

Signatures:
timestamp.getSeconds([tz]) -> int
duration.getSeconds() -> int

Examples:
duration("1h30m45s").getSeconds() // 45
getMilliseconds Returns the milliseconds (0-999).

Signatures:
timestamp.getMilliseconds([tz]) -> int
duration.getMilliseconds() -> int

Examples:
duration("1.5s").getMilliseconds() // 500

Type Conversions

Target Type توضیحات برو سی++ جاوا پایتون سی
bool Converts to boolean.

Signatures:
bool(bool) -> bool
bool(string) -> bool

Examples:
bool("true") // true
bytes Converts to bytes.

Signatures:
bytes(bytes) -> bytes
bytes(string) -> bytes

Examples:
bytes("hello") // b"hello"
double Converts to double-precision float.

Signatures:
double(double) -> double
double(int) -> double
double(uint) -> double
double(string) -> double

Examples:
double(1) // 1.0
duration Converts to duration.

Signatures:
duration(duration) -> duration
duration(string) -> duration

Examples:
duration("1.5s") // 1.5s duration
int Converts to 64-bit signed integer.

Signatures:
int(int) -> int
int(uint) -> int
int(double) -> int (rounds to zero)
int(string) -> int
int(timestamp) -> int (seconds since epoch)

Examples:
int(1.5) // 1
string Converts to string.

Signatures:
string(T) -> string (supports bool , int , uint , double , bytes , timestamp , duration )

Examples:
string(1.5) // "1.5"
timestamp Converts to timestamp.

Signatures:
timestamp(timestamp) -> timestamp
timestamp(string) -> timestamp (RFC3339)

Examples:
timestamp("2026-07-23T00:00:00Z")
uint Converts to 64-bit unsigned integer.

Signatures:
uint(uint) -> uint
uint(int) -> uint
uint(double) -> uint
uint(string) -> uint

Examples:
uint(1) // 1u
dyn Casts value to dynamic type for type-checking.

Signatures:
dyn(T) -> dyn

Examples:
dyn([1, "two"])
type Returns the type of the value.

Signatures:
type(T) -> type

Examples:
type(1) // int

4. Extensions (Libraries)

Bindings Library

عملکرد توضیحات برو سی++ جاوا پایتون سی
cel.bind Binds a local variable to avoid duplicate evaluation.

Signatures:
cel.bind(varName, initExpr, resultExpr) -> T

Examples:
cel.bind(x, a + b, x * x)
(v0.15.0) (v0.10.0) (v0.2.0) (v0.1.1)

How to Enable

Encoders Library

عملکرد توضیحات برو سی++ جاوا پایتون سی
base64.encode Encodes bytes to base64 string.

Signatures:
base64.encode(bytes) -> string

Examples:
base64.encode(b"hello") // "aGVsbG8="
(v0.6.0) (v0.10.0) (v0.2.0) (v0.1.1)
base64.decode Decodes base64 string to bytes. Throws error on invalid input.

Signatures:
base64.decode(string) -> bytes

Examples:
base64.decode("aGVsbG8=") // b"hello"
(v0.6.0) (v0.10.0) (v0.2.0) (v0.1.1)
json.encode Serializes a CEL value to JSON string.

Signatures:
json.encode(dyn) -> string

Examples:
json.encode([1, 2]) // "[1,2]"
(v0.29.0)

How to Enable

Math Library

عملکرد توضیحات برو سی++ جاوا پایتون سی
math.greatest Returns greatest of numeric arguments (or list of numerics).

Signatures:
math.greatest(arg, ...) -> T

Examples:
math.greatest(1, 3, 2) // 3
(v0.13.0) (v0.10.0) (v0.2.0) (v0.1.1)
math.least Returns least of numeric arguments (or list of numerics).

Signatures:
math.least(arg, ...) -> T

Examples:
math.least([1, 3, 2]) // 1
(v0.13.0) (v0.10.0) (v0.2.0) (v0.1.1)
math.abs Absolute value.

Signatures:
math.abs(T) -> T (supports int , uint , double )

Examples:
math.abs(-1) // 1
(v0.21.0) (v0.11.0) (v0.10.1) (v0.1.1)
math.sqrt Square root.

Signatures:
math.sqrt(T) -> double (supports int , uint , double )

Examples:
math.sqrt(9) // 3.0
(v0.25.1) (v0.12.0) (v0.11.0) (v0.1.1)
math.bitAnd Bitwise AND.

Signatures:
math.bitAnd(T, T) -> T (supports int , uint )

Examples:
math.bitAnd(5, 3) // 1
(v0.21.0) (v0.11.0) (v0.10.1) (v0.1.1)
math.bitOr Bitwise OR.

Signatures:
math.bitOr(T, T) -> T (supports int , uint )

Examples:
math.bitOr(5, 3) // 7
(v0.21.0) (v0.11.0) (v0.10.1) (v0.1.1)
math.bitXor Bitwise XOR.

Signatures:
math.bitXor(T, T) -> T (supports int , uint )

Examples:
math.bitXor(5, 3) // 6
(v0.21.0) (v0.11.0) (v0.10.1) (v0.1.1)
math.bitNot Bitwise NOT.

Signatures:
math.bitNot(T) -> T (supports int , uint )

Examples:
math.bitNot(1) // -2
(v0.21.0) (v0.11.0) (v0.10.1) (v0.1.1)
math.bitShiftLeft Bitwise shift left.

Signatures:
math.bitShiftLeft(T, int) -> T (supports int , uint )

Examples:
math.bitShiftLeft(1, 2) // 4
(v0.21.0) (v0.11.0) (v0.10.1) (v0.1.1)
math.bitShiftRight Bitwise shift right.

Signatures:
math.bitShiftRight(T, int) -> T (supports int , uint )

Examples:
math.bitShiftRight(4, 2) // 1
(v0.21.0) (v0.11.0) (v0.10.1) (v0.1.1)
math.ceil Ceiling rounding.

Signatures:
math.ceil(double) -> double

Examples:
math.ceil(1.2) // 2.0
(v0.21.0) (v0.11.0) (v0.10.1) (v0.1.1)
math.floor Floor rounding.

Signatures:
math.floor(double) -> double

Examples:
math.floor(1.8) // 1.0
(v0.21.0) (v0.11.0) (v0.10.1) (v0.1.1)
math.round Nearest integer rounding.

Signatures:
math.round(double) -> double

Examples:
math.round(1.5) // 2.0
(v0.21.0) (v0.11.0) (v0.10.1) (v0.1.1)
math.trunc Truncation rounding (towards zero).

Signatures:
math.trunc(double) -> double

Examples:
math.trunc(-1.8) // -1.0
(v0.21.0) (v0.11.0) (v0.10.1) (v0.1.1)
math.isInf Checks if double is positive or negative infinity.

Signatures:
math.isInf(double) -> bool

Examples:
math.isInf(1.0/0.0) // true
(v0.21.0) (v0.11.0) (v0.10.1) (v0.1.1)
math.isNaN Checks if double is NaN.

Signatures:
math.isNaN(double) -> bool

Examples:
math.isNaN(0.0/0.0) // true
(v0.21.0) (v0.11.0) (v0.10.1) (v0.1.1)
math.isFinite Checks if double is finite.

Signatures:
math.isFinite(double) -> bool

Examples:
math.isFinite(1.2) // true
(v0.21.0) (v0.11.0) (v0.10.1) (v0.1.1)
math.sign Returns sign of value (-1, 0, or 1).

Signatures:
math.sign(T) -> T (supports int , uint , double )

Examples:
math.sign(-42) // -1
(v0.21.0) (v0.11.0) (v0.10.1) (v0.1.1)

How to Enable

Protos Library

عملکرد توضیحات برو سی++ جاوا پایتون سی
proto.getExt Gets proto2 extension field, or default if unset.

Signatures:
proto.getExt(msg, extName) -> T

Examples:
proto.getExt(msg, google.api.expr.test.int32_ext)
(v0.13.0) (v0.10.0) (v0.2.0) (v0.1.1)
proto.hasExt Checks if proto2 extension field is set.

Signatures:
proto.hasExt(msg, extName) -> bool

Examples:
proto.hasExt(msg, google.api.expr.test.int32_ext)
(v0.13.0) (v0.10.0) (v0.2.0) (v0.1.1)

How to Enable

Lists Library

عملکرد توضیحات برو سی++ جاوا پایتون سی
distinct Returns distinct elements.

Signatures:
list.distinct() -> list

Examples:
[1, 2, 2].distinct() // [1, 2]
(v0.22.0) (v0.11.0) (v0.11.0) (v0.1.1)
flatten Flattens nested lists.

Signatures:
list.flatten([depth]) -> list

Examples:
[[1], [2, 3]].flatten() // [1, 2, 3]
(v0.22.0) (v0.11.0) (v0.7.1) (v0.1.1)
lists.range Returns list of integers [0, ..., n-1] .

Signatures:
lists.range(int) -> list(int)

Examples:
lists.range(3) // [0, 1, 2]
(v0.22.0) (v0.11.0) (v0.10.1) (v0.1.1)
reverse Reverses the list.

Signatures:
list.reverse() -> list

Examples:
[1, 2].reverse() // [2, 1]
(v0.22.0) (v0.11.0) (v0.11.0) (v0.1.1)
slice Returns sub-list (start inclusive, end exclusive).

Signatures:
list.slice(start, end) -> list

Examples:
[1, 2, 3].slice(1, 3) // [2, 3]
(v0.17.0) (v0.11.0) (v0.11.0) (v0.1.1)
sort Sorts list of comparable elements.

Signatures:
list.sort() -> list

Examples:
[3, 1, 2].sort() // [1, 2, 3]
(v0.22.0) (v0.11.0) (v0.11.0) (v0.1.1)
sortBy Sorts list by key evaluated from expression.

Signatures:
list.sortBy(var, expr) -> list

Examples:
[{"val": 2}, {"val": 1}].sortBy(x, x.val) // [{"val": 1}, {"val": 2}]
(v0.22.0) (v0.11.0) (v0.11.0) (v0.1.1)
first Returns first element as optional. Requires the Optional extension.

Signatures:
list.first() -> optional

Examples:
[1, 2].first() // optional(1)
(v0.23.0) (v0.15.0) (v0.11.0) (v0.1.2)
last Returns last element as optional. Requires the Optional extension.

Signatures:
list.last() -> optional

Examples:
[1, 2].last() // optional(2)
(v0.23.0) (v0.15.0) (v0.11.0) (v0.1.2)

How to Enable

Sets Library

عملکرد توضیحات برو سی++ جاوا پایتون سی
sets.contains Checks if list1 contains all elements of list2.

Signatures:
sets.contains(list1, list2) -> bool

Examples:
sets.contains([1, 2], [1]) // true
(v0.15.0) (v0.10.0) (v0.6.0) (v0.1.1)
sets.equivalent Checks if lists are set-equivalent (contain same unique elements).

Signatures:
sets.equivalent(list1, list2) -> bool

Examples:
sets.equivalent([1, 2], [2, 1, 1]) // true
(v0.15.0) (v0.10.0) (v0.6.0) (v0.1.1)
sets.intersects Checks if lists share at least one element.

Signatures:
sets.intersects(list1, list2) -> bool

Examples:
sets.intersects([1, 2], [2, 3]) // true
(v0.15.0) (v0.10.0) (v0.6.0) (v0.1.1)

How to Enable

Strings Library

عملکرد توضیحات برو سی++ جاوا پایتون سی
charAt Returns character at index.

Signatures:
string.charAt(int) -> string

Examples:
"hello".charAt(1) // "e"
(v0.4.0) (v0.10.0) (v0.2.0) (v0.1.1)
indexOf Returns index of first occurrence of substring, or -1.

Signatures:
string.indexOf(substr, [start]) -> int

Examples:
"hello".indexOf("l") // 2
(v0.4.0) (v0.10.0) (v0.2.0) (v0.1.1)
lastIndexOf Returns index of last occurrence of substring, or -1.

Signatures:
string.lastIndexOf(substr, [end]) -> int

Examples:
"hello".lastIndexOf("l") // 3
(v0.4.0) (v0.10.0) (v0.2.0) (v0.1.1)
join Concatenates strings.

Signatures:
list(string).join([separator]) -> string

Examples:
["a", "b"].join("-") // "ab"
(v0.10.0) (v0.10.0) (v0.2.0) (v0.1.1)
split Splits string by separator.

Signatures:
string.split(separator, [limit]) -> list(string)

Examples:
"ab".split("-") // ["a", "b"]
(v0.4.0) (v0.10.0) (v0.2.0) (v0.1.1)
substring Returns substring (start inclusive, end exclusive).

Signatures:
string.substring(start, [end]) -> string

Examples:
"hello".substring(1, 3) // "el"
(v0.4.0) (v0.10.0) (v0.2.0) (v0.1.1)
trim Trims Unicode whitespace.

Signatures:
string.trim() -> string

Examples:
" hello ".trim() // "hello"
(v0.4.0) (v0.10.0) (v0.2.0) (v0.1.1)
replace Replaces occurrences of old with new.

Signatures:
string.replace(old, new, [limit]) -> string

Examples:
"hello".replace("l", "w") // "hewwo"
(v0.4.0) (v0.10.0) (v0.2.0) (v0.1.1)
reverse Reverses Unicode code points.

Signatures:
string.reverse() -> string

Examples:
"abc".reverse() // "cba"
(v0.18.0) (v0.14.0) (v0.13.0) (v0.1.1)
lowerAscii Converts ASCII characters to lowercase.

Signatures:
string.lowerAscii() -> string

Examples:
"Hello".lowerAscii() // "hello"
(v0.6.0) (v0.11.0) (v0.2.0) (v0.1.1)
upperAscii Converts ASCII characters to uppercase.

Signatures:
string.upperAscii() -> string

Examples:
"Hello".upperAscii() // "HELLO"
(v0.6.0) (v0.11.0) (v0.2.0) (v0.1.1)
quote Escapes string for safe printing.

Signatures:
strings.quote(string) -> string

Examples:
strings.quote("a\tb") // "\"a\\tb\""
(v0.14.0) (v0.14.0) (v0.13.0) (v0.1.1)
format Formats the string using printf-style placeholders.

Signatures:
string.format(list) -> string

Examples:
"str: %s, int: %d".format(["a", 1]) // "str: a, int: 1"
(v0.14.0) (v0.11.0) (v0.1.1)

How to Enable

Regular Expression Library

عملکرد توضیحات برو سی++ جاوا پایتون سی
regex.replace Replaces matches with replacement string (supports backreferences).

Signatures:
regex.replace(target, pat, repl, [limit]) -> string

Examples:
regex.replace("123-456", r"(\d+)-(\d+)", r"\2-\1") // "456-123"
(v0.25.1) (v0.13.0) (v0.10.1) (v0.1.1)
regex.extract Returns first match of pattern (must have one capture group).

Signatures:
regex.extract(target, pat) -> optional(string)

Examples:
regex.extract("a123b", r"(\d+)") // optional("123")
(v0.25.1) (v0.13.0) (v0.10.1) (v0.1.1)
regex.extractAll Returns all matches of pattern (must have one capture group).

Signatures:
regex.extractAll(target, pat) -> list(string)

Examples:
regex.extractAll("a1b2", r"(\d+)") // ["1", "2"]
(v0.25.1) (v0.13.0) (v0.10.1) (v0.1.1)

How to Enable

Two-Variable Comprehensions

ماکرو توضیحات برو سی++ جاوا پایتون سی
all Short-circuiting logical AND over key/index and value.

Signatures:
list.all(i, v, pred) -> bool
map.all(k, v, pred) -> bool

Examples:
[1, 2].all(i, v, v > 0) // true
(v0.22.0) (v0.14.0) (v0.11.0) (v0.1.1)
exists Short-circuiting logical OR over key/index and value.

Signatures:
list.exists(i, v, pred) -> bool
map.exists(k, v, pred) -> bool

Examples:
[1, 2].exists(i, v, v == 2) // true
(v0.22.0) (v0.14.0) (v0.11.0) (v0.1.1)
existsOne Checks if exactly one pair satisfies predicate.

Signatures:
list.existsOne(i, v, pred) -> bool
map.existsOne(k, v, pred) -> bool

Examples:
[1, 2].existsOne(i, v, v == 2) // true
(v0.22.0) (v0.14.0) (v0.11.0) (v0.1.1)
transformList Transforms/filters list/map into a list.

Signatures:
list.transformList(i, v, [filter], transform) -> list
map.transformList(k, v, [filter], transform) -> list

Examples:
[1, 2].transformList(i, v, v * 2) // [2, 4]
(v0.22.0) (v0.14.0) (v0.11.0) (v0.1.1)
transformMap Transforms values of list/map into a map (keys remain fixed).

Signatures:
list.transformMap(i, v, [filter], transform) -> map
map.transformMap(k, v, [filter], transform) -> map

Examples:
[1, 2].transformMap(i, v, v * 2) // {0: 2, 1: 4}
(v0.22.0) (v0.14.0) (v0.11.0) (v0.1.1)
transformMapEntry Transforms into a map.

Signatures:
list.transformMapEntry(i, v, [filter], transform_entry) -> map
map.transformMapEntry(k, v, [filter], transform_entry) -> map

Examples:
[1, 2].transformMapEntry(i, v, {string(v): v * 2}) // {"1": 2, "2": 4}
(v0.22.0) (v0.14.0) (v0.11.0) (v0.1.1)

How to Enable

Native Types Library

ویژگی توضیحات برو سی++ جاوا پایتون سی
Native Structs Registering and instantiating host native types (Go structs / Java POJOs) in CEL.

Examples:
Account{id: 123} (Java POJO instanced in CEL)
(v0.13.0) (v0.13.0)

How to Enable

Network Library

The Network library provides functions for parsing, validating, and manipulating IP addresses and CIDR blocks.

عملکرد توضیحات برو سی++ جاوا پایتون سی
ip Parses a string into an IP address, or extracts the IP from a CIDR.

Signatures:
ip(string) -> IP
CIDR.ip() -> IP

Examples:
ip("192.168.0.1")
cidr("192.168.0.0/24").ip()
(v0.29.0)
isIP Checks if a string is a valid IP address.

Signatures:
isIP(string) -> bool

Examples:
isIP("192.168.0.1") // true
(v0.29.0)
ip.isCanonical Checks if an IP address string is in its canonical format.

Signatures:
ip.isCanonical(string) -> bool

Examples:
ip.isCanonical("192.168.0.1") // true
(v0.29.0)
cidr Parses a string into a CIDR block.

Signatures:
cidr(string) -> CIDR

Examples:
cidr("192.168.0.0/24")
(v0.29.0)
isCIDR Checks if a string is a valid CIDR block.

Signatures:
isCIDR(string) -> bool

Examples:
isCIDR("192.168.0.0/24") // true
(v0.29.0)
containsIP Checks if a CIDR block contains an IP address.

Signatures:
CIDR.containsIP(IP) -> bool
CIDR.containsIP(string) -> bool

Examples:
cidr("192.168.0.0/24").containsIP(ip("192.168.0.1")) // true
(v0.29.0)
containsCIDR Checks if a CIDR block contains another CIDR block.

Signatures:
CIDR.containsCIDR(CIDR) -> bool
CIDR.containsCIDR(string) -> bool

Examples:
cidr("192.168.0.0/16").containsCIDR(cidr("192.168.1.0/24")) // true
(v0.29.0)
family Returns the IP family (4 for IPv4, 6 for IPv6).

Signatures:
IP.family() -> int

Examples:
ip("192.168.0.1").family() // 4
(v0.29.0)
isGlobalUnicast Checks if the IP is a global unicast address.

Signatures:
IP.isGlobalUnicast() -> bool

Examples:
ip("192.168.0.1").isGlobalUnicast() // true
(v0.29.0)
isLinkLocalMulticast Checks if the IP is a link-local multicast address.

Signatures:
IP.isLinkLocalMulticast() -> bool

Examples:
ip("224.0.0.1").isLinkLocalMulticast() // true
(v0.29.0)
isLinkLocalUnicast Checks if the IP is a link-local unicast address.

Signatures:
IP.isLinkLocalUnicast() -> bool

Examples:
ip("169.254.0.1").isLinkLocalUnicast() // true
(v0.29.0)
isLoopback Checks if the IP is a loopback address.

Signatures:
IP.isLoopback() -> bool

Examples:
ip("127.0.0.1").isLoopback() // true
(v0.29.0)
isMask Checks if the CIDR is a valid subnet mask.

Signatures:
CIDR.isMask() -> bool

Examples:
cidr("255.255.255.0/24").isMask() // true
(v0.29.0)
isUnspecified Checks if the IP is an unspecified address (eg 0.0.0.0 ).

Signatures:
IP.isUnspecified() -> bool

Examples:
ip("0.0.0.0").isUnspecified() // true
(v0.29.0)
masked Returns the masked CIDR block.

Signatures:
CIDR.masked() -> CIDR

Examples:
cidr("192.168.0.1/24").masked() // 192.168.0.0/24
(v0.29.0)
prefixLength Returns the prefix length of the CIDR block.

Signatures:
CIDR.prefixLength() -> int

Examples:
cidr("192.168.0.0/24").prefixLength() // 24
(v0.29.0)
string Converts IP or CIDR to string.

Signatures:
string(IP) -> string
string(CIDR) -> string

Examples:
string(ip("192.168.0.1")) // "192.168.0.1"
(v0.29.0)

How to Enable

  • Go: Pass ext.Network() to cel.NewEnv() .
  • C++: Not supported.
  • Java: Not supported.
  • Python: Not supported.

JWT Library

The JWT library provides data types and helper functions for parsing JSON Web Tokens (JWT) and inspecting standard and custom claims.

عملکرد توضیحات برو سی++ جاوا پایتون سی
jwt.parse Parses a raw token string into a structured jwt.Token wrapped in an optional.

Signatures:
jwt.parse(string) -> optional(jwt.Token)

Examples:
jwt.parse(token_string).hasValue()
(v0.32.0)
claim Queries a custom claim value by key name from the token payload.

Signatures:
jwt.Token.claim(string) -> optional(dyn)
optional(jwt.Token).claim(string) -> optional(dyn)

Examples:
jwt.parse(token).claim("tenant").orValue("")
(v0.32.0)
presentedBy Validates that the token's issuer and audience match expected values.

Signatures:
jwt.Token.presentedBy(string, string) -> bool
optional(jwt.Token).presentedBy(string, string) -> bool

Examples:
jwt.parse(token).presentedBy("https://auth.example.com", "https://api.example.com")
(v0.32.0)

How to Enable

  • Go: Import cel.dev/cel-go/ext/security/jwt and pass jwt.Library() to cel.NewEnv() .
  • C++: Not supported.
  • Java: Not supported.
  • Python: Not supported.

HMAC Library

The HMAC library provides cryptographic functions to compute and verify Hash-based Message Authentication Codes (HMAC) over strings and byte sequences.

عملکرد توضیحات برو سی++ جاوا پایتون سی
hmac.compute Computes raw HMAC signature bytes using the specified algorithm and secret key.

Signatures:
hmac.compute(string, string|bytes, string|bytes) -> bytes

Examples:
hmac.compute(hmac.SHA256, "secret", "message")
(v0.32.0)
hmac.verify Verifies whether an HMAC signature matches the expected digest.

Signatures:
hmac.verify(string, string|bytes, string|bytes, string|bytes) -> bool

Examples:
hmac.verify(hmac.SHA256, secret, msg, expected_sig) // true
(v0.32.0)

How to Enable

  • Go: Import cel.dev/cel-go/ext/security/hmac and pass hmac.Library() to cel.NewEnv() .
  • C++: Not supported.
  • Java: Not supported.
  • Python: Not supported.

5. Advanced Features

Advanced Features Summary

ویژگی توضیحات برو سی++ جاوا پایتون سی
Partial Evaluation Evaluate with missing inputs; returns unknowns or a simplified expression. ³
Async Evaluation Non-blocking concurrent execution of extension functions.
AST Validators Static analysis checks on the Checked AST after type-checking.
AST Optimizers AST rewrites (constant folding, inlining, CSE) to improve performance.
CEL Policy Compiler Compiles YAML-based policy structures into standard CEL ASTs.
Formal Verification Proves safety invariants, satisfiability, validity, and AST equivalence. (v0.14.0)

³ Go supports generating a Residual AST (pruned AST). ⁴ C++ and Java support returning UnknownSet / CelUnknownSet at runtime, but do not expose public APIs for residual AST generation. ⁵ Go uses AsyncBinding / AsyncOp returning channels. ⁶ Java uses CelAsyncRuntime returning ListenableFuture .

Partial Evaluation (Unknowns)

Partial evaluation allows evaluating an expression when only a subset of the input variables (arguments) are known. Instead of failing, the evaluation produces a result that indicates what is missing, or a simplified expression.

  • Go: Full support. Allows defining a PartialActivation with patterns of unknown attributes. Evaluation returns a types.Unknown value. Go supports generating a Residual AST ( Env.ResidualAst ) which is a pruned, simplified AST containing only the parts of the expression that could not be evaluated.
  • C++: Supports Unknown values. Unknown attribute patterns are configured via Activation::set_unknown_attribute_patterns . Evaluation returns an UnknownSet . Public API does not currently expose residual AST generation.
  • Java: Supports partial evaluation via PartialVars passed to Program.eval() . Evaluation returns a CelUnknownSet . Public API does not currently expose residual AST generation.
  • Python / C: No native support.

Async Evaluation

Async evaluation allows CEL expressions to call functions that execute asynchronously (eg, making RPCs or database queries) and block evaluation until the results are available, without blocking the main execution thread.

  • Go: Supports asynchronous function overloads via AsyncBinding and AsyncOp . Async functions return a Go channel ( <-chan ref.Val ), and the interpreter manages the concurrent execution and synchronization.
  • Java: Supports async evaluation via CelAsyncRuntime and AsyncProgram . It uses ListenableFuture to represent pending values and automatically drives evaluation to completion as futures resolve.
  • C++ / Python / C: No built-in support.

AST Validators

Validators perform static analysis on the Checked AST after type-checking to enforce domain-specific constraints before the program is executed.

  • Go: Supports ASTValidator interface. Canonical validators include cel.validator.duration , cel.validator.timestamp , cel.validator.matches (regex), cel.validator.homogeneous_literals , and cel.validator.comprehension_nesting_limit .
  • C++: Supports cel::Validator . Canonical validations include AstDepthValidator , ComprehensionNestingLimitValidator , DurationLiteralValidator , HomogeneousLiteralValidator , MatchesValidator , and TimestampLiteralValidator .
  • Java: Supports CelValidator and CelAstValidator . Canonical validators include AstDepthLimitValidator , ComprehensionNestingLimitValidator , DurationLiteralValidator , HomogeneousLiteralValidator , RegexLiteralValidator , and TimestampLiteralValidator .
  • Python / C: No direct support.

AST Optimizers

Optimizers rewrite the AST to improve execution performance. Optimizers fall into one of two categories: static and runtime optimizers. C++, Java, and Go support runtime optimization. CEL Java and Go also support static optimizers.

Typical optimizations include constant folding (pre-evaluating sub-expressions with constant inputs) and common subexpression elimination (CSE).

  • Go: Supports AST folding during compilation/planning.
  • C++: Supports constant folding via the cel::extensions::EnableConstantFolding extension at plan time.
  • Java: Supports CelOptimizer interface. Canonical optimizers include ConstantFoldingOptimizer (which supports pre-order traversal, Protobuf message constant folding, and aggregate or optional pruning), InliningOptimizer , and SubexpressionOptimizer (CSE).
  • Python / C: No direct support.

CEL Policy Compiler

CEL Policy is a YAML-based format for composing multiple CEL expressions together with variables, match blocks, conditional outputs, and nested rules. It is designed for complex policy engines (like Kubernetes Admission Control) where single CEL expressions would become unreadable.

For the formal language definition, syntax, and conformance suite, refer to the CEL Policy Specification .

The Policy Compiler compiles these YAML policies into a single standard CEL AST, meaning they are fully compatible with standard CEL runtimes and inherit all performance and safety guarantees.

  • Go: Supported via Go policy (including aggregate rule evaluation semantics).
  • C++: Supported via C++ policy .
  • Java: Supported via Java policy (including aggregate rule evaluation semantics and shorthand type specifiers in policy configs).
  • Python / C: Not directly supported.

Formal Verification Framework

The Formal Verification framework allows users to mathematically prove safety invariants, logical equivalence, satisfiability, and validity across CEL expressions and structured CEL Policies.

  • Java: Supported via the CEL Java Verifier ( dev.cel:verifier and dev.cel:verifier-cli ). Capabilities include satisfiability ( isSatisfiable ) with witness input generation, validity ( isAlwaysTrue ) with counterexample generation, bounded model checking (BMC) for comprehensions, logical equivalence proofs across ASTs, and custom assume / assert policy invariant verification.
  • Go / C++ / Python / C: Are supported indirectly via the Java command line toolchain.

For an introduction and real-world examples, see the Google Open Source blog post: Securing the agentic era: Introducing formal verification for CEL .