diff options
author | Marco Groppo <[email protected]> | 2019-04-14 23:03:54 +0100 |
---|---|---|
committer | Marco Groppo <[email protected]> | 2019-04-19 23:10:19 +0100 |
commit | e85ee60c42db57368e24ad9ac24840c2494d383c (patch) | |
tree | a94bb45556b404452e2ef282e6d11887f93601ca /crates/ra_syntax/src | |
parent | d55f1136d6444b1f50b9092c36a976d0e1c26202 (diff) |
Initial support for lang items.
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r-- | crates/ra_syntax/src/ast/extensions.rs | 14 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/generated.rs | 1 | ||||
-rw-r--r-- | crates/ra_syntax/src/grammar.ron | 2 |
3 files changed, 16 insertions, 1 deletions
diff --git a/crates/ra_syntax/src/ast/extensions.rs b/crates/ra_syntax/src/ast/extensions.rs index ca33b43e7..5c4c0ffc1 100644 --- a/crates/ra_syntax/src/ast/extensions.rs +++ b/crates/ra_syntax/src/ast/extensions.rs | |||
@@ -65,6 +65,20 @@ impl ast::Attr { | |||
65 | None | 65 | None |
66 | } | 66 | } |
67 | } | 67 | } |
68 | |||
69 | pub fn as_key_value(&self) -> Option<(SmolStr, SmolStr)> { | ||
70 | let tt = self.value()?; | ||
71 | let tt_node = tt.syntax(); | ||
72 | let attr = tt_node.children_with_tokens().nth(1)?; | ||
73 | if attr.kind() == IDENT { | ||
74 | let key = attr.as_token()?.text().clone(); | ||
75 | let val_node = tt_node.children_with_tokens().find(|t| t.kind() == STRING)?; | ||
76 | let val = val_node.as_token()?.text().trim_start_matches("\"").trim_end_matches("\""); | ||
77 | Some((key, SmolStr::new(val))) | ||
78 | } else { | ||
79 | None | ||
80 | } | ||
81 | } | ||
68 | } | 82 | } |
69 | 83 | ||
70 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 84 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index 774d9bcc8..29a7ce166 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs | |||
@@ -1325,6 +1325,7 @@ impl ToOwned for ImplBlock { | |||
1325 | 1325 | ||
1326 | 1326 | ||
1327 | impl ast::TypeParamsOwner for ImplBlock {} | 1327 | impl ast::TypeParamsOwner for ImplBlock {} |
1328 | impl ast::AttrsOwner for ImplBlock {} | ||
1328 | impl ImplBlock { | 1329 | impl ImplBlock { |
1329 | pub fn item_list(&self) -> Option<&ItemList> { | 1330 | pub fn item_list(&self) -> Option<&ItemList> { |
1330 | super::child_opt(self) | 1331 | super::child_opt(self) |
diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron index b41241287..41fe35f08 100644 --- a/crates/ra_syntax/src/grammar.ron +++ b/crates/ra_syntax/src/grammar.ron | |||
@@ -341,7 +341,7 @@ Grammar( | |||
341 | ], | 341 | ], |
342 | options: ["TypeRef"] | 342 | options: ["TypeRef"] |
343 | ), | 343 | ), |
344 | "ImplBlock": (options: ["ItemList"], traits: ["TypeParamsOwner"]), | 344 | "ImplBlock": (options: ["ItemList"], traits: ["TypeParamsOwner", "AttrsOwner"]), |
345 | 345 | ||
346 | "ParenType": (options: ["TypeRef"]), | 346 | "ParenType": (options: ["TypeRef"]), |
347 | "TupleType": ( collections: [["fields", "TypeRef"]] ), | 347 | "TupleType": ( collections: [["fields", "TypeRef"]] ), |