Update rowan

This commit is contained in:
Aleksey Kladov 2018-10-17 19:52:25 +03:00
parent 2a704035f4
commit 00cdde2c52
8 changed files with 26 additions and 49 deletions

View file

@ -1,5 +1,5 @@
pub mod visit;
pub mod walk;
// pub mod walk;
use crate::{
text_utils::{contains_offset_nonstrict, is_subrange},

View file

@ -1,28 +0,0 @@
use crate::{algo::generate, SyntaxNodeRef};
#[derive(Debug, Copy, Clone)]
pub enum WalkEvent<'a> {
Enter(SyntaxNodeRef<'a>),
Exit(SyntaxNodeRef<'a>),
}
pub fn walk<'a>(root: SyntaxNodeRef<'a>) -> impl Iterator<Item = WalkEvent<'a>> {
generate(Some(WalkEvent::Enter(root)), move |pos| {
let next = match *pos {
WalkEvent::Enter(node) => match node.first_child() {
Some(child) => WalkEvent::Enter(child),
None => WalkEvent::Exit(node),
},
WalkEvent::Exit(node) => {
if node == root {
return None;
}
match node.next_sibling() {
Some(sibling) => WalkEvent::Enter(sibling),
None => WalkEvent::Exit(node.parent().unwrap()),
}
}
};
Some(next)
})
}