mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 08:44:35 +00:00
Update rowan
This commit is contained in:
parent
2a704035f4
commit
00cdde2c52
14
Cargo.lock
generated
14
Cargo.lock
generated
@ -484,7 +484,7 @@ dependencies = [
|
||||
"num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 0.15.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 0.15.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -684,7 +684,7 @@ dependencies = [
|
||||
"drop_bomb 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"itertools 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rowan 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rowan 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"test_utils 0.1.0",
|
||||
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"walkdir 2.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -804,7 +804,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rowan"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -898,7 +898,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 0.15.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 0.15.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -973,7 +973,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "0.15.11"
|
||||
version = "0.15.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -1355,7 +1355,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum relative-path 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "e614f96449605730b4f7ad2c019e88c1652d730634b4eba07b810801856635e3"
|
||||
"checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5"
|
||||
"checksum ron 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c48677d8a9247a4e0d1f3f9cb4b0a8e29167fdc3c04f383a5e669cd7a960ae0f"
|
||||
"checksum rowan 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4a1a7366ece9deee5e7df8316a136d585d5c5042854c2297f7f1aee3014c9130"
|
||||
"checksum rowan 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4bb1f952404091f61bfea7cd09c564090a0fcee3d22223f98084e8756e01c04d"
|
||||
"checksum rustc-demangle 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "bcfe5b13211b4d78e5c2cadfebd7769197d95c639c35a50057eb4c05de811395"
|
||||
"checksum rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7540fc8b0c49f096ee9c961cda096467dce8084bec6bdca2fc83895fd9b28cb8"
|
||||
"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
|
||||
@ -1377,7 +1377,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550"
|
||||
"checksum superslice 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b50b13d42370e0f5fc62eafdd5c2d20065eaf5458dab215ff3e20e63eea96b30"
|
||||
"checksum syn 0.14.9 (registry+https://github.com/rust-lang/crates.io-index)" = "261ae9ecaa397c42b960649561949d69311f08eeaea86a65696e6e46517cf741"
|
||||
"checksum syn 0.15.11 (registry+https://github.com/rust-lang/crates.io-index)" = "b036b7b35e846707c0e55c2c9441fa47867c0f87fca416921db3261b1d8c741a"
|
||||
"checksum syn 0.15.12 (registry+https://github.com/rust-lang/crates.io-index)" = "34ab9797e47d24cb76b8dc4d24ff36807018c7cc549c4cba050b068be0c586b0"
|
||||
"checksum synstructure 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "85bb9b7550d063ea184027c9b8c20ac167cd36d3e06b3a40bceb9d746dc1a7b7"
|
||||
"checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8"
|
||||
"checksum tera 0.11.18 (registry+https://github.com/rust-lang/crates.io-index)" = "6c87cae42cc4fc480278c7583792cc5da2d51a25be916b7921cbb45c43063b8d"
|
||||
|
@ -3,10 +3,10 @@ use crate::TextRange;
|
||||
use ra_syntax::{
|
||||
algo::{
|
||||
visit::{visitor, Visitor},
|
||||
walk::{walk, WalkEvent},
|
||||
},
|
||||
ast::{self, NameOwner},
|
||||
AstNode, File, SmolStr, SyntaxKind, SyntaxNodeRef,
|
||||
WalkEvent,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@ -54,7 +54,7 @@ pub fn file_structure(file: &File) -> Vec<StructureNode> {
|
||||
let mut res = Vec::new();
|
||||
let mut stack = Vec::new();
|
||||
|
||||
for event in walk(file.syntax()) {
|
||||
for event in file.syntax().preorder() {
|
||||
match event {
|
||||
WalkEvent::Enter(node) => match structure_node(node) {
|
||||
Some(mut symbol) => {
|
||||
@ -64,7 +64,7 @@ pub fn file_structure(file: &File) -> Vec<StructureNode> {
|
||||
}
|
||||
None => (),
|
||||
},
|
||||
WalkEvent::Exit(node) => {
|
||||
WalkEvent::Leave(node) => {
|
||||
if structure_node(node).is_some() {
|
||||
stack.pop().unwrap();
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ unicode-xid = "0.1.0"
|
||||
itertools = "0.7.8"
|
||||
drop_bomb = "0.1.4"
|
||||
parking_lot = "0.6.0"
|
||||
rowan = "0.1.0"
|
||||
rowan = "0.1.1"
|
||||
|
||||
[dev-dependencies]
|
||||
test_utils = { path = "../test_utils" }
|
||||
|
@ -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)
|
||||
})
|
||||
}
|
@ -52,7 +52,7 @@ pub use crate::{
|
||||
reparsing::AtomEdit,
|
||||
rowan::{SmolStr, TextRange, TextUnit},
|
||||
syntax_kinds::SyntaxKind,
|
||||
yellow::{Direction, OwnedRoot, RefRoot, SyntaxError, SyntaxNode, SyntaxNodeRef, TreeRoot},
|
||||
yellow::{Direction, OwnedRoot, RefRoot, SyntaxError, SyntaxNode, SyntaxNodeRef, TreeRoot, WalkEvent},
|
||||
};
|
||||
|
||||
use crate::yellow::GreenNode;
|
||||
|
@ -1,6 +1,5 @@
|
||||
use crate::{
|
||||
algo::walk::{walk, WalkEvent},
|
||||
File, SyntaxKind, SyntaxNodeRef,
|
||||
File, SyntaxKind, SyntaxNodeRef, WalkEvent
|
||||
};
|
||||
use std::fmt::Write;
|
||||
|
||||
@ -19,7 +18,7 @@ pub fn dump_tree(syntax: SyntaxNodeRef) -> String {
|
||||
};
|
||||
}
|
||||
|
||||
for event in walk(syntax) {
|
||||
for event in syntax.preorder() {
|
||||
match event {
|
||||
WalkEvent::Enter(node) => {
|
||||
indent!();
|
||||
@ -34,7 +33,7 @@ pub fn dump_tree(syntax: SyntaxNodeRef) -> String {
|
||||
}
|
||||
level += 1;
|
||||
}
|
||||
WalkEvent::Exit(_) => level -= 1,
|
||||
WalkEvent::Leave(_) => level -= 1,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ use std::{
|
||||
};
|
||||
|
||||
pub(crate) use self::builder::GreenBuilder;
|
||||
pub use rowan::TreeRoot;
|
||||
pub use rowan::{TreeRoot, WalkEvent};
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum RaTypes {}
|
||||
@ -71,9 +71,9 @@ impl<'a> SyntaxNodeRef<'a> {
|
||||
crate::algo::generate(Some(self), |&node| node.parent())
|
||||
}
|
||||
pub fn descendants(self) -> impl Iterator<Item = SyntaxNodeRef<'a>> {
|
||||
crate::algo::walk::walk(self).filter_map(|event| match event {
|
||||
crate::algo::walk::WalkEvent::Enter(node) => Some(node),
|
||||
crate::algo::walk::WalkEvent::Exit(_) => None,
|
||||
self.preorder().filter_map(|event| match event {
|
||||
WalkEvent::Enter(node) => Some(node),
|
||||
WalkEvent::Leave(_) => None,
|
||||
})
|
||||
}
|
||||
pub fn siblings(self, direction: Direction) -> impl Iterator<Item = SyntaxNodeRef<'a>> {
|
||||
@ -82,6 +82,12 @@ impl<'a> SyntaxNodeRef<'a> {
|
||||
Direction::Prev => node.prev_sibling(),
|
||||
})
|
||||
}
|
||||
pub fn preorder(self) -> impl Iterator<Item = WalkEvent<SyntaxNodeRef<'a>>> {
|
||||
self.0.preorder().map(|event| match event {
|
||||
WalkEvent::Enter(n) => WalkEvent::Enter(SyntaxNode(n)),
|
||||
WalkEvent::Leave(n) => WalkEvent::Leave(SyntaxNode(n)),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<R: TreeRoot<RaTypes>> SyntaxNode<R> {
|
||||
|
Loading…
Reference in New Issue
Block a user