aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2/src/ast/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/libsyntax2/src/ast/mod.rs')
-rw-r--r--crates/libsyntax2/src/ast/mod.rs30
1 files changed, 21 insertions, 9 deletions
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> {
52impl<R: TreeRoot> FnDef<R> { 52impl<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
61fn as_atom<R: TreeRoot>(tt: TokenTree<R>) -> Option<SmolStr> { 60impl<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