diff options
author | Aleksey Kladov <[email protected]> | 2018-10-17 17:52:25 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-10-17 17:52:25 +0100 |
commit | 00cdde2c5218020b8f6ec751042a436aeef923c7 (patch) | |
tree | aa44f39e0433087c2f862789ed739348f982efdb /crates | |
parent | 2a704035f4b36a0db737f59a7c939d17656b516f (diff) |
Update rowan
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_editor/src/symbols.rs | 6 | ||||
-rw-r--r-- | crates/ra_syntax/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/ra_syntax/src/algo/mod.rs | 2 | ||||
-rw-r--r-- | crates/ra_syntax/src/algo/walk.rs | 28 | ||||
-rw-r--r-- | crates/ra_syntax/src/lib.rs | 2 | ||||
-rw-r--r-- | crates/ra_syntax/src/utils.rs | 7 | ||||
-rw-r--r-- | crates/ra_syntax/src/yellow/mod.rs | 14 |
7 files changed, 19 insertions, 42 deletions
diff --git a/crates/ra_editor/src/symbols.rs b/crates/ra_editor/src/symbols.rs index b768b34bc..c3c66680d 100644 --- a/crates/ra_editor/src/symbols.rs +++ b/crates/ra_editor/src/symbols.rs | |||
@@ -3,10 +3,10 @@ use crate::TextRange; | |||
3 | use ra_syntax::{ | 3 | use ra_syntax::{ |
4 | algo::{ | 4 | algo::{ |
5 | visit::{visitor, Visitor}, | 5 | visit::{visitor, Visitor}, |
6 | walk::{walk, WalkEvent}, | ||
7 | }, | 6 | }, |
8 | ast::{self, NameOwner}, | 7 | ast::{self, NameOwner}, |
9 | AstNode, File, SmolStr, SyntaxKind, SyntaxNodeRef, | 8 | AstNode, File, SmolStr, SyntaxKind, SyntaxNodeRef, |
9 | WalkEvent, | ||
10 | }; | 10 | }; |
11 | 11 | ||
12 | #[derive(Debug, Clone)] | 12 | #[derive(Debug, Clone)] |
@@ -54,7 +54,7 @@ pub fn file_structure(file: &File) -> Vec<StructureNode> { | |||
54 | let mut res = Vec::new(); | 54 | let mut res = Vec::new(); |
55 | let mut stack = Vec::new(); | 55 | let mut stack = Vec::new(); |
56 | 56 | ||
57 | for event in walk(file.syntax()) { | 57 | for event in file.syntax().preorder() { |
58 | match event { | 58 | match event { |
59 | WalkEvent::Enter(node) => match structure_node(node) { | 59 | WalkEvent::Enter(node) => match structure_node(node) { |
60 | Some(mut symbol) => { | 60 | Some(mut symbol) => { |
@@ -64,7 +64,7 @@ pub fn file_structure(file: &File) -> Vec<StructureNode> { | |||
64 | } | 64 | } |
65 | None => (), | 65 | None => (), |
66 | }, | 66 | }, |
67 | WalkEvent::Exit(node) => { | 67 | WalkEvent::Leave(node) => { |
68 | if structure_node(node).is_some() { | 68 | if structure_node(node).is_some() { |
69 | stack.pop().unwrap(); | 69 | stack.pop().unwrap(); |
70 | } | 70 | } |
diff --git a/crates/ra_syntax/Cargo.toml b/crates/ra_syntax/Cargo.toml index 34bb1c591..7efebab8b 100644 --- a/crates/ra_syntax/Cargo.toml +++ b/crates/ra_syntax/Cargo.toml | |||
@@ -10,7 +10,7 @@ unicode-xid = "0.1.0" | |||
10 | itertools = "0.7.8" | 10 | itertools = "0.7.8" |
11 | drop_bomb = "0.1.4" | 11 | drop_bomb = "0.1.4" |
12 | parking_lot = "0.6.0" | 12 | parking_lot = "0.6.0" |
13 | rowan = "0.1.0" | 13 | rowan = "0.1.1" |
14 | 14 | ||
15 | [dev-dependencies] | 15 | [dev-dependencies] |
16 | test_utils = { path = "../test_utils" } | 16 | test_utils = { path = "../test_utils" } |
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 @@ | |||
1 | pub mod visit; | 1 | pub mod visit; |
2 | pub mod walk; | 2 | // pub mod walk; |
3 | 3 | ||
4 | use crate::{ | 4 | use 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 @@ | |||
1 | use crate::{algo::generate, SyntaxNodeRef}; | ||
2 | |||
3 | #[derive(Debug, Copy, Clone)] | ||
4 | pub enum WalkEvent<'a> { | ||
5 | Enter(SyntaxNodeRef<'a>), | ||
6 | Exit(SyntaxNodeRef<'a>), | ||
7 | } | ||
8 | |||
9 | pub 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 | ||
58 | use crate::yellow::GreenNode; | 58 | use 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 @@ | |||
1 | use crate::{ | 1 | use crate::{ |
2 | algo::walk::{walk, WalkEvent}, | 2 | File, SyntaxKind, SyntaxNodeRef, WalkEvent |
3 | File, SyntaxKind, SyntaxNodeRef, | ||
4 | }; | 3 | }; |
5 | use std::fmt::Write; | 4 | use 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 | ||
12 | pub(crate) use self::builder::GreenBuilder; | 12 | pub(crate) use self::builder::GreenBuilder; |
13 | pub use rowan::TreeRoot; | 13 | pub use rowan::{TreeRoot, WalkEvent}; |
14 | 14 | ||
15 | #[derive(Debug, Clone, Copy)] | 15 | #[derive(Debug, Clone, Copy)] |
16 | pub enum RaTypes {} | 16 | pub 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 | ||
87 | impl<R: TreeRoot<RaTypes>> SyntaxNode<R> { | 93 | impl<R: TreeRoot<RaTypes>> SyntaxNode<R> { |