make ancestors and descendants inherent

This commit is contained in:
Aleksey Kladov 2018-10-02 18:02:57 +03:00
parent dccaa5e45e
commit d323c81d5c
14 changed files with 40 additions and 46 deletions

View file

@ -94,10 +94,6 @@ pub fn find_covering_node(root: SyntaxNodeRef, range: TextRange) -> SyntaxNodeRe
common_ancestor(left, right)
}
pub fn ancestors<'a>(node: SyntaxNodeRef<'a>) -> impl Iterator<Item=SyntaxNodeRef<'a>> {
generate(Some(node), |&node| node.parent())
}
#[derive(Debug)]
pub enum Direction {
Forward,
@ -115,8 +111,8 @@ pub fn siblings<'a>(
}
fn common_ancestor<'a>(n1: SyntaxNodeRef<'a>, n2: SyntaxNodeRef<'a>) -> SyntaxNodeRef<'a> {
for p in ancestors(n1) {
if ancestors(n2).any(|a| a == p) {
for p in n1.ancestors() {
if n2.ancestors().any(|a| a == p) {
return p;
}
}

View file

@ -3,12 +3,6 @@ use {
algo::generate,
};
pub fn preorder<'a>(root: SyntaxNodeRef<'a>) -> impl Iterator<Item = SyntaxNodeRef<'a>> {
walk(root).filter_map(|event| match event {
WalkEvent::Enter(node) => Some(node),
WalkEvent::Exit(_) => None,
})
}
#[derive(Debug, Copy, Clone)]
pub enum WalkEvent<'a> {