diff options
author | Aleksey Kladov <[email protected]> | 2018-08-11 10:28:59 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-11 10:28:59 +0100 |
commit | 7afd84febc76a75a3ed1be75c57ff35d7b8b3de6 (patch) | |
tree | 76eb2de7efc569c39cc721b7be298490b9647e0b /crates/libsyntax2/src/ast/mod.rs | |
parent | d5119133fc03694c6644cac9e307d1d496fc9bf2 (diff) |
visitor
Diffstat (limited to 'crates/libsyntax2/src/ast/mod.rs')
-rw-r--r-- | crates/libsyntax2/src/ast/mod.rs | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/crates/libsyntax2/src/ast/mod.rs b/crates/libsyntax2/src/ast/mod.rs index 7d3cdb93d..56bc099fe 100644 --- a/crates/libsyntax2/src/ast/mod.rs +++ b/crates/libsyntax2/src/ast/mod.rs | |||
@@ -12,6 +12,15 @@ pub trait AstNode<R: TreeRoot>: Sized { | |||
12 | fn syntax(&self) -> &SyntaxNode<R>; | 12 | fn syntax(&self) -> &SyntaxNode<R>; |
13 | } | 13 | } |
14 | 14 | ||
15 | pub trait NameOwner<R: TreeRoot>: AstNode<R> { | ||
16 | fn name(&self) -> Option<Name<R>> { | ||
17 | self.syntax() | ||
18 | .children() | ||
19 | .filter_map(Name::cast) | ||
20 | .next() | ||
21 | } | ||
22 | } | ||
23 | |||
15 | impl File<Arc<SyntaxRoot>> { | 24 | impl File<Arc<SyntaxRoot>> { |
16 | pub fn parse(text: &str) -> Self { | 25 | pub fn parse(text: &str) -> Self { |
17 | File::cast(::parse(text)).unwrap() | 26 | File::cast(::parse(text)).unwrap() |