mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-18 08:10:11 +00:00
Update rowan
This commit is contained in:
parent
2a704035f4
commit
00cdde2c52
8 changed files with 26 additions and 49 deletions
|
@ -1,5 +1,5 @@
|
|||
pub mod visit;
|
||||
pub mod walk;
|
||||
// pub mod walk;
|
||||
|
||||
use crate::{
|
||||
text_utils::{contains_offset_nonstrict, is_subrange},
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue