From c31c3246a8c87a3639623c30b692a57e728bb046 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Tue, 15 Dec 2020 18:43:19 +0100 Subject: Basic support for decl macros 2.0 --- crates/syntax/src/ast/generated/nodes.rs | 36 +++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'crates/syntax/src/ast/generated/nodes.rs') 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 { pub fn token_tree(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct MacroDef { + pub(crate) syntax: SyntaxNode, +} +impl ast::AttrsOwner for MacroDef {} +impl ast::NameOwner for MacroDef {} +impl ast::VisibilityOwner for MacroDef {} +impl MacroDef { + pub fn macro_token(&self) -> Option { support::token(&self.syntax, T![macro]) } + pub fn args(&self) -> Option { support::child(&self.syntax) } + pub fn body(&self) -> Option { support::child(&self.syntax) } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Module { pub(crate) syntax: SyntaxNode, } @@ -1332,6 +1344,7 @@ pub enum Item { Impl(Impl), MacroCall(MacroCall), MacroRules(MacroRules), + MacroDef(MacroDef), Module(Module), Static(Static), Struct(Struct), @@ -1689,6 +1702,17 @@ impl AstNode for MacroRules { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } +impl AstNode for MacroDef { + fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_DEF } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} impl AstNode for Module { fn can_cast(kind: SyntaxKind) -> bool { kind == MODULE } fn cast(syntax: SyntaxNode) -> Option { @@ -3086,6 +3110,9 @@ impl From for Item { impl From for Item { fn from(node: MacroRules) -> Item { Item::MacroRules(node) } } +impl From for Item { + fn from(node: MacroDef) -> Item { Item::MacroDef(node) } +} impl From for Item { fn from(node: Module) -> Item { Item::Module(node) } } @@ -3111,7 +3138,7 @@ impl AstNode for Item { fn can_cast(kind: SyntaxKind) -> bool { match kind { CONST | ENUM | EXTERN_BLOCK | EXTERN_CRATE | FN | IMPL | MACRO_CALL | MACRO_RULES - | MODULE | STATIC | STRUCT | TRAIT | TYPE_ALIAS | UNION | USE => true, + | MACRO_DEF | MODULE | STATIC | STRUCT | TRAIT | TYPE_ALIAS | UNION | USE => true, _ => false, } } @@ -3125,6 +3152,7 @@ impl AstNode for Item { IMPL => Item::Impl(Impl { syntax }), MACRO_CALL => Item::MacroCall(MacroCall { syntax }), MACRO_RULES => Item::MacroRules(MacroRules { syntax }), + MACRO_DEF => Item::MacroDef(MacroDef { syntax }), MODULE => Item::Module(Module { syntax }), STATIC => Item::Static(Static { syntax }), STRUCT => Item::Struct(Struct { syntax }), @@ -3146,6 +3174,7 @@ impl AstNode for Item { Item::Impl(it) => &it.syntax, Item::MacroCall(it) => &it.syntax, Item::MacroRules(it) => &it.syntax, + Item::MacroDef(it) => &it.syntax, Item::Module(it) => &it.syntax, Item::Static(it) => &it.syntax, Item::Struct(it) => &it.syntax, @@ -3615,6 +3644,11 @@ impl std::fmt::Display for MacroRules { std::fmt::Display::fmt(self.syntax(), f) } } +impl std::fmt::Display for MacroDef { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} impl std::fmt::Display for Module { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) -- cgit v1.2.3