Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validatron rewrite: rules engine improvements #181

Merged
merged 13 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
84 changes: 34 additions & 50 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions crates/modules/rules-engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ repository.workspace = true
validatron = { path = "../../validatron" }
pulsar-core = { path = "../../pulsar-core" }

log = "0.4"
log = "0.4.17"
anyhow = "1"
tokio = "1.15.0"
glob = "0.3.0"
thiserror = "1"
serde_yaml = "0.8"
serde = { version = "1", features = ["derive"] }
glob = "0.3.1"
thiserror = "1.0.40"
serde = { version = "1.0.160", features = ["derive"] }
serde_yaml = "0.9.21"
lalrpop-util = { version="0.19.9", features=["lexer"] }

[build-dependencies]
lalrpop = "0.19.9"
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use std::str::FromStr;
use crate::{Operator, Condition, Field, RelationalOperator, StringOperator, MultiOperator};

use validatron::{Operator, RelationalOperator, StringOperator, MultiOperator, Match, Field, Condition};
use lalrpop_util::ParseError;
use super::DslError;

grammar;
use super::{DslError};

grammar(variant: &str);

pub Condition: Condition = {
<l:Condition> "AND" <r:SignedCondition> => Condition::And{l: Box::new(l), r: Box::new(r)},
Expand All @@ -18,18 +17,23 @@ SignedCondition: Condition = {
}

BaseCondition: Condition = {
<f: Field> <op: Operator> <value: Value> => Condition::Base {
field: f,
<f: FieldPath> <op: Operator> <value: Value> => Condition::Base {
field_path: f,
op,
value: Match::Value(value)
},
<f: FieldPath> <op: Operator> <value: FieldPath> => Condition::Base {
field_path: f,
op,
value
value: Match::Field(value)
},
<f: Field> "IN" <list: ValueList> =>? {
<f: FieldPath> "IN" <list: ValueList> =>? {
let mut iterator = list.into_iter();

let first = Condition::Base {
field: f.clone(),
field_path: f.clone(),
op: Operator::Relational(RelationalOperator::Equals),
value: iterator.next().ok_or(ParseError::User {
value: iterator.next().map(|x| Match::Value(x)).ok_or(ParseError::User {
error: DslError::EmptyList
})?
};
Expand All @@ -38,9 +42,9 @@ BaseCondition: Condition = {
Condition::Or {
l: Box::new(acc),
r: Box::new(Condition::Base {
field: f.clone(),
field_path: f.clone(),
op: Operator::Relational(RelationalOperator::Equals),
value: x
value: Match::Value(x)
})
}
});
Expand Down Expand Up @@ -84,14 +88,34 @@ Operator: Operator = {
"CONTAINS" => Operator::Multi(MultiOperator::Contains),
}

Field: Field = {
<s: r"[a-zA-Z]\w+[\.[a-zA-Z]\w+]*"> =>? Field::from_str(<>)
.map_err(|err| ParseError::User {
error: DslError::Field {
field: <>.to_string(),
cause: err.to_string()
FieldPath: Vec<Field> = {
<Dot<Ident>> => {
let mut payload_subpath = false;
<>.into_iter().enumerate().map(|(index,value)| {
if index == 0 && value == "payload" {
payload_subpath = true;
}
})
if index == 1 && payload_subpath {
Field::Adt{variant_name: variant.to_string(), field_name: value}
} else {
Field::Simple { field_name: value }
}
}).collect()
}
}

Dot<T>: Vec<T> = {
<mut v:(<T> ".")*> <e:T?> => match e {
None => v,
Some(e) => {
v.push(e);
v
}
}
}

Ident: String = {
<s: r"[a-zA-Z]+\w*"> => <>.to_string()
}

extern {
Expand Down