Add indexing expression parsing and tests

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2020-05-06 17:55:25 -04:00
parent 44970dbf97
commit 5d3021ced7
2 changed files with 69 additions and 3 deletions

View File

@@ -25,6 +25,7 @@ pub enum Expr {
Bin(Box<BinExpr>),
Un(Box<UnExpr>),
FunCall(Box<FunCallExpr>),
Index(Box<IndexExpr>),
Base(BaseExpr),
}
@@ -35,6 +36,7 @@ impl Spanned for Expr {
Expr::Bin(b) => b.span(),
Expr::Un(u) => u.span(),
Expr::FunCall(f) => f.span(),
Expr::Index(i) => i.span(),
}
}
}
@@ -103,6 +105,21 @@ impl Spanned for FunCallExpr {
}
}
#[derive(Derivative, Clone, PartialEq, Eq)]
#[derivative(Debug)]
pub struct IndexExpr {
pub expr: Expr,
pub index: Expr,
#[derivative(Debug = "ignore")]
pub span: Span,
}
impl Spanned for IndexExpr {
fn span(&self) -> Span {
self.span
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum BaseExprKind {
Ident,