generatedSubtreeRepeatDepth function
Implementation
int generatedSubtreeRepeatDepth(GeneratedTreeSitterNode node) {
final depths = <GeneratedTreeSitterNode, int>{};
final pending = <(GeneratedTreeSitterNode, bool)>[(node, false)];
while (pending.isNotEmpty) {
final item = pending.removeLast();
if (!item.$2) {
pending.add((item.$1, true));
for (final child in item.$1.children.reversed) {
pending.add((child, false));
}
continue;
}
final current = item.$1;
var depth = 0;
if (current.children.length >= 2 &&
!current.visible &&
!current.named &&
current.children.first.structuralSymbol == current.structuralSymbol) {
final left = depths[current.children.first] ?? 0;
final right = depths[current.children.last] ?? 0;
depth = 1 + (left > right ? left : right);
}
depths[current] = depth;
}
return depths[node] ?? 0;
}