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