2018-08-09 14:43:39 +00:00
|
|
|
use std::sync::Arc;
|
|
|
|
use {
|
2018-08-11 09:28:59 +00:00
|
|
|
ast,
|
2018-08-09 14:43:39 +00:00
|
|
|
SyntaxNode, SyntaxRoot, TreeRoot, AstNode,
|
|
|
|
SyntaxKind::*,
|
|
|
|
};
|
|
|
|
|
2018-08-13 15:36:16 +00:00
|
|
|
// ConstDef
|
2018-08-11 08:03:22 +00:00
|
|
|
#[derive(Debug, Clone, Copy)]
|
2018-08-13 15:36:16 +00:00
|
|
|
pub struct ConstDef<R: TreeRoot = Arc<SyntaxRoot>> {
|
2018-08-11 08:03:22 +00:00
|
|
|
syntax: SyntaxNode<R>,
|
|
|
|
}
|
|
|
|
|
2018-08-13 15:36:16 +00:00
|
|
|
impl<R: TreeRoot> AstNode<R> for ConstDef<R> {
|
2018-08-11 08:03:22 +00:00
|
|
|
fn cast(syntax: SyntaxNode<R>) -> Option<Self> {
|
|
|
|
match syntax.kind() {
|
2018-08-13 15:36:16 +00:00
|
|
|
CONST_DEF => Some(ConstDef { syntax }),
|
2018-08-11 08:03:22 +00:00
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
|
|
|
|
}
|
|
|
|
|
2018-08-13 15:36:16 +00:00
|
|
|
impl<R: TreeRoot> ast::NameOwner<R> for ConstDef<R> {}
|
|
|
|
impl<R: TreeRoot> ConstDef<R> {}
|
2018-08-11 08:03:22 +00:00
|
|
|
|
2018-08-13 15:36:16 +00:00
|
|
|
// EnumDef
|
2018-08-11 07:56:40 +00:00
|
|
|
#[derive(Debug, Clone, Copy)]
|
2018-08-13 15:36:16 +00:00
|
|
|
pub struct EnumDef<R: TreeRoot = Arc<SyntaxRoot>> {
|
2018-08-11 07:56:40 +00:00
|
|
|
syntax: SyntaxNode<R>,
|
|
|
|
}
|
|
|
|
|
2018-08-13 15:36:16 +00:00
|
|
|
impl<R: TreeRoot> AstNode<R> for EnumDef<R> {
|
2018-08-11 07:56:40 +00:00
|
|
|
fn cast(syntax: SyntaxNode<R>) -> Option<Self> {
|
|
|
|
match syntax.kind() {
|
2018-08-13 15:36:16 +00:00
|
|
|
ENUM_DEF => Some(EnumDef { syntax }),
|
2018-08-11 07:56:40 +00:00
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
|
|
|
|
}
|
|
|
|
|
2018-08-13 15:36:16 +00:00
|
|
|
impl<R: TreeRoot> ast::NameOwner<R> for EnumDef<R> {}
|
|
|
|
impl<R: TreeRoot> EnumDef<R> {}
|
2018-08-11 07:56:40 +00:00
|
|
|
|
2018-08-11 09:28:59 +00:00
|
|
|
// File
|
2018-08-10 12:07:43 +00:00
|
|
|
#[derive(Debug, Clone, Copy)]
|
2018-08-09 14:43:39 +00:00
|
|
|
pub struct File<R: TreeRoot = Arc<SyntaxRoot>> {
|
|
|
|
syntax: SyntaxNode<R>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<R: TreeRoot> AstNode<R> for File<R> {
|
|
|
|
fn cast(syntax: SyntaxNode<R>) -> Option<Self> {
|
|
|
|
match syntax.kind() {
|
|
|
|
FILE => Some(File { syntax }),
|
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
|
|
|
|
}
|
|
|
|
|
2018-08-11 06:55:32 +00:00
|
|
|
impl<R: TreeRoot> File<R> {
|
2018-08-13 15:36:16 +00:00
|
|
|
pub fn functions<'a>(&'a self) -> impl Iterator<Item = FnDef<R>> + 'a {
|
2018-08-11 06:55:32 +00:00
|
|
|
self.syntax()
|
|
|
|
.children()
|
2018-08-13 15:36:16 +00:00
|
|
|
.filter_map(FnDef::cast)
|
2018-08-11 06:55:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-13 15:36:16 +00:00
|
|
|
// FnDef
|
2018-08-10 12:07:43 +00:00
|
|
|
#[derive(Debug, Clone, Copy)]
|
2018-08-13 15:36:16 +00:00
|
|
|
pub struct FnDef<R: TreeRoot = Arc<SyntaxRoot>> {
|
2018-08-09 14:43:39 +00:00
|
|
|
syntax: SyntaxNode<R>,
|
|
|
|
}
|
|
|
|
|
2018-08-13 15:36:16 +00:00
|
|
|
impl<R: TreeRoot> AstNode<R> for FnDef<R> {
|
2018-08-09 14:43:39 +00:00
|
|
|
fn cast(syntax: SyntaxNode<R>) -> Option<Self> {
|
|
|
|
match syntax.kind() {
|
2018-08-13 15:36:16 +00:00
|
|
|
FN_DEF => Some(FnDef { syntax }),
|
2018-08-09 14:43:39 +00:00
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
|
|
|
|
}
|
|
|
|
|
2018-08-13 15:36:16 +00:00
|
|
|
impl<R: TreeRoot> ast::NameOwner<R> for FnDef<R> {}
|
|
|
|
impl<R: TreeRoot> FnDef<R> {}
|
2018-08-11 06:55:32 +00:00
|
|
|
|
2018-08-14 08:20:09 +00:00
|
|
|
// ImplItem
|
|
|
|
#[derive(Debug, Clone, Copy)]
|
|
|
|
pub struct ImplItem<R: TreeRoot = Arc<SyntaxRoot>> {
|
|
|
|
syntax: SyntaxNode<R>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<R: TreeRoot> AstNode<R> for ImplItem<R> {
|
|
|
|
fn cast(syntax: SyntaxNode<R>) -> Option<Self> {
|
|
|
|
match syntax.kind() {
|
|
|
|
IMPL_ITEM => Some(ImplItem { syntax }),
|
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<R: TreeRoot> ImplItem<R> {}
|
|
|
|
|
2018-08-11 09:28:59 +00:00
|
|
|
// Module
|
2018-08-11 08:03:22 +00:00
|
|
|
#[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 }
|
|
|
|
}
|
|
|
|
|
2018-08-11 09:28:59 +00:00
|
|
|
impl<R: TreeRoot> ast::NameOwner<R> for Module<R> {}
|
|
|
|
impl<R: TreeRoot> Module<R> {}
|
2018-08-11 08:03:22 +00:00
|
|
|
|
2018-08-11 09:28:59 +00:00
|
|
|
// Name
|
2018-08-10 12:07:43 +00:00
|
|
|
#[derive(Debug, Clone, Copy)]
|
2018-08-09 14:43:39 +00:00
|
|
|
pub struct Name<R: TreeRoot = Arc<SyntaxRoot>> {
|
|
|
|
syntax: SyntaxNode<R>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<R: TreeRoot> AstNode<R> for Name<R> {
|
|
|
|
fn cast(syntax: SyntaxNode<R>) -> Option<Self> {
|
|
|
|
match syntax.kind() {
|
|
|
|
NAME => Some(Name { syntax }),
|
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
|
|
|
|
}
|
|
|
|
|
2018-08-11 06:55:32 +00:00
|
|
|
impl<R: TreeRoot> Name<R> {}
|
|
|
|
|
2018-08-13 13:35:17 +00:00
|
|
|
// NameRef
|
|
|
|
#[derive(Debug, Clone, Copy)]
|
|
|
|
pub struct NameRef<R: TreeRoot = Arc<SyntaxRoot>> {
|
|
|
|
syntax: SyntaxNode<R>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<R: TreeRoot> AstNode<R> for NameRef<R> {
|
|
|
|
fn cast(syntax: SyntaxNode<R>) -> Option<Self> {
|
|
|
|
match syntax.kind() {
|
|
|
|
NAME_REF => Some(NameRef { syntax }),
|
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<R: TreeRoot> NameRef<R> {}
|
|
|
|
|
2018-08-13 15:36:16 +00:00
|
|
|
// StaticDef
|
2018-08-11 08:03:22 +00:00
|
|
|
#[derive(Debug, Clone, Copy)]
|
2018-08-13 15:36:16 +00:00
|
|
|
pub struct StaticDef<R: TreeRoot = Arc<SyntaxRoot>> {
|
2018-08-11 08:03:22 +00:00
|
|
|
syntax: SyntaxNode<R>,
|
|
|
|
}
|
|
|
|
|
2018-08-13 15:36:16 +00:00
|
|
|
impl<R: TreeRoot> AstNode<R> for StaticDef<R> {
|
2018-08-11 08:03:22 +00:00
|
|
|
fn cast(syntax: SyntaxNode<R>) -> Option<Self> {
|
|
|
|
match syntax.kind() {
|
2018-08-13 15:36:16 +00:00
|
|
|
STATIC_DEF => Some(StaticDef { syntax }),
|
2018-08-11 08:03:22 +00:00
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
|
|
|
|
}
|
|
|
|
|
2018-08-13 15:36:16 +00:00
|
|
|
impl<R: TreeRoot> ast::NameOwner<R> for StaticDef<R> {}
|
|
|
|
impl<R: TreeRoot> StaticDef<R> {}
|
2018-08-11 08:03:22 +00:00
|
|
|
|
2018-08-13 15:36:16 +00:00
|
|
|
// StructDef
|
2018-08-11 07:56:40 +00:00
|
|
|
#[derive(Debug, Clone, Copy)]
|
2018-08-13 15:36:16 +00:00
|
|
|
pub struct StructDef<R: TreeRoot = Arc<SyntaxRoot>> {
|
2018-08-11 07:56:40 +00:00
|
|
|
syntax: SyntaxNode<R>,
|
|
|
|
}
|
|
|
|
|
2018-08-13 15:36:16 +00:00
|
|
|
impl<R: TreeRoot> AstNode<R> for StructDef<R> {
|
2018-08-11 07:56:40 +00:00
|
|
|
fn cast(syntax: SyntaxNode<R>) -> Option<Self> {
|
|
|
|
match syntax.kind() {
|
2018-08-13 15:36:16 +00:00
|
|
|
STRUCT_DEF => Some(StructDef { syntax }),
|
2018-08-11 07:56:40 +00:00
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
|
|
|
|
}
|
|
|
|
|
2018-08-13 15:36:16 +00:00
|
|
|
impl<R: TreeRoot> ast::NameOwner<R> for StructDef<R> {}
|
|
|
|
impl<R: TreeRoot> StructDef<R> {}
|
2018-08-11 07:56:40 +00:00
|
|
|
|
2018-08-13 15:36:16 +00:00
|
|
|
// TraitDef
|
2018-08-11 08:03:22 +00:00
|
|
|
#[derive(Debug, Clone, Copy)]
|
2018-08-13 15:36:16 +00:00
|
|
|
pub struct TraitDef<R: TreeRoot = Arc<SyntaxRoot>> {
|
2018-08-11 08:03:22 +00:00
|
|
|
syntax: SyntaxNode<R>,
|
|
|
|
}
|
|
|
|
|
2018-08-13 15:36:16 +00:00
|
|
|
impl<R: TreeRoot> AstNode<R> for TraitDef<R> {
|
2018-08-11 08:03:22 +00:00
|
|
|
fn cast(syntax: SyntaxNode<R>) -> Option<Self> {
|
|
|
|
match syntax.kind() {
|
2018-08-13 15:36:16 +00:00
|
|
|
TRAIT_DEF => Some(TraitDef { syntax }),
|
2018-08-11 08:03:22 +00:00
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
|
|
|
|
}
|
|
|
|
|
2018-08-13 15:36:16 +00:00
|
|
|
impl<R: TreeRoot> ast::NameOwner<R> for TraitDef<R> {}
|
|
|
|
impl<R: TreeRoot> TraitDef<R> {}
|
2018-08-11 08:03:22 +00:00
|
|
|
|
2018-08-13 15:36:16 +00:00
|
|
|
// TypeDef
|
2018-08-11 13:20:37 +00:00
|
|
|
#[derive(Debug, Clone, Copy)]
|
2018-08-13 15:36:16 +00:00
|
|
|
pub struct TypeDef<R: TreeRoot = Arc<SyntaxRoot>> {
|
2018-08-11 13:20:37 +00:00
|
|
|
syntax: SyntaxNode<R>,
|
|
|
|
}
|
|
|
|
|
2018-08-13 15:36:16 +00:00
|
|
|
impl<R: TreeRoot> AstNode<R> for TypeDef<R> {
|
2018-08-11 13:20:37 +00:00
|
|
|
fn cast(syntax: SyntaxNode<R>) -> Option<Self> {
|
|
|
|
match syntax.kind() {
|
2018-08-13 15:36:16 +00:00
|
|
|
TYPE_DEF => Some(TypeDef { syntax }),
|
2018-08-11 13:20:37 +00:00
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
|
|
|
|
}
|
|
|
|
|
2018-08-13 15:36:16 +00:00
|
|
|
impl<R: TreeRoot> ast::NameOwner<R> for TypeDef<R> {}
|
|
|
|
impl<R: TreeRoot> TypeDef<R> {}
|
2018-08-11 13:20:37 +00:00
|
|
|
|