diff options
author | Jonas Schievink <jonasschievink@gmail.com> | 2020-12-15 17:43:19 +0000 |
---|---|---|
committer | Jonas Schievink <jonasschievink@gmail.com> | 2020-12-15 17:43:34 +0000 |
commit | c31c3246a8c87a3639623c30b692a57e728bb046 (patch) | |
tree | e66cdc459e249767c69c1b29b13e85fe30bdc935 /crates/syntax/src/ast/generated | |
parent | bd4c352831662762ee7a66da77ec9adf623b0a0a (diff) |
Basic support for decl macros 2.0
Diffstat (limited to 'crates/syntax/src/ast/generated')
-rw-r--r-- | crates/syntax/src/ast/generated/nodes.rs | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/crates/syntax/src/ast/generated/nodes.rs b/crates/syntax/src/ast/generated/nodes.rs index 0ad75214f..6eae323f4 100644 --- a/crates/syntax/src/ast/generated/nodes.rs +++ b/crates/syntax/src/ast/generated/nodes.rs | |||
@@ -286,6 +286,18 @@ impl MacroRules { | |||
286 | pub fn token_tree(&self) -> Option<TokenTree> { support::child(&self.syntax) } | 286 | pub fn token_tree(&self) -> Option<TokenTree> { support::child(&self.syntax) } |
287 | } | 287 | } |
288 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 288 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
289 | pub struct MacroDef { | ||
290 | pub(crate) syntax: SyntaxNode, | ||
291 | } | ||
292 | impl ast::AttrsOwner for MacroDef {} | ||
293 | impl ast::NameOwner for MacroDef {} | ||
294 | impl ast::VisibilityOwner for MacroDef {} | ||
295 | impl MacroDef { | ||
296 | pub fn macro_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![macro]) } | ||
297 | pub fn args(&self) -> Option<TokenTree> { support::child(&self.syntax) } | ||
298 | pub fn body(&self) -> Option<TokenTree> { support::child(&self.syntax) } | ||
299 | } | ||
300 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
289 | pub struct Module { | 301 | pub struct Module { |
290 | pub(crate) syntax: SyntaxNode, | 302 | pub(crate) syntax: SyntaxNode, |
291 | } | 303 | } |
@@ -1332,6 +1344,7 @@ pub enum Item { | |||
1332 | Impl(Impl), | 1344 | Impl(Impl), |
1333 | MacroCall(MacroCall), | 1345 | MacroCall(MacroCall), |
1334 | MacroRules(MacroRules), | 1346 | MacroRules(MacroRules), |
1347 | MacroDef(MacroDef), | ||
1335 | Module(Module), | 1348 | Module(Module), |
1336 | Static(Static), | 1349 | Static(Static), |
1337 | Struct(Struct), | 1350 | Struct(Struct), |
@@ -1689,6 +1702,17 @@ impl AstNode for MacroRules { | |||
1689 | } | 1702 | } |
1690 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 1703 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1691 | } | 1704 | } |
1705 | impl AstNode for MacroDef { | ||
1706 | fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_DEF } | ||
1707 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1708 | if Self::can_cast(syntax.kind()) { | ||
1709 | Some(Self { syntax }) | ||
1710 | } else { | ||
1711 | None | ||
1712 | } | ||
1713 | } | ||
1714 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1715 | } | ||
1692 | impl AstNode for Module { | 1716 | impl AstNode for Module { |
1693 | fn can_cast(kind: SyntaxKind) -> bool { kind == MODULE } | 1717 | fn can_cast(kind: SyntaxKind) -> bool { kind == MODULE } |
1694 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1718 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
@@ -3086,6 +3110,9 @@ impl From<MacroCall> for Item { | |||
3086 | impl From<MacroRules> for Item { | 3110 | impl From<MacroRules> for Item { |
3087 | fn from(node: MacroRules) -> Item { Item::MacroRules(node) } | 3111 | fn from(node: MacroRules) -> Item { Item::MacroRules(node) } |
3088 | } | 3112 | } |
3113 | impl From<MacroDef> for Item { | ||
3114 | fn from(node: MacroDef) -> Item { Item::MacroDef(node) } | ||
3115 | } | ||
3089 | impl From<Module> for Item { | 3116 | impl From<Module> for Item { |
3090 | fn from(node: Module) -> Item { Item::Module(node) } | 3117 | fn from(node: Module) -> Item { Item::Module(node) } |
3091 | } | 3118 | } |
@@ -3111,7 +3138,7 @@ impl AstNode for Item { | |||
3111 | fn can_cast(kind: SyntaxKind) -> bool { | 3138 | fn can_cast(kind: SyntaxKind) -> bool { |
3112 | match kind { | 3139 | match kind { |
3113 | CONST | ENUM | EXTERN_BLOCK | EXTERN_CRATE | FN | IMPL | MACRO_CALL | MACRO_RULES | 3140 | CONST | ENUM | EXTERN_BLOCK | EXTERN_CRATE | FN | IMPL | MACRO_CALL | MACRO_RULES |
3114 | | MODULE | STATIC | STRUCT | TRAIT | TYPE_ALIAS | UNION | USE => true, | 3141 | | MACRO_DEF | MODULE | STATIC | STRUCT | TRAIT | TYPE_ALIAS | UNION | USE => true, |
3115 | _ => false, | 3142 | _ => false, |
3116 | } | 3143 | } |
3117 | } | 3144 | } |
@@ -3125,6 +3152,7 @@ impl AstNode for Item { | |||
3125 | IMPL => Item::Impl(Impl { syntax }), | 3152 | IMPL => Item::Impl(Impl { syntax }), |
3126 | MACRO_CALL => Item::MacroCall(MacroCall { syntax }), | 3153 | MACRO_CALL => Item::MacroCall(MacroCall { syntax }), |
3127 | MACRO_RULES => Item::MacroRules(MacroRules { syntax }), | 3154 | MACRO_RULES => Item::MacroRules(MacroRules { syntax }), |
3155 | MACRO_DEF => Item::MacroDef(MacroDef { syntax }), | ||
3128 | MODULE => Item::Module(Module { syntax }), | 3156 | MODULE => Item::Module(Module { syntax }), |
3129 | STATIC => Item::Static(Static { syntax }), | 3157 | STATIC => Item::Static(Static { syntax }), |
3130 | STRUCT => Item::Struct(Struct { syntax }), | 3158 | STRUCT => Item::Struct(Struct { syntax }), |
@@ -3146,6 +3174,7 @@ impl AstNode for Item { | |||
3146 | Item::Impl(it) => &it.syntax, | 3174 | Item::Impl(it) => &it.syntax, |
3147 | Item::MacroCall(it) => &it.syntax, | 3175 | Item::MacroCall(it) => &it.syntax, |
3148 | Item::MacroRules(it) => &it.syntax, | 3176 | Item::MacroRules(it) => &it.syntax, |
3177 | Item::MacroDef(it) => &it.syntax, | ||
3149 | Item::Module(it) => &it.syntax, | 3178 | Item::Module(it) => &it.syntax, |
3150 | Item::Static(it) => &it.syntax, | 3179 | Item::Static(it) => &it.syntax, |
3151 | Item::Struct(it) => &it.syntax, | 3180 | Item::Struct(it) => &it.syntax, |
@@ -3615,6 +3644,11 @@ impl std::fmt::Display for MacroRules { | |||
3615 | std::fmt::Display::fmt(self.syntax(), f) | 3644 | std::fmt::Display::fmt(self.syntax(), f) |
3616 | } | 3645 | } |
3617 | } | 3646 | } |
3647 | impl std::fmt::Display for MacroDef { | ||
3648 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
3649 | std::fmt::Display::fmt(self.syntax(), f) | ||
3650 | } | ||
3651 | } | ||
3618 | impl std::fmt::Display for Module { | 3652 | impl std::fmt::Display for Module { |
3619 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3653 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
3620 | std::fmt::Display::fmt(self.syntax(), f) | 3654 | std::fmt::Display::fmt(self.syntax(), f) |