Skip to content

Commit

Permalink
feat(validatron): methods and unary expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
banditopazzo committed Dec 20, 2023
1 parent fd5b862 commit f087897
Show file tree
Hide file tree
Showing 21 changed files with 996 additions and 467 deletions.
2 changes: 1 addition & 1 deletion crates/bpf-common/src/parsing/mountinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub enum MountinfoError {
/// [the kernel documentation](https://www.kernel.org/doc/Documentation/filesystems/proc.txt).
/// To sum it up, each line contains the following fields:
///
/// ```ignore
/// ```text
/// 36 35 98:0 /mnt1 /mnt2 rw,noatime master:1 - ext3 /dev/root rw,errors=continue
/// (1)(2)(3) (4) (5) (6) (7) (8) (9) (10) (11)
/// ```
Expand Down
38 changes: 19 additions & 19 deletions crates/modules/rules-engine/src/dsl.lalrpop
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use validatron::{Operator, RelationalOperator, StringOperator, MultiOperator, Match, Field, Condition};
use validatron::{Operator, RelationalOperator, StringOperator, MultiOperator, RValue, Field, Identifier, Condition};
use lalrpop_util::ParseError;

use super::{DslError};
Expand All @@ -12,39 +12,39 @@ pub Condition: Condition = {
}

SignedCondition: Condition = {
"NOT" <b:BaseCondition> => Condition::Not{inner: Box::new(b)},
BaseCondition
"NOT" <b:BinaryCondition> => Condition::Not{inner: Box::new(b)},
BinaryCondition
}

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

let first = Condition::Base {
field_path: f.clone(),
let first = Condition::Binary {
l: f.clone(),
op: Operator::Relational(RelationalOperator::Equals),
value: iterator.next().map(|x| Match::Value(x)).ok_or(ParseError::User {
r: iterator.next().map(|x| RValue::Value(x)).ok_or(ParseError::User {
error: DslError::EmptyList
})?
};

let ret_val = iterator.fold(first, |acc, x| {
Condition::Or {
l: Box::new(acc),
r: Box::new(Condition::Base {
field_path: f.clone(),
r: Box::new(Condition::Binary {
l: f.clone(),
op: Operator::Relational(RelationalOperator::Equals),
value: Match::Value(x)
r: RValue::Value(x)
})
}
});
Expand Down Expand Up @@ -88,17 +88,17 @@ Operator: Operator = {
"CONTAINS" => Operator::Multi(MultiOperator::Contains),
}

FieldPath: Vec<Field> = {
FieldPath: Vec<Identifier> = {
<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}
Identifier::Field(Field::Adt{variant_name: variant.to_string(), field_name: value})
} else {
Field::Simple { field_name: value }
Identifier::Field(Field::Simple { field_name: value })
}
}).collect()
}
Expand Down
Loading

0 comments on commit f087897

Please sign in to comment.