diff options
Diffstat (limited to 'crates/ra_syntax/src/algo/walk.rs')
-rw-r--r-- | crates/ra_syntax/src/algo/walk.rs | 28 |
1 files changed, 0 insertions, 28 deletions
diff --git a/crates/ra_syntax/src/algo/walk.rs b/crates/ra_syntax/src/algo/walk.rs deleted file mode 100644 index 9afa86401..000000000 --- a/crates/ra_syntax/src/algo/walk.rs +++ /dev/null | |||
@@ -1,28 +0,0 @@ | |||
1 | use crate::{algo::generate, SyntaxNodeRef}; | ||
2 | |||
3 | #[derive(Debug, Copy, Clone)] | ||
4 | pub enum WalkEvent<'a> { | ||
5 | Enter(SyntaxNodeRef<'a>), | ||
6 | Exit(SyntaxNodeRef<'a>), | ||
7 | } | ||
8 | |||
9 | pub fn walk<'a>(root: SyntaxNodeRef<'a>) -> impl Iterator<Item = WalkEvent<'a>> { | ||
10 | generate(Some(WalkEvent::Enter(root)), move |pos| { | ||
11 | let next = match *pos { | ||
12 | WalkEvent::Enter(node) => match node.first_child() { | ||
13 | Some(child) => WalkEvent::Enter(child), | ||
14 | None => WalkEvent::Exit(node), | ||
15 | }, | ||
16 | WalkEvent::Exit(node) => { | ||
17 | if node == root { | ||
18 | return None; | ||
19 | } | ||
20 | match node.next_sibling() { | ||
21 | Some(sibling) => WalkEvent::Enter(sibling), | ||
22 | None => WalkEvent::Exit(node.parent().unwrap()), | ||
23 | } | ||
24 | } | ||
25 | }; | ||
26 | Some(next) | ||
27 | }) | ||
28 | } | ||