This commit is contained in:
Aleksey Kladov 2018-08-11 11:03:22 +03:00
parent 78f41ea707
commit d5119133fc
5 changed files with 124 additions and 13 deletions

View file

@ -4,6 +4,30 @@ use {
SyntaxKind::*,
};
#[derive(Debug, Clone, Copy)]
pub struct ConstItem<R: TreeRoot = Arc<SyntaxRoot>> {
syntax: SyntaxNode<R>,
}
impl<R: TreeRoot> AstNode<R> for ConstItem<R> {
fn cast(syntax: SyntaxNode<R>) -> Option<Self> {
match syntax.kind() {
CONST_ITEM => Some(ConstItem { syntax }),
_ => None,
}
}
fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
}
impl<R: TreeRoot> ConstItem<R> {
pub fn name(&self) -> Option<Name<R>> {
self.syntax()
.children()
.filter_map(Name::cast)
.next()
}
}
#[derive(Debug, Clone, Copy)]
pub struct Enum<R: TreeRoot = Arc<SyntaxRoot>> {
syntax: SyntaxNode<R>,
@ -75,6 +99,30 @@ impl<R: TreeRoot> Function<R> {
}
}
#[derive(Debug, Clone, Copy)]
pub struct Module<R: TreeRoot = Arc<SyntaxRoot>> {
syntax: SyntaxNode<R>,
}
impl<R: TreeRoot> AstNode<R> for Module<R> {
fn cast(syntax: SyntaxNode<R>) -> Option<Self> {
match syntax.kind() {
MODULE => Some(Module { syntax }),
_ => None,
}
}
fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
}
impl<R: TreeRoot> Module<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>> {
syntax: SyntaxNode<R>,
@ -92,6 +140,30 @@ impl<R: TreeRoot> AstNode<R> for Name<R> {
impl<R: TreeRoot> Name<R> {}
#[derive(Debug, Clone, Copy)]
pub struct StaticItem<R: TreeRoot = Arc<SyntaxRoot>> {
syntax: SyntaxNode<R>,
}
impl<R: TreeRoot> AstNode<R> for StaticItem<R> {
fn cast(syntax: SyntaxNode<R>) -> Option<Self> {
match syntax.kind() {
STATIC_ITEM => Some(StaticItem { syntax }),
_ => None,
}
}
fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
}
impl<R: TreeRoot> StaticItem<R> {
pub fn name(&self) -> Option<Name<R>> {
self.syntax()
.children()
.filter_map(Name::cast)
.next()
}
}
#[derive(Debug, Clone, Copy)]
pub struct Struct<R: TreeRoot = Arc<SyntaxRoot>> {
syntax: SyntaxNode<R>,
@ -116,3 +188,27 @@ impl<R: TreeRoot> Struct<R> {
}
}
#[derive(Debug, Clone, Copy)]
pub struct Trait<R: TreeRoot = Arc<SyntaxRoot>> {
syntax: SyntaxNode<R>,
}
impl<R: TreeRoot> AstNode<R> for Trait<R> {
fn cast(syntax: SyntaxNode<R>) -> Option<Self> {
match syntax.kind() {
TRAIT => Some(Trait { syntax }),
_ => None,
}
}
fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
}
impl<R: TreeRoot> Trait<R> {
pub fn name(&self) -> Option<Name<R>> {
self.syntax()
.children()
.filter_map(Name::cast)
.next()
}
}