2020-04-27 20:17:16 -04:00
|
|
|
use crate::syn::{op::*, span::*};
|
2020-05-02 18:42:01 -04:00
|
|
|
use derivative::Derivative;
|
2020-04-27 20:17:16 -04:00
|
|
|
|
2020-05-02 18:42:01 -04:00
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
|
|
|
pub enum Stmt {
|
2020-05-05 16:38:07 -04:00
|
|
|
Assign(AssignStmt),
|
2020-05-02 18:42:01 -04:00
|
|
|
Expr(Expr),
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-05 16:38:07 -04:00
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
|
|
|
pub struct AssignStmt {
|
|
|
|
|
pub lhs: Expr,
|
|
|
|
|
pub rhs: Expr,
|
|
|
|
|
pub span: Span,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Spanned for AssignStmt {
|
|
|
|
|
fn span(&self) -> Span {
|
|
|
|
|
self.span
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-02 18:42:01 -04:00
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
2020-04-27 20:17:16 -04:00
|
|
|
pub enum Expr {
|
|
|
|
|
Base(BaseExpr),
|
|
|
|
|
Bin(Box<BinExpr>),
|
|
|
|
|
Un(Box<UnExpr>),
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-02 18:42:01 -04:00
|
|
|
impl Spanned for Expr {
|
|
|
|
|
fn span(&self) -> Span {
|
|
|
|
|
match self {
|
|
|
|
|
Expr::Base(b) => b.span(),
|
|
|
|
|
Expr::Bin(b) => b.span(),
|
|
|
|
|
Expr::Un(u) => u.span(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-27 20:17:16 -04:00
|
|
|
impl From<UnExpr> for Expr {
|
|
|
|
|
fn from(un: UnExpr) -> Self {
|
|
|
|
|
Expr::Un(Box::new(un))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl From<BinExpr> for Expr {
|
|
|
|
|
fn from(bin: BinExpr) -> Self {
|
|
|
|
|
Expr::Bin(Box::new(bin))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl From<BaseExpr> for Expr {
|
|
|
|
|
fn from(base: BaseExpr) -> Self {
|
|
|
|
|
Expr::Base(base)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-02 18:42:01 -04:00
|
|
|
#[derive(Derivative, Clone, PartialEq, Eq)]
|
|
|
|
|
#[derivative(Debug)]
|
2020-04-27 20:17:16 -04:00
|
|
|
pub struct BinExpr {
|
|
|
|
|
pub lhs: Expr,
|
|
|
|
|
pub op: BinOp,
|
|
|
|
|
pub rhs: Expr,
|
2020-05-02 18:42:01 -04:00
|
|
|
#[derivative(Debug = "ignore")]
|
|
|
|
|
pub span: Span,
|
2020-04-27 20:17:16 -04:00
|
|
|
}
|
|
|
|
|
|
2020-05-02 18:42:01 -04:00
|
|
|
impl Spanned for BinExpr {
|
|
|
|
|
fn span(&self) -> Span {
|
|
|
|
|
self.span
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Derivative, Clone, PartialEq, Eq)]
|
|
|
|
|
#[derivative(Debug)]
|
2020-04-27 20:17:16 -04:00
|
|
|
pub struct UnExpr {
|
|
|
|
|
pub op: UnOp,
|
|
|
|
|
pub expr: Expr,
|
2020-05-02 18:42:01 -04:00
|
|
|
#[derivative(Debug = "ignore")]
|
2020-04-27 20:17:16 -04:00
|
|
|
pub span: Span,
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-02 18:42:01 -04:00
|
|
|
impl Spanned for UnExpr {
|
|
|
|
|
fn span(&self) -> Span {
|
|
|
|
|
self.span
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
2020-04-27 20:17:16 -04:00
|
|
|
pub enum BaseExprKind {
|
|
|
|
|
Ident,
|
|
|
|
|
Num,
|
|
|
|
|
Str,
|
|
|
|
|
Sym,
|
|
|
|
|
List(Vec<Expr>),
|
|
|
|
|
Object(Vec<(Expr, Expr)>),
|
|
|
|
|
Tuple(Vec<Expr>),
|
2020-05-06 16:57:28 -04:00
|
|
|
Block(Vec<Stmt>),
|
2020-04-27 20:17:16 -04:00
|
|
|
}
|
|
|
|
|
|
2020-05-02 18:42:01 -04:00
|
|
|
#[derive(Derivative, Clone, PartialEq, Eq)]
|
|
|
|
|
#[derivative(Debug)]
|
2020-04-27 20:17:16 -04:00
|
|
|
pub struct BaseExpr {
|
|
|
|
|
pub kind: BaseExprKind,
|
2020-05-02 18:42:01 -04:00
|
|
|
#[derivative(Debug = "ignore")]
|
2020-04-27 20:17:16 -04:00
|
|
|
pub span: Span,
|
|
|
|
|
}
|
2020-05-02 18:42:01 -04:00
|
|
|
|
|
|
|
|
impl Spanned for BaseExpr {
|
|
|
|
|
fn span(&self) -> Span {
|
|
|
|
|
self.span
|
|
|
|
|
}
|
|
|
|
|
}
|