aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-10-17 17:52:25 +0100
committerAleksey Kladov <[email protected]>2018-10-17 17:52:25 +0100
commit00cdde2c5218020b8f6ec751042a436aeef923c7 (patch)
treeaa44f39e0433087c2f862789ed739348f982efdb /crates/ra_syntax/src
parent2a704035f4b36a0db737f59a7c939d17656b516f (diff)
Update rowan
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r--crates/ra_syntax/src/algo/mod.rs2
-rw-r--r--crates/ra_syntax/src/algo/walk.rs28
-rw-r--r--crates/ra_syntax/src/lib.rs2
-rw-r--r--crates/ra_syntax/src/utils.rs7
-rw-r--r--crates/ra_syntax/src/yellow/mod.rs14
5 files changed, 15 insertions, 38 deletions
diff --git a/crates/ra_syntax/src/algo/mod.rs b/crates/ra_syntax/src/algo/mod.rs
index b4896c482..9d2014bc7 100644
--- a/crates/ra_syntax/src/algo/mod.rs
+++ b/crates/ra_syntax/src/algo/mod.rs
@@ -1,5 +1,5 @@
1pub mod visit; 1pub mod visit;
2pub mod walk; 2// pub mod walk;
3 3
4use crate::{ 4use crate::{
5 text_utils::{contains_offset_nonstrict, is_subrange}, 5 text_utils::{contains_offset_nonstrict, is_subrange},
diff --git a/crates/ra_syntax/src/algo/walk.rs b/crates/ra_syntax/src/algo/walk.rs
deleted file mode 100644
index 9afa86401..000000000
--- a/crates/ra_syntax/src/algo/walk.rs
+++ /dev/null
@@ -1,28 +0,0 @@
1use crate::{algo::generate, SyntaxNodeRef};
2
3#[derive(Debug, Copy, Clone)]
4pub enum WalkEvent<'a> {
5 Enter(SyntaxNodeRef<'a>),
6 Exit(SyntaxNodeRef<'a>),
7}
8
9pub fn walk<'a>(root: SyntaxNodeRef<'a>) -> impl Iterator<Item = WalkEvent<'a>> {
10 generate(Some(WalkEvent::Enter(root)), move |pos| {
11 let next = match *pos {
12 WalkEvent::Enter(node) => match node.first_child() {
13 Some(child) => WalkEvent::Enter(child),
14 None => WalkEvent::Exit(node),
15 },
16 WalkEvent::Exit(node) => {
17 if node == root {
18 return None;
19 }
20 match node.next_sibling() {
21 Some(sibling) => WalkEvent::Enter(sibling),
22 None => WalkEvent::Exit(node.parent().unwrap()),
23 }
24 }
25 };
26 Some(next)
27 })
28}
diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs
index 7a9718aad..3698eccd7 100644
--- a/crates/ra_syntax/src/lib.rs
+++ b/crates/ra_syntax/src/lib.rs
@@ -52,7 +52,7 @@ pub use crate::{
52 reparsing::AtomEdit, 52 reparsing::AtomEdit,
53 rowan::{SmolStr, TextRange, TextUnit}, 53 rowan::{SmolStr, TextRange, TextUnit},
54 syntax_kinds::SyntaxKind, 54 syntax_kinds::SyntaxKind,
55 yellow::{Direction, OwnedRoot, RefRoot, SyntaxError, SyntaxNode, SyntaxNodeRef, TreeRoot}, 55 yellow::{Direction, OwnedRoot, RefRoot, SyntaxError, SyntaxNode, SyntaxNodeRef, TreeRoot, WalkEvent},
56}; 56};
57 57
58use crate::yellow::GreenNode; 58use crate::yellow::GreenNode;
diff --git a/crates/ra_syntax/src/utils.rs b/crates/ra_syntax/src/utils.rs
index 27248ff32..7d0ef2fa2 100644
--- a/crates/ra_syntax/src/utils.rs
+++ b/crates/ra_syntax/src/utils.rs
@@ -1,6 +1,5 @@
1use crate::{ 1use crate::{
2 algo::walk::{walk, WalkEvent}, 2 File, SyntaxKind, SyntaxNodeRef, WalkEvent
3 File, SyntaxKind, SyntaxNodeRef,
4}; 3};
5use std::fmt::Write; 4use std::fmt::Write;
6 5
@@ -19,7 +18,7 @@ pub fn dump_tree(syntax: SyntaxNodeRef) -> String {
19 }; 18 };
20 } 19 }
21 20
22 for event in walk(syntax) { 21 for event in syntax.preorder() {
23 match event { 22 match event {
24 WalkEvent::Enter(node) => { 23 WalkEvent::Enter(node) => {
25 indent!(); 24 indent!();
@@ -34,7 +33,7 @@ pub fn dump_tree(syntax: SyntaxNodeRef) -> String {
34 } 33 }
35 level += 1; 34 level += 1;
36 } 35 }
37 WalkEvent::Exit(_) => level -= 1, 36 WalkEvent::Leave(_) => level -= 1,
38 } 37 }
39 } 38 }
40 39
diff --git a/crates/ra_syntax/src/yellow/mod.rs b/crates/ra_syntax/src/yellow/mod.rs
index b5c9da813..650917214 100644
--- a/crates/ra_syntax/src/yellow/mod.rs
+++ b/crates/ra_syntax/src/yellow/mod.rs
@@ -10,7 +10,7 @@ use std::{
10}; 10};
11 11
12pub(crate) use self::builder::GreenBuilder; 12pub(crate) use self::builder::GreenBuilder;
13pub use rowan::TreeRoot; 13pub use rowan::{TreeRoot, WalkEvent};
14 14
15#[derive(Debug, Clone, Copy)] 15#[derive(Debug, Clone, Copy)]
16pub enum RaTypes {} 16pub enum RaTypes {}
@@ -71,9 +71,9 @@ impl<'a> SyntaxNodeRef<'a> {
71 crate::algo::generate(Some(self), |&node| node.parent()) 71 crate::algo::generate(Some(self), |&node| node.parent())
72 } 72 }
73 pub fn descendants(self) -> impl Iterator<Item = SyntaxNodeRef<'a>> { 73 pub fn descendants(self) -> impl Iterator<Item = SyntaxNodeRef<'a>> {
74 crate::algo::walk::walk(self).filter_map(|event| match event { 74 self.preorder().filter_map(|event| match event {
75 crate::algo::walk::WalkEvent::Enter(node) => Some(node), 75 WalkEvent::Enter(node) => Some(node),
76 crate::algo::walk::WalkEvent::Exit(_) => None, 76 WalkEvent::Leave(_) => None,
77 }) 77 })
78 } 78 }
79 pub fn siblings(self, direction: Direction) -> impl Iterator<Item = SyntaxNodeRef<'a>> { 79 pub fn siblings(self, direction: Direction) -> impl Iterator<Item = SyntaxNodeRef<'a>> {
@@ -82,6 +82,12 @@ impl<'a> SyntaxNodeRef<'a> {
82 Direction::Prev => node.prev_sibling(), 82 Direction::Prev => node.prev_sibling(),
83 }) 83 })
84 } 84 }
85 pub fn preorder(self) -> impl Iterator<Item = WalkEvent<SyntaxNodeRef<'a>>> {
86 self.0.preorder().map(|event| match event {
87 WalkEvent::Enter(n) => WalkEvent::Enter(SyntaxNode(n)),
88 WalkEvent::Leave(n) => WalkEvent::Leave(SyntaxNode(n)),
89 })
90 }
85} 91}
86 92
87impl<R: TreeRoot<RaTypes>> SyntaxNode<R> { 93impl<R: TreeRoot<RaTypes>> SyntaxNode<R> {