visitor-less scopes

This commit is contained in:
Aleksey Kladov 2018-08-27 10:12:28 +03:00
parent 8b0298ce09
commit c16530c988
3 changed files with 49 additions and 17 deletions

View file

@ -116,9 +116,13 @@ impl<'a> AstNode<'a> for Block<'a> {
}
impl<'a> Block<'a> {
pub fn let_stmts(self) -> impl Iterator<Item = LetStmt<'a>> + 'a {
pub fn statements(self) -> impl Iterator<Item = Stmt<'a>> + 'a {
super::children(self)
}
pub fn expr(self) -> Option<Expr<'a>> {
super::child_opt(self)
}
}
// BlockExpr
@ -1370,6 +1374,31 @@ impl<'a> ast::TypeParamsOwner<'a> for StaticDef<'a> {}
impl<'a> ast::AttrsOwner<'a> for StaticDef<'a> {}
impl<'a> StaticDef<'a> {}
// Stmt
#[derive(Debug, Clone, Copy)]
pub enum Stmt<'a> {
ExprStmt(ExprStmt<'a>),
LetStmt(LetStmt<'a>),
}
impl<'a> AstNode<'a> for Stmt<'a> {
fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
match syntax.kind() {
EXPR_STMT => Some(Stmt::ExprStmt(ExprStmt { syntax })),
LET_STMT => Some(Stmt::LetStmt(LetStmt { syntax })),
_ => None,
}
}
fn syntax(self) -> SyntaxNodeRef<'a> {
match self {
Stmt::ExprStmt(inner) => inner.syntax(),
Stmt::LetStmt(inner) => inner.syntax(),
}
}
}
impl<'a> Stmt<'a> {}
// StructDef
#[derive(Debug, Clone, Copy)]
pub struct StructDef<'a> {