Convert Figma logo to code with AI

google logocel-spec

Common Expression Language -- specification and binary representation

2,783
222
2,783
56

Top Related Projects

2,187

Fast, portable, non-Turing complete expression evaluation with gradual typing (Go)

Quick Overview

The google/cel-spec repository contains the specification for the Common Expression Language (CEL). CEL is a simple expression language designed for fast evaluation, safety, and portability. It's used for expressing policies, rules, and configurations in various Google products and open-source projects.

Pros

  • Lightweight and fast evaluation
  • Designed with security in mind, preventing arbitrary code execution
  • Portable across different programming languages and environments
  • Extensible with custom functions and types

Cons

  • Limited functionality compared to full programming languages
  • Learning curve for those unfamiliar with expression languages
  • May require additional tooling for complex use cases
  • Not suitable for general-purpose programming tasks

Code Examples

CEL is not a code library itself, but rather a specification for an expression language. However, here are some examples of CEL expressions:

// Basic arithmetic and comparison
(5 + 3) * 2 > 15
// String manipulation and function calls
'hello'.size() + ' world'.size() == 10
// Working with maps and lists
[1, 2, 3].map(x, x * 2).filter(x, x > 4).size() == 2

Getting Started

To use CEL, you typically need to implement or use an existing implementation of the CEL specification in your preferred programming language. Here's a general outline of how to get started:

  1. Choose a CEL implementation for your language (e.g., cel-go for Go, cel-java for Java).
  2. Install the implementation in your project.
  3. Create a CEL environment and parse expressions.
  4. Evaluate expressions with provided variables and functions.

For specific implementation details, refer to the documentation of the CEL implementation you choose to use.

Competitor Comparisons

2,187

Fast, portable, non-Turing complete expression evaluation with gradual typing (Go)

Pros of cel-go

  • Provides a Go implementation of CEL, allowing direct integration in Go projects
  • Includes additional tools and utilities for working with CEL in Go environments
  • Offers performance optimizations specific to Go runtime

Cons of cel-go

  • Limited to Go language, whereas cel-spec is language-agnostic
  • May have slight differences in behavior compared to the official specification
  • Requires maintenance to keep up with changes in the cel-spec

Code Comparison

cel-spec (example from conformance tests):

[1, 2, 3].map(x, x * 2) == [2, 4, 6]

cel-go (equivalent implementation):

program, _ := cel.Parse(`[1, 2, 3].map(x, x * 2) == [2, 4, 6]`)
result, _ := program.Eval(cel.NoVars())
fmt.Println(result) // Output: true

The cel-spec repository defines the Common Expression Language (CEL) specification, while cel-go provides a Go implementation of CEL. cel-spec serves as the authoritative reference for CEL behavior across all implementations, ensuring consistency. cel-go, on the other hand, offers a concrete implementation tailored for Go developers, with additional tools and optimizations specific to the Go ecosystem.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Common Expression Language

The Common Expression Language (CEL) implements common semantics for expression evaluation, enabling different applications to more easily interoperate.

Key Applications

  • Security policy: organizations have complex infrastructure and need common tooling to reason about the system as a whole
  • Protocols: expressions are a useful data type and require interoperability across programming languages and platforms.

Guiding philosophy:

  1. Keep it small & fast.
    • CEL evaluates in linear time, is mutation free, and not Turing-complete. This limitation is a feature of the language design, which allows the implementation to evaluate orders of magnitude faster than equivalently sandboxed JavaScript.
  2. Make it extensible.
    • CEL is designed to be embedded in applications, and allows for extensibility via its context which allows for functions and data to be provided by the software that embeds it.
  3. Developer-friendly.
    • The language is approachable to developers. The initial spec was based on the experience of developing Firebase Rules and usability testing many prior iterations.
    • The library itself and accompanying toolings should be easy to adopt by teams that seek to integrate CEL into their platforms.

The required components of a system that supports CEL are:

  • The textual representation of an expression as written by a developer. It is of similar syntax to expressions in C/C++/Java/JavaScript
  • A representation of the program's abstract syntax tree (AST).
  • A compiler library that converts the textual representation to the binary representation. This can be done ahead of time (in the control plane) or just before evaluation (in the data plane).
  • A context containing one or more typed variables, often protobuf messages. Most use-cases will use attribute_context.proto
  • An evaluator library that takes the binary format in the context and produces a result, usually a Boolean.

For use cases which require persistence or cross-process communcation, it is highly recommended to serialize the type-checked expression as a protocol buffer. The CEL team will maintains canonical protocol buffers for ASTs and will keep these versions identical and wire-compatible in perpetuity:

Example of boolean conditions and object construction:

// Condition
account.balance >= transaction.withdrawal
    || (account.overdraftProtection
    && account.overdraftLimit >= transaction.withdrawal  - account.balance)

// Object construction
common.GeoPoint{ latitude: 10.0, longitude: -5.5 }

For more detail, see:

Released under the Apache License.

Disclaimer: This is not an official Google product.