Skip to content

Commit

Permalink
chore: reorganize project
Browse files Browse the repository at this point in the history
  • Loading branch information
thesayyn committed Mar 11, 2024
1 parent 0ff68dc commit f075608
Show file tree
Hide file tree
Showing 19 changed files with 38 additions and 42 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[workspace]
members = ["parser", "program", "web", "cel_spec"]
members = ["cel-rs", "cel-spec", "web"]
resolver = "1"
8 changes: 6 additions & 2 deletions parser/Cargo.toml → cel-rs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"] }
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions program/src/eval.rs → cel-rs/src/eval.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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()
Expand All @@ -34,19 +34,19 @@ 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");
return value.to_owned()
}
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 {
Expand Down
3 changes: 2 additions & 1 deletion program/src/lib.rs → cel-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ pub use crate::program::Program;
pub use crate::context::Context;
pub mod value;
pub use crate::value::Value;
mod eval;
mod eval;
mod parser;
File renamed without changes.
2 changes: 1 addition & 1 deletion parser/src/cel.lalrpop → cel-rs/src/parser/cel.lalrpop
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
11 changes: 11 additions & 0 deletions cel-rs/src/parser/mod.rs
Original file line number Diff line number Diff line change
@@ -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"
);
6 changes: 3 additions & 3 deletions program/src/program.rs → cel-rs/src/program.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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};

Expand Down
2 changes: 1 addition & 1 deletion program/src/value.rs → cel-rs/src/value.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion cel_spec/Cargo.toml → cel-spec/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "cel_spec"
name = "cel-spec"
version = "0.1.0"
edition = "2021"

Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions cel_spec/src/lib.rs → cel-spec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 0 additions & 6 deletions parser/src/lib.rs

This file was deleted.

14 changes: 0 additions & 14 deletions program/Cargo.toml

This file was deleted.

2 changes: 1 addition & 1 deletion web/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ edition = "2021"
crate-type = ["cdylib"]

[dependencies]
program = {path = "../program"}
cel-rs = {path = "../cel-rs"}
wasm-bindgen = "0.2"
4 changes: 2 additions & 2 deletions web/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use program::{Context, Program};
use cel_rs::{Context, Program};
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
Expand All @@ -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
Expand Down

0 comments on commit f075608

Please sign in to comment.