From 917c89c103597d09e95bdee273633f79123dd19e Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 18:37:46 +0200 Subject: Finaize item grammar --- crates/ra_hir_def/src/item_tree/lower.rs | 1 + crates/ra_syntax/src/ast/generated/nodes.rs | 135 +++++++++++++++------------- 2 files changed, 72 insertions(+), 64 deletions(-) (limited to 'crates') diff --git a/crates/ra_hir_def/src/item_tree/lower.rs b/crates/ra_hir_def/src/item_tree/lower.rs index b0cf94956..29f1de547 100644 --- a/crates/ra_hir_def/src/item_tree/lower.rs +++ b/crates/ra_hir_def/src/item_tree/lower.rs @@ -557,6 +557,7 @@ impl Ctx { let statik = self.lower_static(&ast)?; statik.into() } + ast::ExternItem::MacroCall(_) => return None, }; self.add_attrs(id.into(), attrs); Some(id) diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs index ba00742f0..9345a5e8f 100644 --- a/crates/ra_syntax/src/ast/generated/nodes.rs +++ b/crates/ra_syntax/src/ast/generated/nodes.rs @@ -453,12 +453,23 @@ impl Variant { pub struct AssocItemList { pub(crate) syntax: SyntaxNode, } +impl ast::AttrsOwner for AssocItemList {} impl AssocItemList { pub fn l_curly_token(&self) -> Option { support::token(&self.syntax, T!['{']) } pub fn assoc_items(&self) -> AstChildren { support::children(&self.syntax) } pub fn r_curly_token(&self) -> Option { support::token(&self.syntax, T!['}']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct ExternItemList { + pub(crate) syntax: SyntaxNode, +} +impl ast::AttrsOwner for ExternItemList {} +impl ExternItemList { + pub fn l_curly_token(&self) -> Option { support::token(&self.syntax, T!['{']) } + pub fn extern_items(&self) -> AstChildren { support::children(&self.syntax) } + pub fn r_curly_token(&self) -> Option { support::token(&self.syntax, T!['}']) } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ParenType { pub(crate) syntax: SyntaxNode, } @@ -1254,15 +1265,6 @@ impl ConstArg { pub fn block_expr(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct ExternItemList { - pub(crate) syntax: SyntaxNode, -} -impl ExternItemList { - pub fn l_curly_token(&self) -> Option { support::token(&self.syntax, T!['{']) } - pub fn extern_items(&self) -> AstChildren { support::children(&self.syntax) } - pub fn r_curly_token(&self) -> Option { support::token(&self.syntax, T!['}']) } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct MetaItem { pub(crate) syntax: SyntaxNode, } @@ -1373,6 +1375,14 @@ pub enum AssocItem { impl ast::AttrsOwner for AssocItem {} impl ast::NameOwner for AssocItem {} #[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub enum ExternItem { + Fn(Fn), + Static(Static), + MacroCall(MacroCall), +} +impl ast::AttrsOwner for ExternItem {} +impl ast::NameOwner for ExternItem {} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum Stmt { LetStmt(LetStmt), ExprStmt(ExprStmt), @@ -1384,14 +1394,6 @@ pub enum AttrInput { TokenTree(TokenTree), } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub enum ExternItem { - Fn(Fn), - Static(Static), -} -impl ast::AttrsOwner for ExternItem {} -impl ast::NameOwner for ExternItem {} -impl ast::VisibilityOwner for ExternItem {} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum AdtDef { Struct(Struct), Enum(Enum), @@ -1841,6 +1843,17 @@ impl AstNode for AssocItemList { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } +impl AstNode for ExternItemList { + fn can_cast(kind: SyntaxKind) -> bool { kind == EXTERN_ITEM_LIST } + 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 ParenType { fn can_cast(kind: SyntaxKind) -> bool { kind == PAREN_TYPE } fn cast(syntax: SyntaxNode) -> Option { @@ -2754,17 +2767,6 @@ impl AstNode for ConstArg { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for ExternItemList { - fn can_cast(kind: SyntaxKind) -> bool { kind == EXTERN_ITEM_LIST } - 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 MetaItem { fn can_cast(kind: SyntaxKind) -> bool { kind == META_ITEM } fn cast(syntax: SyntaxNode) -> Option { @@ -3290,6 +3292,39 @@ impl AstNode for AssocItem { } } } +impl From for ExternItem { + fn from(node: Fn) -> ExternItem { ExternItem::Fn(node) } +} +impl From for ExternItem { + fn from(node: Static) -> ExternItem { ExternItem::Static(node) } +} +impl From for ExternItem { + fn from(node: MacroCall) -> ExternItem { ExternItem::MacroCall(node) } +} +impl AstNode for ExternItem { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + FN | STATIC | MACRO_CALL => true, + _ => false, + } + } + fn cast(syntax: SyntaxNode) -> Option { + let res = match syntax.kind() { + FN => ExternItem::Fn(Fn { syntax }), + STATIC => ExternItem::Static(Static { syntax }), + MACRO_CALL => ExternItem::MacroCall(MacroCall { syntax }), + _ => return None, + }; + Some(res) + } + fn syntax(&self) -> &SyntaxNode { + match self { + ExternItem::Fn(it) => &it.syntax, + ExternItem::Static(it) => &it.syntax, + ExternItem::MacroCall(it) => &it.syntax, + } + } +} impl From for Stmt { fn from(node: LetStmt) -> Stmt { Stmt::LetStmt(node) } } @@ -3346,34 +3381,6 @@ impl AstNode for AttrInput { } } } -impl From for ExternItem { - fn from(node: Fn) -> ExternItem { ExternItem::Fn(node) } -} -impl From for ExternItem { - fn from(node: Static) -> ExternItem { ExternItem::Static(node) } -} -impl AstNode for ExternItem { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - FN | STATIC => true, - _ => false, - } - } - fn cast(syntax: SyntaxNode) -> Option { - let res = match syntax.kind() { - FN => ExternItem::Fn(Fn { syntax }), - STATIC => ExternItem::Static(Static { syntax }), - _ => return None, - }; - Some(res) - } - fn syntax(&self) -> &SyntaxNode { - match self { - ExternItem::Fn(it) => &it.syntax, - ExternItem::Static(it) => &it.syntax, - } - } -} impl From for AdtDef { fn from(node: Struct) -> AdtDef { AdtDef::Struct(node) } } @@ -3437,17 +3444,17 @@ impl std::fmt::Display for AssocItem { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for Stmt { +impl std::fmt::Display for ExternItem { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for AttrInput { +impl std::fmt::Display for Stmt { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for ExternItem { +impl std::fmt::Display for AttrInput { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } @@ -3657,6 +3664,11 @@ impl std::fmt::Display for AssocItemList { std::fmt::Display::fmt(self.syntax(), f) } } +impl std::fmt::Display for ExternItemList { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} impl std::fmt::Display for ParenType { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) @@ -4072,11 +4084,6 @@ impl std::fmt::Display for ConstArg { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for ExternItemList { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - std::fmt::Display::fmt(self.syntax(), f) - } -} impl std::fmt::Display for MetaItem { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) -- cgit v1.2.3