aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/libsyntax2/src')
-rw-r--r--crates/libsyntax2/src/ast/generated.rs1
-rw-r--r--crates/libsyntax2/src/ast/mod.rs30
-rw-r--r--crates/libsyntax2/src/grammar.ron5
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
342impl<R: TreeRoot> ast::AttrsOwner<R> for NominalDef<R> {}
342impl<R: TreeRoot> NominalDef<R> {} 343impl<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> {
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
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)