Skip to content

CEL Specification#

This page summarizes the canonical CEL specification. Refer to the official specification for authoritative details.

Grammar#

CEL expressions follow this grammar. Operator precedence is encoded in the production hierarchy, from lowest (conditional) to highest (primary).

Notation#

The grammar uses Extended Backus-Naur Form (EBNF):

Notation Meaning
= Definition
| Alternation
[] Optional (zero or one)
{} Repetition (zero or more)
() Grouping
"x" Terminal string
UPPER Terminal (token)
Lower Non-terminal (production)

Expressions#

An expression is a conditional, which may include a ternary operator.

Expr = ConditionalOr [ "?" ConditionalOr ":" Expr ] ;

Logical operators#

Logical OR has lower precedence than logical AND.

ConditionalOr  = ConditionalAnd { "||" ConditionalAnd } ;
ConditionalAnd = Relation { "&&" Relation } ;

Relational operators#

Comparison and membership operators.

Relation = Addition { Relop Addition } ;
Relop    = "<" | "<=" | ">=" | ">" | "==" | "!=" | "in" ;

Arithmetic operators#

Addition and subtraction have lower precedence than multiplication.

Addition       = Multiplication { ( "+" | "-" ) Multiplication } ;
Multiplication = Unary { ( "*" | "/" | "%" ) Unary } ;

Negation#

Negation and logical NOT.

Unary = Member
      | "!" { "!" } Member
      | "-" { "-" } Member
      ;

Member access#

Field access, indexing, and method calls.

Member = Primary
       | Member "." IDENT [ "(" [ ExprList ] ")" ]
       | Member "[" Expr "]"
       ;

Primary expressions#

Literals, identifiers, parenthesized expressions, and constructors.

Primary = [ "." ] IDENT [ "(" [ ExprList ] ")" ]
        | "(" Expr ")"
        | "[" [ ExprList ] [ "," ] "]"
        | "{" [ MapInits ] [ "," ] "}"
        | [ "." ] IDENT { "." IDENT } "{" [ FieldInits ] [ "," ] "}"
        | LITERAL
        ;
ExprList   = Expr { "," Expr } ;
FieldInits =