aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2/src/algo
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-24 11:41:25 +0100
committerAleksey Kladov <[email protected]>2018-08-24 11:41:25 +0100
commit6cade3f6d8ad7bb5a11b1910689b25f709c12502 (patch)
tree96aea3209cc310462c37708d5623fe1f1d667634 /crates/libsyntax2/src/algo
parent89e56c364f3d0a9d5a12ae488185abc1ea69df4a (diff)
Runnig tests somehow
Diffstat (limited to 'crates/libsyntax2/src/algo')
-rw-r--r--crates/libsyntax2/src/algo/mod.rs13
1 files changed, 4 insertions, 9 deletions
diff --git a/crates/libsyntax2/src/algo/mod.rs b/crates/libsyntax2/src/algo/mod.rs
index 6efdff12f..2640d60ea 100644
--- a/crates/libsyntax2/src/algo/mod.rs
+++ b/crates/libsyntax2/src/algo/mod.rs
@@ -1,7 +1,10 @@
1pub mod walk; 1pub mod walk;
2pub mod visit; 2pub mod visit;
3 3
4use {SyntaxNodeRef, TextUnit, TextRange}; 4use {
5 SyntaxNodeRef, TextUnit, TextRange,
6 text_utils::{contains_offset_nonstrict, is_subrange},
7};
5 8
6pub fn find_leaf_at_offset(node: SyntaxNodeRef, offset: TextUnit) -> LeafAtOffset { 9pub fn find_leaf_at_offset(node: SyntaxNodeRef, offset: TextUnit) -> LeafAtOffset {
7 let range = node.range(); 10 let range = node.range();
@@ -116,14 +119,6 @@ fn common_ancestor<'a>(n1: SyntaxNodeRef<'a>, n2: SyntaxNodeRef<'a>) -> SyntaxNo
116 panic!("Can't find common ancestor of {:?} and {:?}", n1, n2) 119 panic!("Can't find common ancestor of {:?} and {:?}", n1, n2)
117} 120}
118 121
119fn contains_offset_nonstrict(range: TextRange, offset: TextUnit) -> bool {
120 range.start() <= offset && offset <= range.end()
121}
122
123fn is_subrange(range: TextRange, subrange: TextRange) -> bool {
124 range.start() <= subrange.start() && subrange.end() <= range.end()
125}
126
127fn generate<T>(seed: Option<T>, step: impl Fn(&T) -> Option<T>) -> impl Iterator<Item=T> { 122fn generate<T>(seed: Option<T>, step: impl Fn(&T) -> Option<T>) -> impl Iterator<Item=T> {
128 ::itertools::unfold(seed, move |slot| { 123 ::itertools::unfold(seed, move |slot| {
129 slot.take().map(|curr| { 124 slot.take().map(|curr| {