Skip to main content

cel_core/
lib.rs

1//! CEL-Core: High-level API for the Common Expression Language
2//!
3//! This crate provides a unified `Env` for working with CEL expressions,
4//! following the cel-go architecture pattern.
5//!
6//! # Quick Start
7//!
8//! ```
9//! use cel_core::Env;
10//! use cel_core::CelType;
11//!
12//! // Create an environment with standard library and a variable
13//! let env = Env::with_standard_library()
14//!     .with_variable("x", CelType::Int);
15//!
16//! // Parse and type-check in one step
17//! let ast = env.compile("x + 1").unwrap();
18//! assert!(ast.is_checked());
19//! ```
20//!
21//! # Architecture
22//!
23//! The `Env` struct coordinates:
24//! - **Parser**: Converts source text into an AST
25//! - **Checker**: Type-checks expressions and resolves references
26//! - **Variables**: User-defined variable declarations
27//! - **Functions**: Standard library + custom function declarations
28//!
29//! # Modules
30//!
31//! - `types`: Core type system, AST, and declarations
32//! - `parser`: Lexer, parser, and macro expansion
33//! - `checker`: Type checking and overload resolution
34//! - `ext`: Extension libraries (strings, math, encoders, optionals)
35//!
36//! # Proto Conversion
37//!
38//! For proto wire format conversion (interop with cel-go, cel-cpp), use the
39//! `cel-core-proto` crate which provides `CheckedExpr` and `ParsedExpr` types.
40
41mod ast;
42mod env;
43mod unparser;
44
45// Core modules
46mod checker;
47mod eval;
48pub mod ext;
49pub mod parser;
50pub mod types;
51
52pub use ast::{Ast, AstError};
53pub use env::{AbbrevError, Abbreviations, CompileError, Env};
54pub use unparser::ast_to_string;
55
56// Re-export from checker module
57pub use checker::{CheckError, CheckErrorKind, CheckResult, ReferenceInfo};
58
59// Re-export from eval module
60pub use eval::time;
61pub use eval::{
62    Activation, EmptyActivation, EvalError, EvalErrorKind, HierarchicalActivation, MapActivation,
63    Program, Value, ValueError,
64};
65pub use eval::{
66    Duration, EnumValue, MapKey, OptionalValue, SharedActivation, Timestamp, TypeValue, ValueMap,
67};
68pub use eval::{MessageValue, ProtoRegistry, ProtoTypeResolver, StructFieldValue};
69
70// Re-export from parser module
71pub use parser::{parse, ParseError, ParseResult};
72
73// Re-export from types module
74pub use types::proto::{proto_message_to_cel_type, ResolvedProtoType};
75pub use types::{
76    BinaryOp, CelType, CelValue, ComprehensionData, Expr, FunctionDecl, ListElement, MapEntry,
77    OverloadDecl, Span, Spanned, SpannedExpr, StructField, UnaryOp, VariableDecl,
78};