diff --git a/Cargo.toml b/Cargo.toml index 611e833..472e625 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,3 @@ [workspace] -members = ["parser", "program", "web", "cel_spec"] +members = ["cel-rs", "cel-spec", "web"] resolver = "1" \ No newline at end of file diff --git a/parser/Cargo.toml b/cel-rs/Cargo.toml similarity index 69% rename from parser/Cargo.toml rename to cel-rs/Cargo.toml index 5f51822..88a144f 100644 --- a/parser/Cargo.toml +++ b/cel-rs/Cargo.toml @@ -1,14 +1,18 @@ [package] -name = "parser" +name = "cel-rs" version = "0.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] +ordered-float = "4.2.0" +ordered_hash_map = "0.4.0" regex = "1.4.2" lalrpop-util = "0.19.1" +[dev_dependencies] +cel-spec = {path = "../cel-spec"} + [build-dependencies] lalrpop = { version = "0.19.1", features = ["lexer"] } \ No newline at end of file diff --git a/parser/build.rs b/cel-rs/build.rs similarity index 100% rename from parser/build.rs rename to cel-rs/build.rs diff --git a/program/src/context.rs b/cel-rs/src/context.rs similarity index 100% rename from program/src/context.rs rename to cel-rs/src/context.rs diff --git a/program/src/eval.rs b/cel-rs/src/eval.rs similarity index 92% rename from program/src/eval.rs rename to cel-rs/src/eval.rs index 7eddd2f..07c7cf7 100644 --- a/program/src/eval.rs +++ b/cel-rs/src/eval.rs @@ -1,7 +1,7 @@ use core::panic; -use std::{mem, rc::Rc}; +use std::rc::Rc; use ordered_hash_map::OrderedHashMap; -use parser::{ArithmeticOp, Expression, Member, RelationOp}; +use crate::parser::{ArithmeticOp, Expression, Member, RelationOp}; use crate::{value::Value, Context}; pub trait Bag { @@ -22,7 +22,7 @@ impl Eval { fn eval_member(&self, expr: Expression, member: Member, ctx: &mut Context) -> impl Bag { let v = self.eval(expr.clone(), ctx).unpack(); match member { - parser::Member::Attribute(attr) => { + crate::parser::Member::Attribute(attr) => { if let Value::Map(v) = v { let value = v.get(&Value::String(attr)).expect("TODO: unknown map key"); return value.to_owned() @@ -34,11 +34,11 @@ impl Eval { panic!("unknown attribute {}", attr) }, - parser::Member::FunctionCall(args) => { + crate::parser::Member::FunctionCall(args) => { println!("call args = {:?} v = {:?}, expr = {:?}", args, v, expr); Value::Null }, - parser::Member::Index(i) => { + crate::parser::Member::Index(i) => { let i = self.eval(*i, ctx).unpack(); if let Value::Map(v) = v { let value = v.get(&i).expect("TODO: unknown map key"); @@ -46,7 +46,7 @@ impl Eval { } Value::Null }, - parser::Member::Fields(_) => todo!("Fields"), + crate::parser::Member::Fields(_) => todo!("Fields"), } } fn eval_map(&self, entries: Vec<(Expression, Expression)>, ctx: &mut Context) -> Value { diff --git a/program/src/lib.rs b/cel-rs/src/lib.rs similarity index 87% rename from program/src/lib.rs rename to cel-rs/src/lib.rs index 80d3d71..b6d9c1a 100644 --- a/program/src/lib.rs +++ b/cel-rs/src/lib.rs @@ -4,4 +4,5 @@ pub use crate::program::Program; pub use crate::context::Context; pub mod value; pub use crate::value::Value; -mod eval; \ No newline at end of file +mod eval; +mod parser; \ No newline at end of file diff --git a/parser/src/ast.rs b/cel-rs/src/parser/ast.rs similarity index 100% rename from parser/src/ast.rs rename to cel-rs/src/parser/ast.rs diff --git a/parser/src/cel.lalrpop b/cel-rs/src/parser/cel.lalrpop similarity index 98% rename from parser/src/cel.lalrpop rename to cel-rs/src/parser/cel.lalrpop index c691e91..5c3f0b0 100644 --- a/parser/src/cel.lalrpop +++ b/cel-rs/src/parser/cel.lalrpop @@ -1,4 +1,4 @@ -use crate::{RelationOp, ArithmeticOp, Expression, UnaryOp, Member, Atom}; +use crate::parser::{RelationOp, ArithmeticOp, Expression, UnaryOp, Member, Atom}; use std::rc::Rc; grammar; diff --git a/cel-rs/src/parser/mod.rs b/cel-rs/src/parser/mod.rs new file mode 100644 index 0000000..3d5750a --- /dev/null +++ b/cel-rs/src/parser/mod.rs @@ -0,0 +1,11 @@ +use lalrpop_util::lalrpop_mod; + +pub mod ast; +pub use ast::*; + +lalrpop_mod!( + #[allow(clippy::all)] + #[allow(unused)] + pub cel, + "/parser/cel.rs" +); \ No newline at end of file diff --git a/program/src/program.rs b/cel-rs/src/program.rs similarity index 95% rename from program/src/program.rs rename to cel-rs/src/program.rs index 3cd5039..4376886 100644 --- a/program/src/program.rs +++ b/cel-rs/src/program.rs @@ -1,5 +1,5 @@ -use parser::Expression; -use parser::parser::ExpressionParser; +use crate::parser::Expression; +use crate::parser::cel::ExpressionParser; use std::fmt; use std::result::Result; use crate::context::Context; @@ -44,7 +44,7 @@ impl Program { #[cfg(test)] pub mod tests { - use std::{default, rc::Rc, task::Context}; + use std::rc::Rc; use crate::{program, value::{FnValue, Overload}, Value}; diff --git a/program/src/value.rs b/cel-rs/src/value.rs similarity index 99% rename from program/src/value.rs rename to cel-rs/src/value.rs index 2b64269..70a4223 100644 --- a/program/src/value.rs +++ b/cel-rs/src/value.rs @@ -1,7 +1,7 @@ use std::{hash::Hash, rc::Rc}; use ordered_float::OrderedFloat; use ordered_hash_map::OrderedHashMap; -use parser::Atom; +use crate::parser::Atom; #[derive(PartialEq, Eq, Clone, Debug)] pub enum Value { diff --git a/program/tests/test.rs b/cel-rs/tests/test.rs similarity index 100% rename from program/tests/test.rs rename to cel-rs/tests/test.rs diff --git a/cel_spec/Cargo.toml b/cel-spec/Cargo.toml similarity index 92% rename from cel_spec/Cargo.toml rename to cel-spec/Cargo.toml index 40b295d..9029286 100644 --- a/cel_spec/Cargo.toml +++ b/cel-spec/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "cel_spec" +name = "cel-spec" version = "0.1.0" edition = "2021" diff --git a/cel_spec/build.rs b/cel-spec/build.rs similarity index 100% rename from cel_spec/build.rs rename to cel-spec/build.rs diff --git a/cel_spec/src/lib.rs b/cel-spec/src/lib.rs similarity index 94% rename from cel_spec/src/lib.rs rename to cel-spec/src/lib.rs index a81da7d..c746bc8 100644 --- a/cel_spec/src/lib.rs +++ b/cel-spec/src/lib.rs @@ -15,7 +15,7 @@ fn get_expected_value(value: &prost_reflect::DynamicMessage) -> String { "bytes_value" => ("Bytes(std::rc::Rc::new(Vec::from(", format!("{:?}", field.1.as_bytes().unwrap().to_vec()), ")))"), _ => ("Null", String::new(), "") }; - format!("program::value::Value::{}{}{}", m, v, c) + format!("cel_rs::value::Value::{}{}{}", m, v, c) } #[proc_macro] @@ -61,10 +61,10 @@ pub fn suite(attr: TokenStream) -> TokenStream { ast.push_str(&format!(r##" #[test] fn {name}() {{ - let program = program::Program::new(r#"{expr}"#); + let program = cel_rs::Program::new(r#"{expr}"#); assert!(program.is_ok(), "failed to parse '{{}}'", r#"{expr}"#); let program = program.unwrap(); - let mut ctx = program::context::Context::default(); + let mut ctx = cel_rs::context::Context::default(); let value = program.eval(&mut ctx); let expected_value = {expected_value}; assert_eq!(value, expected_value, r#""{{}}" did not match "{{}}""#, value, expected_value); diff --git a/parser/src/lib.rs b/parser/src/lib.rs deleted file mode 100644 index 76927b3..0000000 --- a/parser/src/lib.rs +++ /dev/null @@ -1,6 +0,0 @@ -use lalrpop_util::lalrpop_mod; - -pub mod ast; -pub use ast::*; - -lalrpop_mod!(#[allow(clippy::all)] pub parser, "/cel.rs"); \ No newline at end of file diff --git a/program/Cargo.toml b/program/Cargo.toml deleted file mode 100644 index e92a5ea..0000000 --- a/program/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -[package] -name = "program" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -parser = {path = "../parser"} -ordered-float = "4.2.0" -ordered_hash_map = "0.4.0" - -[dev_dependencies] -cel_spec = {path = "../cel_spec"} \ No newline at end of file diff --git a/web/Cargo.toml b/web/Cargo.toml index a4bd8b8..c3d5228 100644 --- a/web/Cargo.toml +++ b/web/Cargo.toml @@ -7,5 +7,5 @@ edition = "2021" crate-type = ["cdylib"] [dependencies] -program = {path = "../program"} +cel-rs = {path = "../cel-rs"} wasm-bindgen = "0.2" diff --git a/web/src/lib.rs b/web/src/lib.rs index 0755240..fe57886 100644 --- a/web/src/lib.rs +++ b/web/src/lib.rs @@ -1,4 +1,4 @@ -use program::{Context, Program}; +use cel_rs::{Context, Program}; use wasm_bindgen::prelude::*; #[wasm_bindgen] @@ -11,7 +11,7 @@ extern "C" { fn eval(source: &str) -> bool { match Program::new(source) { - Ok(p) => p.execute(Context::default()), + Ok(p) => p.execute(&mut Context::default()), Err(err) => { error(format!("cel-rs: parse error {}", err)); false