diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-09-30 09:46:08 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2019-09-30 09:46:08 +0100 |
commit | 733f1d8b709788225bd06f8c0aee1819db92620b (patch) | |
tree | d17395e4c3f7965c5cf9bdd50ef940e52eef1155 /crates/ra_syntax/src/ast/generated.rs | |
parent | c913b48928107710d6ec87a455b1ae6891297c2b (diff) | |
parent | f7e12559cb26b59a9a2ecee4deecaf6fe9100d16 (diff) |
Merge #1934
1934: Parse Path and AttrInput in Attr r=matklad a=uHOOCCOOHu
[Syntax reference](https://doc.rust-lang.org/reference/attributes.html#attributes)
Co-authored-by: uHOOCCOOHu <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src/ast/generated.rs')
-rw-r--r-- | crates/ra_syntax/src/ast/generated.rs | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index dc1f8c82c..aaf03ce3f 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs | |||
@@ -166,11 +166,52 @@ impl AstNode for Attr { | |||
166 | } | 166 | } |
167 | } | 167 | } |
168 | impl Attr { | 168 | impl Attr { |
169 | pub fn value(&self) -> Option<TokenTree> { | 169 | pub fn path(&self) -> Option<Path> { |
170 | AstChildren::new(&self.syntax).next() | ||
171 | } | ||
172 | pub fn input(&self) -> Option<AttrInput> { | ||
170 | AstChildren::new(&self.syntax).next() | 173 | AstChildren::new(&self.syntax).next() |
171 | } | 174 | } |
172 | } | 175 | } |
173 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 176 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
177 | pub enum AttrInput { | ||
178 | Literal(Literal), | ||
179 | TokenTree(TokenTree), | ||
180 | } | ||
181 | impl From<Literal> for AttrInput { | ||
182 | fn from(node: Literal) -> AttrInput { | ||
183 | AttrInput::Literal(node) | ||
184 | } | ||
185 | } | ||
186 | impl From<TokenTree> for AttrInput { | ||
187 | fn from(node: TokenTree) -> AttrInput { | ||
188 | AttrInput::TokenTree(node) | ||
189 | } | ||
190 | } | ||
191 | impl AstNode for AttrInput { | ||
192 | fn can_cast(kind: SyntaxKind) -> bool { | ||
193 | match kind { | ||
194 | LITERAL | TOKEN_TREE => true, | ||
195 | _ => false, | ||
196 | } | ||
197 | } | ||
198 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
199 | let res = match syntax.kind() { | ||
200 | LITERAL => AttrInput::Literal(Literal { syntax }), | ||
201 | TOKEN_TREE => AttrInput::TokenTree(TokenTree { syntax }), | ||
202 | _ => return None, | ||
203 | }; | ||
204 | Some(res) | ||
205 | } | ||
206 | fn syntax(&self) -> &SyntaxNode { | ||
207 | match self { | ||
208 | AttrInput::Literal(it) => &it.syntax, | ||
209 | AttrInput::TokenTree(it) => &it.syntax, | ||
210 | } | ||
211 | } | ||
212 | } | ||
213 | impl AttrInput {} | ||
214 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
174 | pub struct AwaitExpr { | 215 | pub struct AwaitExpr { |
175 | pub(crate) syntax: SyntaxNode, | 216 | pub(crate) syntax: SyntaxNode, |
176 | } | 217 | } |