diff options
Diffstat (limited to 'crates/syntax/src/ast')
-rw-r--r-- | crates/syntax/src/ast/generated/nodes.rs | 46 | ||||
-rw-r--r-- | crates/syntax/src/ast/node_ext.rs | 10 |
2 files changed, 23 insertions, 33 deletions
diff --git a/crates/syntax/src/ast/generated/nodes.rs b/crates/syntax/src/ast/generated/nodes.rs index 6097178b6..9a88fdb56 100644 --- a/crates/syntax/src/ast/generated/nodes.rs +++ b/crates/syntax/src/ast/generated/nodes.rs | |||
@@ -152,7 +152,7 @@ impl Attr { | |||
152 | pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) } | 152 | pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) } |
153 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } | 153 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } |
154 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } | 154 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } |
155 | pub fn literal(&self) -> Option<Literal> { support::child(&self.syntax) } | 155 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
156 | pub fn token_tree(&self) -> Option<TokenTree> { support::child(&self.syntax) } | 156 | pub fn token_tree(&self) -> Option<TokenTree> { support::child(&self.syntax) } |
157 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } | 157 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } |
158 | } | 158 | } |
@@ -632,12 +632,6 @@ impl WherePred { | |||
632 | pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) } | 632 | pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) } |
633 | } | 633 | } |
634 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 634 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
635 | pub struct Literal { | ||
636 | pub(crate) syntax: SyntaxNode, | ||
637 | } | ||
638 | impl ast::AttrsOwner for Literal {} | ||
639 | impl Literal {} | ||
640 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
641 | pub struct ExprStmt { | 635 | pub struct ExprStmt { |
642 | pub(crate) syntax: SyntaxNode, | 636 | pub(crate) syntax: SyntaxNode, |
643 | } | 637 | } |
@@ -805,6 +799,12 @@ impl IndexExpr { | |||
805 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } | 799 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } |
806 | } | 800 | } |
807 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 801 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
802 | pub struct Literal { | ||
803 | pub(crate) syntax: SyntaxNode, | ||
804 | } | ||
805 | impl ast::AttrsOwner for Literal {} | ||
806 | impl Literal {} | ||
807 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
808 | pub struct LoopExpr { | 808 | pub struct LoopExpr { |
809 | pub(crate) syntax: SyntaxNode, | 809 | pub(crate) syntax: SyntaxNode, |
810 | } | 810 | } |
@@ -2072,17 +2072,6 @@ impl AstNode for WherePred { | |||
2072 | } | 2072 | } |
2073 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 2073 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2074 | } | 2074 | } |
2075 | impl AstNode for Literal { | ||
2076 | fn can_cast(kind: SyntaxKind) -> bool { kind == LITERAL } | ||
2077 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2078 | if Self::can_cast(syntax.kind()) { | ||
2079 | Some(Self { syntax }) | ||
2080 | } else { | ||
2081 | None | ||
2082 | } | ||
2083 | } | ||
2084 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2085 | } | ||
2086 | impl AstNode for ExprStmt { | 2075 | impl AstNode for ExprStmt { |
2087 | fn can_cast(kind: SyntaxKind) -> bool { kind == EXPR_STMT } | 2076 | fn can_cast(kind: SyntaxKind) -> bool { kind == EXPR_STMT } |
2088 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2077 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
@@ -2259,6 +2248,17 @@ impl AstNode for IndexExpr { | |||
2259 | } | 2248 | } |
2260 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 2249 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2261 | } | 2250 | } |
2251 | impl AstNode for Literal { | ||
2252 | fn can_cast(kind: SyntaxKind) -> bool { kind == LITERAL } | ||
2253 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2254 | if Self::can_cast(syntax.kind()) { | ||
2255 | Some(Self { syntax }) | ||
2256 | } else { | ||
2257 | None | ||
2258 | } | ||
2259 | } | ||
2260 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2261 | } | ||
2262 | impl AstNode for LoopExpr { | 2262 | impl AstNode for LoopExpr { |
2263 | fn can_cast(kind: SyntaxKind) -> bool { kind == LOOP_EXPR } | 2263 | fn can_cast(kind: SyntaxKind) -> bool { kind == LOOP_EXPR } |
2264 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2264 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
@@ -3887,11 +3887,6 @@ impl std::fmt::Display for WherePred { | |||
3887 | std::fmt::Display::fmt(self.syntax(), f) | 3887 | std::fmt::Display::fmt(self.syntax(), f) |
3888 | } | 3888 | } |
3889 | } | 3889 | } |
3890 | impl std::fmt::Display for Literal { | ||
3891 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
3892 | std::fmt::Display::fmt(self.syntax(), f) | ||
3893 | } | ||
3894 | } | ||
3895 | impl std::fmt::Display for ExprStmt { | 3890 | impl std::fmt::Display for ExprStmt { |
3896 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3891 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
3897 | std::fmt::Display::fmt(self.syntax(), f) | 3892 | std::fmt::Display::fmt(self.syntax(), f) |
@@ -3972,6 +3967,11 @@ impl std::fmt::Display for IndexExpr { | |||
3972 | std::fmt::Display::fmt(self.syntax(), f) | 3967 | std::fmt::Display::fmt(self.syntax(), f) |
3973 | } | 3968 | } |
3974 | } | 3969 | } |
3970 | impl std::fmt::Display for Literal { | ||
3971 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
3972 | std::fmt::Display::fmt(self.syntax(), f) | ||
3973 | } | ||
3974 | } | ||
3975 | impl std::fmt::Display for LoopExpr { | 3975 | impl std::fmt::Display for LoopExpr { |
3976 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3976 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
3977 | std::fmt::Display::fmt(self.syntax(), f) | 3977 | 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 0b0d39a75..5a9834cbb 100644 --- a/crates/syntax/src/ast/node_ext.rs +++ b/crates/syntax/src/ast/node_ext.rs | |||
@@ -109,16 +109,6 @@ impl ast::Attr { | |||
109 | Some((self.simple_name()?, tt)) | 109 | Some((self.simple_name()?, tt)) |
110 | } | 110 | } |
111 | 111 | ||
112 | pub fn as_simple_key_value(&self) -> Option<(SmolStr, SmolStr)> { | ||
113 | let lit = self.literal()?; | ||
114 | let key = self.simple_name()?; | ||
115 | let value_token = lit.syntax().first_token()?; | ||
116 | |||
117 | let value: SmolStr = ast::String::cast(value_token)?.value()?.into(); | ||
118 | |||
119 | Some((key, value)) | ||
120 | } | ||
121 | |||
122 | pub fn simple_name(&self) -> Option<SmolStr> { | 112 | pub fn simple_name(&self) -> Option<SmolStr> { |
123 | let path = self.path()?; | 113 | let path = self.path()?; |
124 | match (path.segment(), path.qualifier()) { | 114 | match (path.segment(), path.qualifier()) { |