Support if-let in scopes

This commit is contained in:
Aleksey Kladov 2018-08-27 12:22:09 +03:00
parent c16530c988
commit 07cbb7d73d
12 changed files with 289 additions and 104 deletions

View file

@ -115,6 +115,18 @@ impl<'a> Module<'a> {
}
}
impl<'a> IfExpr<'a> {
pub fn then_branch(self) -> Option<Block<'a>> {
self.blocks().nth(0)
}
pub fn else_branch(self) -> Option<Block<'a>> {
self.blocks().nth(1)
}
fn blocks(self) -> impl Iterator<Item=Block<'a>> {
children(self)
}
}
fn child_opt<'a, P: AstNode<'a>, C: AstNode<'a>>(parent: P) -> Option<C> {
children(parent).next()
}