Skip to content

Commit ed0181b

Browse files
authored
update grammar and tests to differentiate reserved tokens (#437)
update grammar to differentiate reserved tokens
1 parent 6f8806d commit ed0181b

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

doc/langdef.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,18 @@ Unary = Member
7777
| "-" {"-"} Member
7878
;
7979
Member = Primary
80-
| Member "." IDENT ["(" [ExprList] ")"]
80+
| Member "." SELECTOR ["(" [ExprList] ")"]
8181
| Member "[" Expr "]"
8282
;
8383
Primary = ["."] IDENT ["(" [ExprList] ")"]
8484
| "(" Expr ")"
8585
| "[" [ExprList] [","] "]"
8686
| "{" [MapInits] [","] "}"
87-
| ["."] IDENT { "." IDENT } "{" [FieldInits] [","] "}"
87+
| ["."] SELECTOR { "." SELECTOR } "{" [FieldInits] [","] "}"
8888
| LITERAL
8989
;
9090
ExprList = Expr {"," Expr} ;
91-
FieldInits = IDENT ":" Expr {"," IDENT ":" Expr} ;
91+
FieldInits = SELECTOR ":" Expr {"," SELECTOR ":" Expr} ;
9292
MapInits = Expr ":" Expr {"," Expr ":" Expr} ;
9393
```
9494

@@ -137,7 +137,8 @@ by the grammar. Please note, that in the lexer `[]` denotes a character range,
137137
or one occurrence.
138138

139139
```
140-
IDENT ::= [_a-zA-Z][_a-zA-Z0-9]* - RESERVED
140+
IDENT ::= SELECTOR - RESERVED
141+
SELECTOR ::= [_a-zA-Z][_a-zA-Z0-9]* - KEYWORD
141142
LITERAL ::= INT_LIT | UINT_LIT | FLOAT_LIT | STRING_LIT | BYTES_LIT
142143
| BOOL_LIT | NULL_LIT
143144
INT_LIT ::= -? DIGIT+ | -? 0x HEXDIGIT+
@@ -159,8 +160,8 @@ ESCAPE ::= \ [abfnrtv\?"'`]
159160
| \ [0-3] [0-7] [0-7]
160161
BOOL_LIT ::= "true" | "false"
161162
NULL_LIT ::= "null"
162-
RESERVED ::= BOOL_LIT | NULL_LIT | "in"
163-
| "as" | "break" | "const" | "continue" | "else"
163+
KEYWORD ::= BOOL_LIT | NULL_LIT | "in"
164+
RESERVED ::= "as" | "break" | "const" | "continue" | "else"
164165
| "for" | "function" | "if" | "import" | "let"
165166
| "loop" | "package" | "namespace" | "return"
166167
| "var" | "void" | "while"
@@ -174,13 +175,13 @@ without the `r` or `R` (raw) prefix process `ESCAPE` sequences, while in strings
174175
with the raw prefix they stay uninterpreted. See documentation of string
175176
literals below.
176177

177-
The following identifiers are reserved due to their use as literal values or in
178-
the syntax:
178+
The following language keywords are reserved and cannot be used as identifiers,
179+
function names, selectors, struct name segments, or field names:
179180

180181
false in null true
181182

182-
The following identifiers are reserved to allow easier embedding of CEL into a
183-
host language.
183+
The following tokens are reserved to allow easier embedding of CEL into a host
184+
language and cannot be used as identifiers or function names[^function-names]:
184185

185186
as break const continue else for function if import let loop package
186187
namespace return var void while
@@ -189,6 +190,9 @@ In general it is a bad idea for those defining contexts or extensions to use
189190
identifiers that are reserved words in programming languages which might embed
190191
CEL.
191192

193+
[^function-names]: Except for receiver-call-style functions, e.g. `a.package()`,
194+
which is permitted.
195+
192196
### Name Resolution
193197

194198
A CEL expression is parsed in the scope of a specific protocol buffer package or

0 commit comments

Comments
 (0)