1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
[](https://zizmor.sh/)
[](https://github.com/zizmorcore/zizmor/actions/workflows/ci.yml)
[](https://crates.io/crates/tree-sitter-iter)
[](https://docs.rs/tree-sitter-iter)
[](https://github.com/sponsors/woodruffw)
[](https://discord.com/invite/PGU3zGZuGG)
A very simple pre-order iterator for tree-sitter CSTs.
This library is part of [zizmor].
Given a `tree_sitter::Tree`, you can create a `TreeIter` to iterate
over its nodes in pre-order:
```rust
use tree_sitter_iter::TreeIter;
let tree: tree_sitter::Tree = parse(); // Your parsing logic here.
for node in TreeIter::new(&tree) {
}
```
`TreeIter` implements the standard `Iterator` trait, meaning that
you can use any of the normal iterator combinators. For example, to
filter only to nodes of a specific kind:
```rust
`tree-sitter-iter`'s space and time performance is equivalent to a
walk of the tree using the `TreeCursor` APIs. In other words, it's
exactly the same as using a `TreeCursor` manually, but with a more ergonomic
iterator interface.
See the [documentation] for more details.