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 lalrpop_util::lalrpop_mod;
6use tracing::instrument;
7
8pub mod ast;
9
10pub use ast::*;
11
12lalrpop_mod!(
14 #[allow(clippy::all)]
15 parser,
16 "/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}