-
Notifications
You must be signed in to change notification settings - Fork 801
Expand file tree
/
Copy pathexample.cel
More file actions
228 lines (200 loc) · 3.78 KB
/
example.cel
File metadata and controls
228 lines (200 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
// CEL (Common Expression Language) example covering all syntax features.
// --- Boolean and null literals ---
true
false
null
// --- Integer literals ---
0
42
255
0xff
0XFF
0u
42u
255u
0xFFu
// --- Float literals ---
0.0
3.14
3.14e2
3.14e+2
3.14e-2
.5
.0
1e10
1E5
1.0E+2
1.5e-10
0.0e0
// --- String literals ---
"hello, world"
'hello, world'
"escape: \n \t \\ \" \' \` \? \x41 \X41 \u0041 \U00000041 \012"
'escape: \a \b \f \r \v \xff \u0041'
"it's fine"
'say "hi"'
r"raw \n no escape"
R'raw \t no escape'
"""triple
double
quoted"""
'''triple
single
quoted'''
R"uppercase raw double-quoted"
r"""raw triple: \n \t \\ not processed"""
R'''raw triple: \n \t \\ not processed'''
r""""""
r''''''
// --- Bytes literals ---
b"bytes"
b'bytes'
B"uppercase bytes"
B'uppercase bytes'
b"\x00\xFF"
b'\x00\xFF'
b'\X00\XFF'
br"raw bytes"
rb"raw bytes"
bR"mixed case"
Br"mixed case"
BR"raw bytes"
RB"raw bytes"
b"""triple bytes"""
b'''triple bytes'''
br"""raw triple bytes"""
rb'''raw triple bytes'''
// --- Operators ---
1 + 2 - 3 * 4 / 5 % 6
1+2*3+4
a / b % c
a&&b||c
a==b!=c
!!x
--x
true&&false
null==null
!true && !false
true||false&&null
x == y
x != y
x < y
x <= y
x > y
x >= y
a < b && c <= d && e > f && g >= h
x && y
x || y
a || b && c
!x
-x
!a && !b
-a + -b
x ? y : z
a ? b || d : c || e
a ? b : c ? d : e
x in [1, 2, 3]
1 in [1, 2, 3]
"key" in {"key": 1}
// --- Identifiers and member access ---
request.auth.claims
resource.labels.env
_under_score
mixedCase123
café
_日本語
r
b
r + x
b.field
// --- Function calls ---
size(request.path)
timestamp("2099-01-01T00:00:00Z")
matches(name, "^[a-z]+$")
has(resource.labels)
has(x.y)
a(1, 2) + b()
f(a, b,)
// --- Member method calls ---
"hello".contains("ell")
x.startsWith("foo")
[1, 2, 3].all(i, i > 0)
a.b() + a.b.c(1, 2)
x.map(y, y > 0).size()
// --- Absolute expressions ---
.foo
.func(a, b)
.pkg.func()
.google.protobuf.Duration
.google.protobuf.Timestamp{seconds: 0}
// --- List expressions ---
[]
[1, 2, 3]
[true, false, null]
["a", "b", "c",]
[[1, 2], [3]]
[1, 2+a, 3u][1]
// --- Map expressions ---
{}
{"key": "value"}
{"a": 1, "b": 2,}
{a: 1, 'b': 2, "c": 3}
{a: 1,}
{a + b: 1}
// --- Struct expressions ---
Foo{}
google.protobuf.Duration{seconds: 60}
MyType{field: "value", other: 42}
MyType{as: 1, return: x}
Foo{a: 1,}
a.b{field: 1}
ext.TestAllTypes{PbVal: test.TestAllTypes{}}
// --- All reserved keywords ---
as + break + const + continue + else + for
function + if + import + in + let + loop
namespace + package + return + var + void + while
// --- Reserved keywords used as field/method names ---
x.package
x.namespace()
x.as
x.if
Foo{import: 1, for: 2}
as(x)
// --- Identifiers that begin with reserved words (must NOT be keywords) ---
async + breaking + constant + elsewhere + forall
function_name + iffy + imported + inlet + letting
looping + namespacer + packaged + returning + variable + voiding + whileTrue
// --- Conditional (ternary) ---
size(x) > 0 ? x[0] : "default"
a || b ? c && d : e != f
// --- Index expressions ---
a[1]
a[1] + b.c[2.0] + d[1][2] + e[1].f(1, 2)
// --- Parenthesized expressions ---
(a + b) * c
(a + b).c
(a + b)[1]
((1 + 2) * 3) == 9
x[0].field.method(arg1, arg2)
// --- Edge cases from spec ---
// URL in string: // must not become a comment inside a string
"https://example.com/path"
{"url": "https://example.com // not a comment"}
// String followed by a comment on the same line
"test" // this is a comment
// Integer select (not a float): 1.a
1.a
// `in` as standalone reserved keyword and in arithmetic
in
in + 1
// Empty strings
"" + ''
// Empty triple-quoted strings
"""""" + ''''''
// Triple-quoted with embedded quotes
"""text ends with quote" and two quotes"" here"""
'''line with 'single' and "double" quotes'''
// String with backslash sequences (fallback escapes)
'C:\path\to\file\newline\n'
// Unicode content
'🎉😀' == '中文'