use super::{span::Spanned, value::Value};
pub type Expr = Spanned<ExprKind>;
#[derive(Debug, Clone)]
pub enum ExprKind {
Literal(Value),
ArrayLiteral(Vec<Expr>),
Variable(VariableRef),
ProcessorCall(ProcessorCall),
CommandCall(CommandCall),
Trigger(TriggerRef),
Document(DocumentRef),
BinaryOp {
left: Box<Expr>,
op: BinOp,
right: Box<Expr>,
},
UnaryOp { op: UnaryOp, operand: Box<Expr> },
}
#[derive(Debug, Clone)]
pub struct VariableRef {
pub scope: Option<String>,
pub name: String,
}
#[derive(Debug, Clone)]
pub struct ProcessorCall {
pub namespace: String,
pub name: String,
pub properties: Vec<ProcessorProperty>,
}
#[derive(Debug, Clone)]
pub struct ProcessorProperty {
pub key: String,
pub value: Expr,
}
#[derive(Debug, Clone)]
pub struct CommandCall {
pub name: String,
pub args: Vec<Expr>,
}
#[derive(Debug, Clone)]
pub struct TriggerRef {
pub entry_id: Box<Expr>,
}
#[derive(Debug, Clone)]
pub struct DocumentRef {
pub document_id: Box<Expr>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BinOp {
Eq,
NotEq,
Lt,
Gt,
LtEq,
GtEq,
And,
Or,
Add,
Sub,
Mul,
Div,
}
impl BinOp {
pub fn precedence(&self) -> u8 {
match self {
BinOp::Or => 1,
BinOp::And => 2,
BinOp::Eq | BinOp::NotEq => 3,
BinOp::Lt | BinOp::Gt | BinOp::LtEq | BinOp::GtEq => 4,
BinOp::Add | BinOp::Sub => 5,
BinOp::Mul | BinOp::Div => 6,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum UnaryOp {
Not,
Neg,
}