https://github.com/nikola-jokic/cellang
CEL interpreter, parser, lexer, and other utilities
https://github.com/nikola-jokic/cellang
cel-language interpr lex parser rust
Last synced: 4 months ago
JSON representation
CEL interpreter, parser, lexer, and other utilities
- Host: GitHub
- URL: https://github.com/nikola-jokic/cellang
- Owner: nikola-jokic
- License: mit
- Created: 2024-12-01T11:14:15.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-23T19:50:13.000Z (over 1 year ago)
- Last Synced: 2025-04-12T03:08:56.846Z (about 1 year ago)
- Topics: cel-language, interpr, lex, parser, rust
- Language: Rust
- Homepage: https://crates.io/crates/cellang
- Size: 284 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
# CEL language interpreter for Rust
This is a rust implementation of the [CEL](https://cel.dev/) language.
This project is built for [BountyHub](https://bountyhub.org) platform, but is open-source and can be used by anyone.
If you find any issues, please report them.
## Getting started
```bash
git clone https://github.com/nikola-jokic/cellang.git
cd cellang
cargo build
```
### Running the test suite
The workspace is fully covered by automated checks. Locally you can mirror CI with:
```bash
cargo test --locked --all-features --all-targets
cargo test --locked --all-features --doc
```
Examples under `crates/cellang/examples` can be exercised via:
```bash
cd crates/cellang
for example in examples/*.rs; do \
name=$(basename "${example%.rs}"); \
cargo test --locked --all-features --example "$name"; \
done
```
or run directly with `cargo run --example ` for interactive experimentation.
### Example overview
| Example | Highlights |
| --- | --- |
| `simple` | Basic expression evaluation, child runtimes, and scalar values. |
| `create_function` | Registering function declarations plus native Rust implementations. |
| `concurrency` | Sharing a runtime builder across threads for parallel evaluation. |
| `user_role_derive` | Using the `derive` feature to expose Rust structs and methods to CEL. |
| `comprehensions` | Practical use of CEL macros like `exists`, `filter`, `map`, and `all`. |
| `env_snapshot` | Building, serializing, and rehydrating a reusable environment snapshot. |
## CLI
The `cellang-cli` crate exposes a developer-friendly command line interface for inspecting CEL programs.
```bash
cargo run -p cellang-cli -- lex expr --format json "a + size(b)"
cargo run -p cellang-cli -- parse file --path script.cel --format debug
cargo run -p cellang-cli -- eval expr --expr "users[0].has_role(role)" --env-path ./env.json
```
Subcommands:
- `lex` – emit tokens for a file or inline expression (formatted as pretty JSON or debug output).
- `parse` – dump the AST generated by the Pratt parser.
- `eval` – evaluate an expression within a runtime populated from a JSON environment file.
## Repository structure
This repository is a rust workspace, with the following crates:
- `cellang`: The main library crate located at [lib](./crates/cellang)
- `cellang-cli`: A CLI tool to evaluate CEL expressions located at [cli](./crates/cellang-cli)
## License
This project is licensed under the [MIT license](./LICENSE).
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the MIT license, shall be licensed as above, without any additional terms or conditions.
## Special thanks
Special thanks to [Jon Gjengset](https://github.com/jonhoo) for his amazing [video](https://youtu.be/mNOLaw-_Buc) which helped me get started with this project.