diff options
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r-- | crates/ra_syntax/src/ast/generated.rs | 44 | ||||
-rw-r--r-- | crates/ra_syntax/src/grammar.ron | 3 |
2 files changed, 46 insertions, 1 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 | } |
diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron index 5f395501a..8cb45f394 100644 --- a/crates/ra_syntax/src/grammar.ron +++ b/crates/ra_syntax/src/grammar.ron | |||
@@ -576,7 +576,8 @@ Grammar( | |||
576 | traits: [ "NameOwner", "AttrsOwner","DocCommentsOwner" ], | 576 | traits: [ "NameOwner", "AttrsOwner","DocCommentsOwner" ], |
577 | options: [ "TokenTree", "Path" ], | 577 | options: [ "TokenTree", "Path" ], |
578 | ), | 578 | ), |
579 | "Attr": ( options: [ ["value", "TokenTree"] ] ), | 579 | "AttrInput": ( enum: [ "Literal", "TokenTree" ] ), |
580 | "Attr": ( options: [ "Path", [ "input", "AttrInput" ], [ "value", "TokenTree" ] ] ), | ||
580 | "TokenTree": (), | 581 | "TokenTree": (), |
581 | "TypeParamList": ( | 582 | "TypeParamList": ( |
582 | collections: [ | 583 | collections: [ |