Generate accessors
This commit is contained in:
@@ -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> {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user