add Expr type for union of BoolExpr or NumExpr

This commit is contained in:
Anand Balakrishnan 2023-09-29 13:59:39 -07:00
parent 7c81b30a8f
commit 6632e897ba
6 changed files with 32 additions and 22 deletions

View file

@ -17,7 +17,7 @@ use crate::{ArgusResult, Error};
/// All expressions that are numeric
#[derive(Clone, Debug, PartialEq, argus_derive::NumExpr)]
#[enum_dispatch(Expr)]
#[enum_dispatch(AnyExpr)]
pub enum NumExpr {
/// A signed integer literal
IntLit(IntLit),
@ -54,7 +54,7 @@ impl NumExpr {
/// All expressions that are evaluated to be of type `bool`
#[derive(Clone, Debug, PartialEq, argus_derive::BoolExpr)]
#[enum_dispatch(Expr)]
#[enum_dispatch(AnyExpr)]
pub enum BoolExpr {
/// A `bool` literal
BoolLit(BoolLit),
@ -118,6 +118,15 @@ pub enum ExprRef<'a> {
Num(&'a NumExpr),
}
/// An expression (either [`BoolExpr`] or [`NumExpr`])
#[derive(Clone, Debug, derive_more::From)]
pub enum Expr {
/// A reference to a [`BoolExpr`]
Bool(BoolExpr),
/// A reference to a [`NumExpr`]
Num(NumExpr),
}
/// Expression builder
///
/// The `ExprBuilder` is a factory structure that deals with the creation of