feat: partial incorporation of custom predicates into statement and operation structures in middleware (#84)

* Add custom predicates to middleware Statement enum

* Add custom op enum variant and wildcard matching procedures
This commit is contained in:
Ahmad Afuni 2025-02-26 00:44:27 +10:00 committed by GitHub
parent 538353a701
commit 05c21ebe6a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 119 additions and 36 deletions

View file

@ -1,6 +1,6 @@
use anyhow::{anyhow, Result};
use super::Statement;
use super::{CustomPredicateRef, Statement};
use crate::middleware::{AnchoredKey, SELF};
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
@ -42,6 +42,7 @@ pub enum Operation {
SumOf(Statement, Statement, Statement),
ProductOf(Statement, Statement, Statement),
MaxOf(Statement, Statement, Statement),
Custom(CustomPredicateRef, Vec<Statement>),
}
impl Operation {
@ -64,6 +65,7 @@ impl Operation {
Self::SumOf(_, _, _) => SumOf,
Self::ProductOf(_, _, _) => ProductOf,
Self::MaxOf(_, _, _) => MaxOf,
Self::Custom(_, _) => todo!(),
}
}
@ -85,6 +87,7 @@ impl Operation {
Self::SumOf(s1, s2, s3) => vec![s1, s2, s3],
Self::ProductOf(s1, s2, s3) => vec![s1, s2, s3],
Self::MaxOf(s1, s2, s3) => vec![s1, s2, s3],
Self::Custom(_, args) => args,
}
}
/// Forms operation from op-code and arguments.
@ -171,6 +174,10 @@ impl Operation {
let v3: i64 = v3.clone().try_into()?;
Ok((v1 == v2 + v3) && ak4 == ak1 && ak5 == ak2 && ak6 == ak3)
}
(
Self::Custom(CustomPredicateRef(cpb, i), _args),
Custom(CustomPredicateRef(s_cpb, s_i), _s_args),
) if cpb == s_cpb && i == s_i => todo!(),
_ => Err(anyhow!(
"Invalid deduction: {:?} ⇏ {:#}",
self,