From 1d6eef1350ee0793fcd2a0eb191cdb127b76a49d Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Fri, 11 Jun 2021 18:12:51 +0200 Subject: Update ungrammar --- crates/syntax/src/ast/generated/nodes.rs | 31 +++++++++++++++++++++++++++---- crates/syntax/src/ast/node_ext.rs | 19 ++++++++++++++++--- 2 files changed, 43 insertions(+), 7 deletions(-) (limited to 'crates/syntax/src') diff --git a/crates/syntax/src/ast/generated/nodes.rs b/crates/syntax/src/ast/generated/nodes.rs index 9a88fdb56..702de59a9 100644 --- a/crates/syntax/src/ast/generated/nodes.rs +++ b/crates/syntax/src/ast/generated/nodes.rs @@ -150,10 +150,7 @@ impl Attr { pub fn pound_token(&self) -> Option { support::token(&self.syntax, T![#]) } pub fn excl_token(&self) -> Option { support::token(&self.syntax, T![!]) } pub fn l_brack_token(&self) -> Option { support::token(&self.syntax, T!['[']) } - pub fn path(&self) -> Option { support::child(&self.syntax) } - pub fn eq_token(&self) -> Option { support::token(&self.syntax, T![=]) } - pub fn expr(&self) -> Option { support::child(&self.syntax) } - pub fn token_tree(&self) -> Option { support::child(&self.syntax) } + pub fn meta(&self) -> Option { support::child(&self.syntax) } pub fn r_brack_token(&self) -> Option { support::token(&self.syntax, T![']']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -632,6 +629,16 @@ impl WherePred { pub fn ty(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct Meta { + pub(crate) syntax: SyntaxNode, +} +impl Meta { + pub fn path(&self) -> Option { support::child(&self.syntax) } + pub fn eq_token(&self) -> Option { support::token(&self.syntax, T![=]) } + pub fn expr(&self) -> Option { support::child(&self.syntax) } + pub fn token_tree(&self) -> Option { support::child(&self.syntax) } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ExprStmt { pub(crate) syntax: SyntaxNode, } @@ -2072,6 +2079,17 @@ impl AstNode for WherePred { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } +impl AstNode for Meta { + fn can_cast(kind: SyntaxKind) -> bool { kind == META } + 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 ExprStmt { fn can_cast(kind: SyntaxKind) -> bool { kind == EXPR_STMT } fn cast(syntax: SyntaxNode) -> Option { @@ -3887,6 +3905,11 @@ impl std::fmt::Display for WherePred { std::fmt::Display::fmt(self.syntax(), f) } } +impl std::fmt::Display for Meta { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} impl std::fmt::Display for ExprStmt { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) diff --git a/crates/syntax/src/ast/node_ext.rs b/crates/syntax/src/ast/node_ext.rs index a60bc5ad9..3d27d2c1a 100644 --- a/crates/syntax/src/ast/node_ext.rs +++ b/crates/syntax/src/ast/node_ext.rs @@ -144,19 +144,20 @@ impl AttrKind { impl ast::Attr { pub fn as_simple_atom(&self) -> Option { - if self.eq_token().is_some() || self.token_tree().is_some() { + let meta = self.meta()?; + if meta.eq_token().is_some() || meta.token_tree().is_some() { return None; } self.simple_name() } pub fn as_simple_call(&self) -> Option<(SmolStr, ast::TokenTree)> { - let tt = self.token_tree()?; + let tt = self.meta()?.token_tree()?; Some((self.simple_name()?, tt)) } pub fn simple_name(&self) -> Option { - let path = self.path()?; + let path = self.meta()?.path()?; match (path.segment(), path.qualifier()) { (Some(segment), None) => Some(segment.syntax().first_token()?.text().into()), _ => None, @@ -174,6 +175,18 @@ impl ast::Attr { _ => AttrKind::Outer, } } + + pub fn path(&self) -> Option { + self.meta()?.path() + } + + pub fn expr(&self) -> Option { + self.meta()?.expr() + } + + pub fn token_tree(&self) -> Option { + self.meta()?.token_tree() + } } #[derive(Debug, Clone, PartialEq, Eq)] -- cgit v1.2.3