84 lines
1.7 KiB
Rust
84 lines
1.7 KiB
Rust
use {super::token::IntLit, chumsky::span::SimpleSpan, lasso::Spur};
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
pub struct Spanned<T> {
|
|
pub item: T,
|
|
pub span: SimpleSpan,
|
|
}
|
|
|
|
impl<T> Spanned<T> {
|
|
#[inline]
|
|
pub fn new(item: T, span: SimpleSpan) -> Self {
|
|
Self { item, span }
|
|
}
|
|
}
|
|
|
|
pub type SpanExpr<'a> = Spanned<Expr<'a>>;
|
|
pub type ExprRef<'a> = &'a SpanExpr<'a>;
|
|
pub type ExprList<'a> = &'a [SpanExpr<'a>];
|
|
pub type Ident = Spur;
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
pub enum Expr<'a> {
|
|
Ident(Ident),
|
|
Path(ExprList<'a>),
|
|
Literal(Literal),
|
|
Call(ExprRef<'a>, ExprList<'a>),
|
|
Binary(Spanned<BinaryOperator>, ExprRef<'a>, ExprRef<'a>),
|
|
Unary(Spanned<UnaryOperator>, ExprRef<'a>),
|
|
BindLocal(Spanned<Pattern>, ExprRef<'a>, Option<ExprList<'a>>),
|
|
BindIn(
|
|
Spanned<Pattern>,
|
|
ExprRef<'a>,
|
|
ExprList<'a>,
|
|
Option<ExprList<'a>>,
|
|
),
|
|
Set(ExprRef<'a>, ExprRef<'a>),
|
|
Match(ExprRef<'a>, &'a [(Spanned<Pattern>, SpanExpr<'a>)]),
|
|
Func(&'a [(Spanned<Pattern>, Spanned<Type>)], Spanned<Type>, ExprRef<'a>),
|
|
Block(ExprList<'a>),
|
|
Unit,
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
pub enum Type {
|
|
Ident(Ident),
|
|
Unit,
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
pub enum Pattern {
|
|
Ident(Ident),
|
|
Literal(Literal),
|
|
None,
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
pub enum Literal {
|
|
String(Spur),
|
|
Integer(IntLit),
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
pub enum BinaryOperator {
|
|
Plus,
|
|
Minus,
|
|
Star,
|
|
Slash,
|
|
And,
|
|
VLine,
|
|
Lt,
|
|
Gt,
|
|
Equ,
|
|
Nequ,
|
|
LtEqu,
|
|
GtEqu,
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
pub enum UnaryOperator {
|
|
Tilde,
|
|
Minus,
|
|
Star,
|
|
}
|