From 3ff5440a503f090032136c37c3d44375d6107db1 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Fri, 19 Apr 2019 02:47:29 +0800 Subject: Add MacroItems and MacroStmts in grammer.ron --- crates/ra_syntax/src/ast/generated.rs | 66 +++++++++++++++++++++++++++++++++++ crates/ra_syntax/src/grammar.ron | 15 ++++++++ 2 files changed, 81 insertions(+) (limited to 'crates/ra_syntax/src') diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index 774d9bcc8..17de4f058 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs @@ -1770,6 +1770,72 @@ impl MacroCall { } } +// MacroItems +#[derive(Debug, PartialEq, Eq, Hash)] +#[repr(transparent)] +pub struct MacroItems { + pub(crate) syntax: SyntaxNode, +} +unsafe impl TransparentNewType for MacroItems { + type Repr = rowan::SyntaxNode; +} + +impl AstNode for MacroItems { + fn cast(syntax: &SyntaxNode) -> Option<&Self> { + match syntax.kind() { + MACRO_ITEMS => Some(MacroItems::from_repr(syntax.into_repr())), + _ => None, + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for MacroItems { + type Owned = TreeArc; + fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } +} + + +impl ast::ModuleItemOwner for MacroItems {} +impl ast::FnDefOwner for MacroItems {} +impl MacroItems {} + +// MacroStmts +#[derive(Debug, PartialEq, Eq, Hash)] +#[repr(transparent)] +pub struct MacroStmts { + pub(crate) syntax: SyntaxNode, +} +unsafe impl TransparentNewType for MacroStmts { + type Repr = rowan::SyntaxNode; +} + +impl AstNode for MacroStmts { + fn cast(syntax: &SyntaxNode) -> Option<&Self> { + match syntax.kind() { + MACRO_STMTS => Some(MacroStmts::from_repr(syntax.into_repr())), + _ => None, + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for MacroStmts { + type Owned = TreeArc; + fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } +} + + +impl MacroStmts { + pub fn statements(&self) -> impl Iterator { + super::children(self) + } + + pub fn expr(&self) -> Option<&Expr> { + super::child_opt(self) + } +} + // MatchArm #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron index b41241287..663e3a2f9 100644 --- a/crates/ra_syntax/src/grammar.ron +++ b/crates/ra_syntax/src/grammar.ron @@ -247,6 +247,10 @@ Grammar( "ARG_LIST", "TYPE_BOUND", "TYPE_BOUND_LIST", + + // macro related + "MACRO_ITEMS", + "MACRO_STMTS", ], ast: { "SourceFile": ( @@ -668,5 +672,16 @@ Grammar( "TypeArg": (options: ["TypeRef"]), "AssocTypeArg": (options: ["NameRef", "TypeRef"]), "LifetimeArg": (), + + "MacroItems": ( + traits: [ "ModuleItemOwner", "FnDefOwner" ], + ), + + "MacroStmts" : ( + options: [ "Expr" ], + collections: [ + ["statements", "Stmt"], + ], + ) }, ) -- cgit v1.2.3