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 +++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'crates/ra_syntax/src/ast') 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)] -- cgit v1.2.3