2024-06-14 18:38:37 +02:00
|
|
|
use std::rc::Rc;
|
|
|
|
use crate::expressions::expression::Expression;
|
|
|
|
use crate::expressions::operator::BinaryOperator;
|
2024-06-05 20:41:00 +02:00
|
|
|
|
2024-06-14 18:38:37 +02:00
|
|
|
#[inline]
|
2024-06-25 19:57:23 +02:00
|
|
|
#[must_use]
|
2024-06-14 18:38:37 +02:00
|
|
|
pub fn and<L, R>(left: L, right: R) -> Expression
|
|
|
|
where
|
|
|
|
L: Into<Rc<Expression>>,
|
|
|
|
R: Into<Rc<Expression>>,
|
|
|
|
{
|
|
|
|
binary(left, BinaryOperator::And, right)
|
2024-06-05 20:41:00 +02:00
|
|
|
}
|
|
|
|
|
2024-06-14 18:38:37 +02:00
|
|
|
#[inline]
|
2024-06-25 19:57:23 +02:00
|
|
|
#[must_use]
|
2024-06-14 18:38:37 +02:00
|
|
|
pub fn or<L, R>(left: L, right: R) -> Expression
|
|
|
|
where
|
|
|
|
L: Into<Rc<Expression>>,
|
|
|
|
R: Into<Rc<Expression>>,
|
|
|
|
{
|
|
|
|
binary(left, BinaryOperator::Or, right)
|
2024-06-05 20:41:00 +02:00
|
|
|
}
|
|
|
|
|
2024-06-14 18:38:37 +02:00
|
|
|
#[inline]
|
2024-06-25 19:57:23 +02:00
|
|
|
#[must_use]
|
2024-06-14 18:38:37 +02:00
|
|
|
pub fn implies<L, R>(left: L, right: R) -> Expression
|
|
|
|
where
|
|
|
|
L: Into<Rc<Expression>>,
|
|
|
|
R: Into<Rc<Expression>>,
|
|
|
|
{
|
|
|
|
binary(left, BinaryOperator::Implication, right)
|
2024-06-05 20:41:00 +02:00
|
|
|
}
|
|
|
|
|
2024-06-14 18:38:37 +02:00
|
|
|
#[inline]
|
2024-06-25 19:57:23 +02:00
|
|
|
#[must_use]
|
2024-06-14 18:38:37 +02:00
|
|
|
pub fn binary<L, R>(left: L, operator: BinaryOperator, right: R) -> Expression
|
|
|
|
where
|
|
|
|
L: Into<Rc<Expression>>,
|
|
|
|
R: Into<Rc<Expression>>,
|
|
|
|
{
|
|
|
|
Expression::Binary { left: left.into(), operator, right: right.into() }
|
2024-06-05 20:41:00 +02:00
|
|
|
}
|
|
|
|
|
2024-06-14 18:38:37 +02:00
|
|
|
#[inline]
|
2024-06-25 19:57:23 +02:00
|
|
|
#[must_use]
|
2024-06-14 18:38:37 +02:00
|
|
|
pub fn not<T: Into<Rc<Expression>>>(value: T) -> Expression {
|
|
|
|
Expression::Not(value.into())
|
2024-06-05 20:41:00 +02:00
|
|
|
}
|
|
|
|
|
2024-06-14 18:38:37 +02:00
|
|
|
#[inline]
|
2024-06-25 19:57:23 +02:00
|
|
|
#[must_use]
|
2024-06-14 18:38:37 +02:00
|
|
|
pub fn atomic<T: Into<String>>(value: T) -> Expression {
|
|
|
|
Expression::Atomic(value.into())
|
2024-06-05 20:41:00 +02:00
|
|
|
}
|
|
|
|
|
2024-06-14 18:38:37 +02:00
|
|
|
// TODO eval function using nom parser
|