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-11 09:28:59 +00:00
|
|
|
// ConstItem
|
2018-08-11 08:03:22 +00:00
|
|
|
#[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() {
|
2018-08-13 15:27:26 +00:00
|
|
|
CONST_DEF => Some(ConstItem { syntax }),
|
2018-08-11 08:03:22 +00:00
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
|
|
|
|
}
|
|
|
|
|
2018-08-11 09:28:59 +00:00
|
|
|
impl<R: TreeRoot> ast::NameOwner<R> for ConstItem<R> {}
|
|
|
|
impl<R: TreeRoot> ConstItem<R> {}
|
2018-08-11 08:03:22 +00:00
|
|
|
|
2018-08-11 09:28:59 +00:00
|
|
|
// Enum
|
2018-08-11 07:56:40 +00:00
|
|
|
#[derive(Debug, Clone, Copy)]
|
|
|
|
pub struct Enum<R: TreeRoot = Arc<SyntaxRoot>> {
|
|
|
|
syntax: SyntaxNode<R>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<R: TreeRoot> AstNode<R> for Enum<R> {
|
|
|
|
fn cast(syntax: SyntaxNode<R>) -> Option<Self> {
|
|
|
|
match syntax.kind() {
|
2018-08-13 15:27:26 +00:00
|
|
|
ENUM_DEF => Some(Enum { syntax }),
|
2018-08-11 07:56:40 +00:00
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
|
|
|
|
}
|
|
|
|
|
2018-08-11 09:28:59 +00:00
|
|
|
impl<R: TreeRoot> ast::NameOwner<R> for Enum<R> {}
|
|
|
|
impl<R: TreeRoot> Enum<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> {
|
|
|
|
pub fn functions<'a>(&'a self) -> impl Iterator<Item = Function<R>> + 'a {
|
|
|
|
self.syntax()
|
|
|
|
.children()
|
|
|
|
.filter_map(Function::cast)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-11 09:28:59 +00:00
|
|
|
// Function
|
2018-08-10 12:07:43 +00:00
|
|
|
#[derive(Debug, Clone, Copy)]
|
2018-08-09 14:44:40 +00:00
|
|
|
pub struct Function<R: TreeRoot = Arc<SyntaxRoot>> {
|
2018-08-09 14:43:39 +00:00
|
|
|
syntax: SyntaxNode<R>,
|
|
|
|
}
|
|
|
|
|
2018-08-09 14:44:40 +00:00
|
|
|
impl<R: TreeRoot> AstNode<R> for Function<R> {
|
2018-08-09 14:43:39 +00:00
|
|
|
fn cast(syntax: SyntaxNode<R>) -> Option<Self> {
|
|
|
|
match syntax.kind() {
|
2018-08-13 15:27:26 +00:00
|
|
|
FN_DEF => Some(Function { syntax }),
|
2018-08-09 14:43:39 +00:00
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
|
|
|
|
}
|
|
|
|
|
2018-08-11 09:28:59 +00:00
|
|
|
impl<R: TreeRoot> ast::NameOwner<R> for Function<R> {}
|
|
|
|
impl<R: TreeRoot> Function<R> {}
|
2018-08-11 06:55:32 +00:00
|
|
|
|
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-11 09:28:59 +00:00
|
|
|
// StaticItem
|
2018-08-11 08:03:22 +00:00
|
|
|
#[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() {
|
2018-08-13 15:27:26 +00:00
|
|
|
STATIC_DEF => Some(StaticItem { syntax }),
|
2018-08-11 08:03:22 +00:00
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
|
|
|
|
}
|
|
|
|
|
2018-08-11 09:28:59 +00:00
|
|
|
impl<R: TreeRoot> ast::NameOwner<R> for StaticItem<R> {}
|
|
|
|
impl<R: TreeRoot> StaticItem<R> {}
|
2018-08-11 08:03:22 +00:00
|
|
|
|
2018-08-11 09:28:59 +00:00
|
|
|
// Struct
|
2018-08-11 07:56:40 +00:00
|
|
|
#[derive(Debug, Clone, Copy)]
|
|
|
|
pub struct Struct<R: TreeRoot = Arc<SyntaxRoot>> {
|
|
|
|
syntax: SyntaxNode<R>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<R: TreeRoot> AstNode<R> for Struct<R> {
|
|
|
|
fn cast(syntax: SyntaxNode<R>) -> Option<Self> {
|
|
|
|
match syntax.kind() {
|
2018-08-13 15:27:26 +00:00
|
|
|
STRUCT_DEF => Some(Struct { syntax }),
|
2018-08-11 07:56:40 +00:00
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
|
|
|
|
}
|
|
|
|
|
2018-08-11 09:28:59 +00:00
|
|
|
impl<R: TreeRoot> ast::NameOwner<R> for Struct<R> {}
|
|
|
|
impl<R: TreeRoot> Struct<R> {}
|
2018-08-11 07:56:40 +00:00
|
|
|
|
2018-08-11 09:28:59 +00:00
|
|
|
// Trait
|
2018-08-11 08:03:22 +00:00
|
|
|
#[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() {
|
2018-08-13 15:27:26 +00:00
|
|
|
TRAIT_DEF => Some(Trait { syntax }),
|
2018-08-11 08:03:22 +00:00
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
|
|
|
|
}
|
|
|
|
|
2018-08-11 09:28:59 +00:00
|
|
|
impl<R: TreeRoot> ast::NameOwner<R> for Trait<R> {}
|
|
|
|
impl<R: TreeRoot> Trait<R> {}
|
2018-08-11 08:03:22 +00:00
|
|
|
|
2018-08-11 13:20:37 +00:00
|
|
|
// TypeItem
|
|
|
|
#[derive(Debug, Clone, Copy)]
|
|
|
|
pub struct TypeItem<R: TreeRoot = Arc<SyntaxRoot>> {
|
|
|
|
syntax: SyntaxNode<R>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<R: TreeRoot> AstNode<R> for TypeItem<R> {
|
|
|
|
fn cast(syntax: SyntaxNode<R>) -> Option<Self> {
|
|
|
|
match syntax.kind() {
|
2018-08-13 15:27:26 +00:00
|
|
|
TYPE_DEF => Some(TypeItem { syntax }),
|
2018-08-11 13:20:37 +00:00
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<R: TreeRoot> ast::NameOwner<R> for TypeItem<R> {}
|
|
|
|
impl<R: TreeRoot> TypeItem<R> {}
|
|
|
|
|