58 lines
1.2 KiB
Rust
Raw Normal View History

use std::rc::Rc;
use crate::expressions::expression::Expression;
use crate::expressions::operator::BinaryOperator;
2024-06-05 20:41:00 +02:00
#[inline]
#[must_use]
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
}
#[inline]
#[must_use]
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
}
#[inline]
#[must_use]
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
}
#[inline]
#[must_use]
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
}
#[inline]
#[must_use]
pub fn not<T: Into<Rc<Expression>>>(value: T) -> Expression {
Expression::Not(value.into())
2024-06-05 20:41:00 +02:00
}
#[inline]
#[must_use]
pub fn atomic<T: Into<String>>(value: T) -> Expression {
Expression::Atomic(value.into())
2024-06-05 20:41:00 +02:00
}
// TODO eval function using nom parser