From 492f9509a2e6db8e58ef5cba7910c8c4ebe44bb7 Mon Sep 17 00:00:00 2001 From: Tristan Swadell Date: Tue, 26 Jan 2021 15:55:03 -0800 Subject: [PATCH 1/3] Update intro examples --- doc/intro.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/intro.md b/doc/intro.md index 8f0f7f6b..f4f363d2 100644 --- a/doc/intro.md +++ b/doc/intro.md @@ -30,8 +30,8 @@ example, given an instance of the `Account` type assigned to the variable ```proto has(account.user_id) || has(account.gaia_id) // true if either one is set -size(account.emails) > 0 // true if emails is non-empty -matches(account.phone_number, "[0-9-]+") // true if number matches regexp +account.emails.size() > 0 // true if emails is non-empty +account.phone_number.matches("[0-9-]+") // true if number matches regexp ``` CEL expressions support most operators and functions one would expect when @@ -60,7 +60,7 @@ doesn't have a matching protocol buffer type. Within CEL, these objects support the same accesses and functions as protocol buffer types: ```proto -has(account.properties.id) && size(account.properties.id) > 0 +has(account.properties.id) && account.properties.id.size() > 0 ``` When the expression `account.properties` is evaluated, CEL will automatically @@ -85,7 +85,7 @@ citizens of CEL: ```proto has(account.properties.id) && (type(account.properties.id) == string - || type(account.properties.id) == list(string)) + || type(account.properties.id) == list) ``` CEL's default type checker deals with a mixture of dynamic and static typing; From 0016c7f40ba2f45524f14104220a3c71c4c624ca Mon Sep 17 00:00:00 2001 From: Tristan Swadell Date: Mon, 1 Feb 2021 16:24:37 -0800 Subject: [PATCH 2/3] Update langdef.md references to 'size' to indicate it should be used as a receiver function --- doc/langdef.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/doc/langdef.md b/doc/langdef.md index c34d690f..968026c9 100644 --- a/doc/langdef.md +++ b/doc/langdef.md @@ -632,7 +632,7 @@ A CEL expression is parsed and evaluated in the scope of a particular protocol buffer package, which controls name resolution as described above, and a binding context, which binds identifiers to values, errors, and functions. A given identifier has different meanings as a function name or as a variable, depending -on the use. For instance in the expression `size(requests) > size`, the first +on the use. For instance in the expression `requests.size() > size`, the first `size` is a function, and the second is a variable. The CEL implementation provides mechanisms for adding bindings of variable names @@ -914,7 +914,7 @@ size of the inputs. cost of `O(P * I)`, and see below. * Eliminating all of the above and using only default-cost functions, plus aggregate literals, time and space are limited `O(P * I)`. - A limiting time example is `size(x) + size(x) + ...`. + A limiting time example is `x.size() + x.size() + ...`. A limiting time and space example is `[x, x, ..., x]`. Note that custom function will alter this analysis if they are more expensive @@ -942,7 +942,7 @@ specified by the following overloads: size - (string) -> int + string.() -> int string length @@ -950,7 +950,7 @@ specified by the following overloads: - (bytes) -> int + bytes.() -> int bytes length @@ -958,7 +958,7 @@ specified by the following overloads: - (list(A)) -> int + list(A).() -> int list size @@ -966,7 +966,7 @@ specified by the following overloads: - (map(A, B)) -> int + map(A, B).() -> int map size @@ -2156,7 +2156,7 @@ See [cel-go/issues/9](https://github.com/google/cel-go/issues/9). size - (string) -> int + string.() -> int string length @@ -2164,7 +2164,7 @@ See [cel-go/issues/9](https://github.com/google/cel-go/issues/9). - (bytes) -> int + bytes.() -> int bytes length @@ -2172,7 +2172,7 @@ See [cel-go/issues/9](https://github.com/google/cel-go/issues/9). - (list(A)) -> int + list(A).() -> int list size. Time cost proportional to the length of the list. @@ -2180,7 +2180,7 @@ See [cel-go/issues/9](https://github.com/google/cel-go/issues/9). - (map(A, B)) -> int + map(A, B).() -> int map size. Time cost proportional to the number of entries. From e46f2a72149115c191c7904c44ae8f151e6459c1 Mon Sep 17 00:00:00 2001 From: Tristan Swadell Date: Wed, 10 Mar 2021 14:02:14 -0800 Subject: [PATCH 3/3] Updated the docs to indicate the full set of size() overloads --- doc/langdef.md | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/doc/langdef.md b/doc/langdef.md index 968026c9..373f87c3 100644 --- a/doc/langdef.md +++ b/doc/langdef.md @@ -945,7 +945,7 @@ specified by the following overloads: string.() -> int - string length + number of unicode codepoints in the string @@ -2152,14 +2152,22 @@ See [cel-go/issues/9](https://github.com/google/cel-go/issues/9). - + size string.() -> int - string length + number of unicode codepoints in the string + + + + + (string) -> int + + + number of unicode codepoints in the string @@ -2170,6 +2178,14 @@ See [cel-go/issues/9](https://github.com/google/cel-go/issues/9). bytes length + + + (bytes) -> int + + + bytes length + + list(A).() -> int @@ -2178,6 +2194,14 @@ See [cel-go/issues/9](https://github.com/google/cel-go/issues/9). list size. Time cost proportional to the length of the list. + + + (list(A)) -> int + + + list size. Time cost proportional to the length of the list. + + map(A, B).() -> int @@ -2186,6 +2210,14 @@ See [cel-go/issues/9](https://github.com/google/cel-go/issues/9). map size. Time cost proportional to the number of entries. + + + (map(A, B)) -> int + + + map size. Time cost proportional to the number of entries. + + startsWith