aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast
diff options
context:
space:
mode:
authoruHOOCCOOHu <[email protected]>2019-09-29 21:44:33 +0100
committeruHOOCCOOHu <[email protected]>2019-09-30 09:11:40 +0100
commit71efdaa6364142b359c59659ec10f35a1e53b5d2 (patch)
tree5dbbbc522bbb52f05d77e2bc0ad2241a57349c86 /crates/ra_syntax/src/ast
parentc913b48928107710d6ec87a455b1ae6891297c2b (diff)
Parse correct AttrInput
Diffstat (limited to 'crates/ra_syntax/src/ast')
-rw-r--r--crates/ra_syntax/src/ast/generated.rs44
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}
168impl Attr { 168impl 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)]
180pub enum AttrInput {
181 Literal(Literal),
182 TokenTree(TokenTree),
183}
184impl From<Literal> for AttrInput {
185 fn from(node: Literal) -> AttrInput {
186 AttrInput::Literal(node)
187 }
188}
189impl From<TokenTree> for AttrInput {
190 fn from(node: TokenTree) -> AttrInput {
191 AttrInput::TokenTree(node)
192 }
193}
194impl 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}
216impl AttrInput {}
217#[derive(Debug, Clone, PartialEq, Eq, Hash)]
174pub struct AwaitExpr { 218pub struct AwaitExpr {
175 pub(crate) syntax: SyntaxNode, 219 pub(crate) syntax: SyntaxNode,
176} 220}