use std::sync::Arc; use { ast, SyntaxNode, SyntaxRoot, TreeRoot, AstNode, SyntaxKind::*, }; // ConstItem #[derive(Debug, Clone, Copy)] pub struct ConstItem> { syntax: SyntaxNode, } impl AstNode for ConstItem { fn cast(syntax: SyntaxNode) -> Option { match syntax.kind() { CONST_ITEM => Some(ConstItem { syntax }), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } } impl ast::NameOwner for ConstItem {} impl ConstItem {} // Enum #[derive(Debug, Clone, Copy)] pub struct Enum> { syntax: SyntaxNode, } impl AstNode for Enum { fn cast(syntax: SyntaxNode) -> Option { match syntax.kind() { ENUM => Some(Enum { syntax }), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } } impl ast::NameOwner for Enum {} impl Enum {} // File #[derive(Debug, Clone, Copy)] pub struct File> { syntax: SyntaxNode, } impl AstNode for File { fn cast(syntax: SyntaxNode) -> Option { match syntax.kind() { FILE => Some(File { syntax }), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } } impl File { pub fn functions<'a>(&'a self) -> impl Iterator> + 'a { self.syntax() .children() .filter_map(Function::cast) } } // Function #[derive(Debug, Clone, Copy)] pub struct Function> { syntax: SyntaxNode, } impl AstNode for Function { fn cast(syntax: SyntaxNode) -> Option { match syntax.kind() { FUNCTION => Some(Function { syntax }), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } } impl ast::NameOwner for Function {} impl Function {} // Module #[derive(Debug, Clone, Copy)] pub struct Module> { syntax: SyntaxNode, } impl AstNode for Module { fn cast(syntax: SyntaxNode) -> Option { match syntax.kind() { MODULE => Some(Module { syntax }), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } } impl ast::NameOwner for Module {} impl Module {} // Name #[derive(Debug, Clone, Copy)] pub struct Name> { syntax: SyntaxNode, } impl AstNode for Name { fn cast(syntax: SyntaxNode) -> Option { match syntax.kind() { NAME => Some(Name { syntax }), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } } impl Name {} // NameRef #[derive(Debug, Clone, Copy)] pub struct NameRef> { syntax: SyntaxNode, } impl AstNode for NameRef { fn cast(syntax: SyntaxNode) -> Option { match syntax.kind() { NAME_REF => Some(NameRef { syntax }), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } } impl NameRef {} // StaticItem #[derive(Debug, Clone, Copy)] pub struct StaticItem> { syntax: SyntaxNode, } impl AstNode for StaticItem { fn cast(syntax: SyntaxNode) -> Option { match syntax.kind() { STATIC_ITEM => Some(StaticItem { syntax }), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } } impl ast::NameOwner for StaticItem {} impl StaticItem {} // Struct #[derive(Debug, Clone, Copy)] pub struct Struct> { syntax: SyntaxNode, } impl AstNode for Struct { fn cast(syntax: SyntaxNode) -> Option { match syntax.kind() { STRUCT => Some(Struct { syntax }), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } } impl ast::NameOwner for Struct {} impl Struct {} // Trait #[derive(Debug, Clone, Copy)] pub struct Trait> { syntax: SyntaxNode, } impl AstNode for Trait { fn cast(syntax: SyntaxNode) -> Option { match syntax.kind() { TRAIT => Some(Trait { syntax }), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } } impl ast::NameOwner for Trait {} impl Trait {} // TypeItem #[derive(Debug, Clone, Copy)] pub struct TypeItem> { syntax: SyntaxNode, } impl AstNode for TypeItem { fn cast(syntax: SyntaxNode) -> Option { match syntax.kind() { TYPE_ITEM => Some(TypeItem { syntax }), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } } impl ast::NameOwner for TypeItem {} impl TypeItem {}