aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/ast.rs')
-rw-r--r--crates/ra_syntax/src/ast.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs
index 8fb6b6408..3e948800e 100644
--- a/crates/ra_syntax/src/ast.rs
+++ b/crates/ra_syntax/src/ast.rs
@@ -48,10 +48,40 @@ pub trait FnDefOwner<'a>: AstNode<'a> {
48 } 48 }
49} 49}
50 50
51// ModuleItem
52#[derive(Debug, Clone, Copy, PartialEq, Eq)]
53pub enum ItemOrMacro<'a> {
54 Item(ModuleItem<'a>),
55 Macro(MacroCall<'a>),
56}
57
58impl<'a> AstNode<'a> for ItemOrMacro<'a> {
59 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
60 let res = if let Some(item) = ModuleItem::cast(syntax) {
61 ItemOrMacro::Item(item)
62 } else if let Some(macro_call) = MacroCall::cast(syntax) {
63 ItemOrMacro::Macro(macro_call)
64 } else {
65 return None;
66 };
67 Some(res)
68 }
69 fn syntax(self) -> SyntaxNodeRef<'a> {
70 match self {
71 ItemOrMacro::Item(it) => it.syntax(),
72 ItemOrMacro::Macro(it) => it.syntax(),
73 }
74 }
75}
76
51pub trait ModuleItemOwner<'a>: AstNode<'a> { 77pub trait ModuleItemOwner<'a>: AstNode<'a> {
52 fn items(self) -> AstChildren<'a, ModuleItem<'a>> { 78 fn items(self) -> AstChildren<'a, ModuleItem<'a>> {
53 children(self) 79 children(self)
54 } 80 }
81
82 fn items_with_macros(self) -> AstChildren<'a, ItemOrMacro<'a>> {
83 children(self)
84 }
55} 85}
56 86
57pub trait TypeParamsOwner<'a>: AstNode<'a> { 87pub trait TypeParamsOwner<'a>: AstNode<'a> {