use ast;
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Expr
{
Assignment(AssignmentExpr),
Paren(ParenExpr),
Call(CallExpr),
StringLiteral(StringLiteral),
IntegerLiteral(IntegerLiteral),
Symbol(SymbolExpr),
KeyValue(KeyValueExpr),
Negate(NegateExpr),
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct AssignmentExpr
{
pub assignee: ast::Path,
pub value: Box<Expr>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct KeyValueExpr
{
pub key: String,
pub value: Box<Expr>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ParenExpr
{
pub inner: Box<Expr>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct CallExpr
{
pub callee: ast::Path,
pub arguments: Vec<ast::Argument>
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct StringLiteral
{
pub value: String,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct IntegerLiteral
{
pub value: i64,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct SymbolExpr
{
pub name: String,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct NegateExpr
{
pub inner: Box<Expr>,
}
macro_rules! expr_boilerplate {
($ty:ty => $shortname:ident) => {
impl Into<Expr> for $ty {
fn into(self) -> Expr {
Expr::$shortname(self)
}
}
}
}
expr_boilerplate!(AssignmentExpr => Assignment);
expr_boilerplate!(ParenExpr => Paren);
expr_boilerplate!(CallExpr => Call);
expr_boilerplate!(StringLiteral => StringLiteral);
expr_boilerplate!(IntegerLiteral => IntegerLiteral);
expr_boilerplate!(SymbolExpr => Symbol);
expr_boilerplate!(KeyValueExpr => KeyValue);
expr_boilerplate!(NegateExpr => Negate);