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
// SPDX-License-Identifier: Apache-2.0
//! The single source of truth for "which tree-sitter nodes are comments" and
//! the non-comment leaf walk built on it.
//!
//! Both change-classification (`strip_comments`) and the semantic-index token
//! stream (`hd-sem-sym-v1`) need to walk an AST in document order while
//! skipping comment subtrees. Keeping the predicate and the walk here — in the
//! parser crate — means there is exactly one definition of "comment" and one
//! traversal shape; the consumers only differ in what they do with each leaf.
use Node;
/// Whether a tree-sitter node kind names a comment. Comment subtrees are
/// skipped wholesale by [`walk_non_comment_leaves`], so doc-comments and
/// ordinary comments alike are excluded from semantic fingerprints.
/// DFS in document order over `node`'s subtree, invoking `on_leaf` for each
/// non-comment leaf (a node with no children). Comment nodes — and their
/// entire subtrees — are skipped.
///
/// The stack pushes children in reverse so they pop in source order, giving a
/// stable pre-order document-order traversal. Iterative (not recursive) so
/// deeply-nested-but-valid input drives heap, not call depth.