Rust CEL Parser
A parser for Google's Common Expression Language (CEL) that produces a detailed Abstract Syntax Tree (AST).
Core Features
Quick Start
1. Installation
Add the following to your Cargo.toml:
[]
= "0.1.0" # Replace with the latest version
2. Parsing an Expression
use ;
3. Walking the AST with a Visitor
The Visitor pattern is a way to analyze an expression. Here's how to find all unique identifiers used in an expression:
use ;
use HashSet;
// 1. Define a struct to hold your state.
// 2. Implement the Visitor trait, overriding only the methods you need.
// 3. Run the visitor.
let ast = parse_cel_program.unwrap;
let mut collector = IdentifierCollector ;
ast.accept; // The `accept` method starts the traversal.
assert!;
assert!;
println!;
Supported Features
This parser supports a significant portion of the CEL specification.
- Literals:
int,uint,double,bool,string,bytes,null. - Operators: All arithmetic, logical, and relational operators with correct precedence.
- Data Structures:
List([...]),Map({...}), andMessageliterals. - Accessors: Field access (
.), index access ([...]). - Control Flow: Ternary operator (
_ ? _ : _). - Macros:
has(),all(),exists(),exists_one(),filter(),map().
License
This project is licensed under the MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for details on how to set up the development environment, run tests, and submit a pull request.