Skip to content

Commit 062a9ec

Browse files
committed
feat: CEL reserved keywords
1 parent 53b5fc8 commit 062a9ec

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

cel.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,32 @@ func GetCelEnv(environment map[string]any) []cel.EnvOption {
3333

3434
return opts
3535
}
36+
37+
// The following identifiers are reserved to allow easier embedding of CEL into a host language.
38+
//
39+
// Reference: https://github.com/google/cel-spec/blob/master/doc/langdef.md
40+
var celKeywords = map[string]struct{}{
41+
"as": {},
42+
"break": {},
43+
"const": {},
44+
"continue": {},
45+
"else": {},
46+
"for": {},
47+
"function": {},
48+
"if": {},
49+
"import": {},
50+
"let": {},
51+
"loop": {},
52+
"namespace": {},
53+
"package": {},
54+
"return": {},
55+
"var": {},
56+
"void": {},
57+
"while": {},
58+
}
59+
60+
// IsCelKeyword returns true if the given key is a reserved word in Cel
61+
func IsCelKeyword(key string) bool {
62+
_, ok := celKeywords[key]
63+
return ok
64+
}

0 commit comments

Comments
 (0)