pub struct Ast { /* private fields */ }Expand description
Unified AST representation matching cel-go’s Ast type.
An Ast can be either checked (has type info) or unchecked (parsed only).
This follows the cel-go pattern where a single type represents both states.
§Creating an Ast
- Use
Env::compile()to get a checkedAst - Use
Env::parse_only()to get an uncheckedAst
§Proto Conversion
For proto wire format conversion, use the cel-core-proto crate directly.
Implementations§
Source§impl Ast
impl Ast
Sourcepub fn new_unchecked(expr: SpannedExpr, source: impl Into<Arc<str>>) -> Self
pub fn new_unchecked(expr: SpannedExpr, source: impl Into<Arc<str>>) -> Self
Create an unchecked AST (after parsing, before type checking).
Sourcepub fn new_checked(
expr: SpannedExpr,
source: impl Into<Arc<str>>,
check_result: CheckResult,
) -> Self
pub fn new_checked( expr: SpannedExpr, source: impl Into<Arc<str>>, check_result: CheckResult, ) -> Self
Create a checked AST (after type checking).
Sourcepub fn is_checked(&self) -> bool
pub fn is_checked(&self) -> bool
Returns true if this AST has been type-checked.
Sourcepub fn expr(&self) -> &SpannedExpr
pub fn expr(&self) -> &SpannedExpr
Get the expression tree.
Sourcepub fn type_info(&self) -> Option<&CheckResult>
pub fn type_info(&self) -> Option<&CheckResult>
Get type checking results (if checked).
Sourcepub fn result_type(&self) -> Option<&CelType>
pub fn result_type(&self) -> Option<&CelType>
Get the result type of the expression (if checked).
Returns the type of the root expression from the type map.
Sourcepub fn to_cel_string(&self) -> String
pub fn to_cel_string(&self) -> String
Convert the AST back to CEL source text.
The output is a valid CEL expression that is semantically equivalent to the original. Formatting may differ (whitespace, parenthesization).
§Example
use cel_core::Env;
let env = Env::with_standard_library();
let ast = env.compile("1 + 2 * 3").unwrap();
assert_eq!(ast.to_cel_string(), "1 + 2 * 3");