Add function expression parsing

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2020-05-07 17:43:39 -04:00
parent d90ecfd4d7
commit 1232eca64c
3 changed files with 164 additions and 19 deletions

View File

@@ -26,17 +26,19 @@ pub enum Expr {
Un(Box<UnExpr>),
FunCall(Box<FunCallExpr>),
Index(Box<IndexExpr>),
Fun(Box<FunExpr>),
Base(BaseExpr),
}
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(),
Expr::FunCall(f) => f.span(),
Expr::Index(i) => i.span(),
Expr::Fun(f) => f.span(),
Expr::Base(b) => b.span(),
}
}
}
@@ -120,6 +122,21 @@ impl Spanned for IndexExpr {
}
}
#[derive(Derivative, Clone, PartialEq, Eq)]
#[derivative(Debug)]
pub struct FunExpr {
pub params: Vec<String>,
pub expr: Expr,
#[derivative(Debug = "ignore")]
pub span: Span,
}
impl Spanned for FunExpr {
fn span(&self) -> Span {
self.span
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum BaseExprKind {
Ident,