diff options
author | uHOOCCOOHu <[email protected]> | 2019-09-29 21:44:33 +0100 |
---|---|---|
committer | uHOOCCOOHu <[email protected]> | 2019-09-30 09:11:40 +0100 |
commit | 71efdaa6364142b359c59659ec10f35a1e53b5d2 (patch) | |
tree | 5dbbbc522bbb52f05d77e2bc0ad2241a57349c86 /crates/ra_syntax/src/ast | |
parent | c913b48928107710d6ec87a455b1ae6891297c2b (diff) |
Parse correct AttrInput
Diffstat (limited to 'crates/ra_syntax/src/ast')
-rw-r--r-- | crates/ra_syntax/src/ast/generated.rs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index dc1f8c82c..408449fd6 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs | |||
@@ -166,11 +166,55 @@ impl AstNode for Attr { | |||
166 | } | 166 | } |
167 | } | 167 | } |
168 | impl Attr { | 168 | impl Attr { |
169 | pub fn path(&self) -> Option<Path> { | ||
170 | AstChildren::new(&self.syntax).next() | ||
171 | } | ||
172 | pub fn input(&self) -> Option<AttrInput> { | ||
173 | AstChildren::new(&self.syntax).next() | ||
174 | } | ||
169 | pub fn value(&self) -> Option<TokenTree> { | 175 | pub fn value(&self) -> Option<TokenTree> { |
170 | AstChildren::new(&self.syntax).next() | 176 | AstChildren::new(&self.syntax).next() |
171 | } | 177 | } |
172 | } | 178 | } |
173 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 179 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
180 | pub enum AttrInput { | ||
181 | Literal(Literal), | ||
182 | TokenTree(TokenTree), | ||
183 | } | ||
184 | impl From<Literal> for AttrInput { | ||
185 | fn from(node: Literal) -> AttrInput { | ||
186 | AttrInput::Literal(node) | ||
187 | } | ||
188 | } | ||
189 | impl From<TokenTree> for AttrInput { | ||
190 | fn from(node: TokenTree) -> AttrInput { | ||
191 | AttrInput::TokenTree(node) | ||
192 | } | ||
193 | } | ||
194 | impl AstNode for AttrInput { | ||
195 | fn can_cast(kind: SyntaxKind) -> bool { | ||
196 | match kind { | ||
197 | LITERAL | TOKEN_TREE => true, | ||
198 | _ => false, | ||
199 | } | ||
200 | } | ||
201 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
202 | let res = match syntax.kind() { | ||
203 | LITERAL => AttrInput::Literal(Literal { syntax }), | ||
204 | TOKEN_TREE => AttrInput::TokenTree(TokenTree { syntax }), | ||
205 | _ => return None, | ||
206 | }; | ||
207 | Some(res) | ||
208 | } | ||
209 | fn syntax(&self) -> &SyntaxNode { | ||
210 | match self { | ||
211 | AttrInput::Literal(it) => &it.syntax, | ||
212 | AttrInput::TokenTree(it) => &it.syntax, | ||
213 | } | ||
214 | } | ||
215 | } | ||
216 | impl AttrInput {} | ||
217 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
174 | pub struct AwaitExpr { | 218 | pub struct AwaitExpr { |
175 | pub(crate) syntax: SyntaxNode, | 219 | pub(crate) syntax: SyntaxNode, |
176 | } | 220 | } |