Generate accessors

This commit is contained in:
Aleksey Kladov 2018-08-11 09:55:32 +03:00
parent 7581984601
commit b18d2882f4
4 changed files with 42 additions and 20 deletions

View file

@ -20,6 +20,14 @@ impl<R: TreeRoot> AstNode<R> for File<R> {
fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
}
impl<R: TreeRoot> File<R> {
pub fn functions<'a>(&'a self) -> impl Iterator<Item = Function<R>> + 'a {
self.syntax()
.children()
.filter_map(Function::cast)
}
}
#[derive(Debug, Clone, Copy)]
pub struct Function<R: TreeRoot = Arc<SyntaxRoot>> {
@ -36,6 +44,15 @@ impl<R: TreeRoot> AstNode<R> for Function<R> {
fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
}
impl<R: TreeRoot> Function<R> {
pub fn name(&self) -> Option<Name<R>> {
self.syntax()
.children()
.filter_map(Name::cast)
.next()
}
}
#[derive(Debug, Clone, Copy)]
pub struct Name<R: TreeRoot = Arc<SyntaxRoot>> {
@ -52,3 +69,5 @@ impl<R: TreeRoot> AstNode<R> for Name<R> {
fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
}
impl<R: TreeRoot> Name<R> {}