diff options
author | Aleksey Kladov <[email protected]> | 2018-08-16 11:11:20 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-16 11:11:20 +0100 |
commit | a5515d9d6f215da4351b482d839aab5212fa0e6f (patch) | |
tree | a0557e07f57fad65ad32b80010cce08b5559f9e5 /crates/libsyntax2/src | |
parent | 7094291573dc819e3115950ec3b2316bd5e9ea33 (diff) |
Add derive handles cursor
Diffstat (limited to 'crates/libsyntax2/src')
-rw-r--r-- | crates/libsyntax2/src/ast/generated.rs | 1 | ||||
-rw-r--r-- | crates/libsyntax2/src/ast/mod.rs | 30 | ||||
-rw-r--r-- | crates/libsyntax2/src/grammar.ron | 5 |
3 files changed, 26 insertions, 10 deletions
diff --git a/crates/libsyntax2/src/ast/generated.rs b/crates/libsyntax2/src/ast/generated.rs index c575e15df..be3f73f7e 100644 --- a/crates/libsyntax2/src/ast/generated.rs +++ b/crates/libsyntax2/src/ast/generated.rs | |||
@@ -339,6 +339,7 @@ impl<R: TreeRoot> AstNode<R> for NominalDef<R> { | |||
339 | } | 339 | } |
340 | } | 340 | } |
341 | 341 | ||
342 | impl<R: TreeRoot> ast::AttrsOwner<R> for NominalDef<R> {} | ||
342 | impl<R: TreeRoot> NominalDef<R> {} | 343 | impl<R: TreeRoot> NominalDef<R> {} |
343 | 344 | ||
344 | // ParenType | 345 | // ParenType |
diff --git a/crates/libsyntax2/src/ast/mod.rs b/crates/libsyntax2/src/ast/mod.rs index fe8f91d15..d53b12ab8 100644 --- a/crates/libsyntax2/src/ast/mod.rs +++ b/crates/libsyntax2/src/ast/mod.rs | |||
@@ -52,19 +52,31 @@ impl<R: TreeRoot> File<R> { | |||
52 | impl<R: TreeRoot> FnDef<R> { | 52 | impl<R: TreeRoot> FnDef<R> { |
53 | pub fn has_atom_attr(&self, atom: &str) -> bool { | 53 | pub fn has_atom_attr(&self, atom: &str) -> bool { |
54 | self.attrs() | 54 | self.attrs() |
55 | .filter_map(|x| x.value()) | 55 | .filter_map(|x| x.as_atom()) |
56 | .filter_map(|x| as_atom(x)) | ||
57 | .any(|x| x == atom) | 56 | .any(|x| x == atom) |
58 | } | 57 | } |
59 | } | 58 | } |
60 | 59 | ||
61 | fn as_atom<R: TreeRoot>(tt: TokenTree<R>) -> Option<SmolStr> { | 60 | impl<R: TreeRoot> Attr<R> { |
62 | let syntax = tt.syntax_ref(); | 61 | pub fn as_atom(&self) -> Option<SmolStr> { |
63 | let (_bra, attr, _ket) = syntax.children().collect_tuple()?; | 62 | let tt = self.value()?; |
64 | if attr.kind() == IDENT { | 63 | let (_bra, attr, _ket) = tt.syntax().children().collect_tuple()?; |
65 | Some(attr.leaf_text().unwrap()) | 64 | if attr.kind() == IDENT { |
66 | } else { | 65 | Some(attr.leaf_text().unwrap()) |
67 | None | 66 | } else { |
67 | None | ||
68 | } | ||
69 | } | ||
70 | |||
71 | pub fn as_call(&self) -> Option<(SmolStr, TokenTree<R>)> { | ||
72 | let tt = self.value()?; | ||
73 | let (_bra, attr, args, _ket) = tt.syntax().children().collect_tuple()?; | ||
74 | let args = TokenTree::cast(args)?; | ||
75 | if attr.kind() == IDENT { | ||
76 | Some((attr.leaf_text().unwrap(), args)) | ||
77 | } else { | ||
78 | None | ||
79 | } | ||
68 | } | 80 | } |
69 | } | 81 | } |
70 | 82 | ||
diff --git a/crates/libsyntax2/src/grammar.ron b/crates/libsyntax2/src/grammar.ron index 4e523da9a..abeffb2c3 100644 --- a/crates/libsyntax2/src/grammar.ron +++ b/crates/libsyntax2/src/grammar.ron | |||
@@ -272,6 +272,9 @@ Grammar( | |||
272 | "DynTraitType", | 272 | "DynTraitType", |
273 | ]), | 273 | ]), |
274 | 274 | ||
275 | "NominalDef": ( enum: ["StructDef", "EnumDef"]), | 275 | "NominalDef": ( |
276 | enum: ["StructDef", "EnumDef"], | ||
277 | traits: [ "AttrsOwner" ], | ||
278 | ), | ||
276 | }, | 279 | }, |
277 | ) | 280 | ) |