1#![cfg_attr(feature = "fail-on-warnings", deny(warnings))]
2#![cfg_attr(feature = "fail-on-warnings", deny(clippy::all))]
3
4use cached::proc_macro::cached;
5use tracing::instrument;
6
7pub mod ast;
8
9pub use ast::*;
10
11#[allow(clippy::all)]
15mod parser {
16 include!("cel.rs");
17}
18
19#[derive(Debug)]
21pub struct ParseErrors(pub Vec<(usize, String)>);
22
23impl std::fmt::Display for ParseErrors {
24 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25 write!(f, "{} parse error(s)", self.0.len())
26 }
27}
28
29impl std::error::Error for ParseErrors {}
30
31#[cached(size = 10000)]
37#[instrument(name = "cel.parse", skip(source), fields(expression = %source), err)]
38pub fn parse_expression(source: String) -> Result<Expression, String> {
39 parser::ExpressionParser::new()
40 .parse(&source)
41 .map_err(|e| e.to_string())
42}