#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Arg {
Known(String),
Unknown(String),
Below {
folder: String,
source: String,
},
}
impl Arg {
pub fn known(&self) -> Option<&str> {
match self {
Self::Known(text) => Some(text),
Self::Unknown(_) | Self::Below { .. } => None,
}
}
pub fn text(&self) -> &str {
match self {
Self::Known(text) | Self::Unknown(text) | Self::Below { source: text, .. } => text,
}
}
}
pub const MAX_DEPTH: usize = 8;
pub const MAX_TREE_DEPTH: usize = 400;
pub const MAX_LEN: usize = 64 * 1024;
pub(crate) fn for_each_node<'tree>(
root: tree_sitter::Node<'tree>,
mut visit: impl FnMut(tree_sitter::Node<'tree>),
) {
let mut cursor = root.walk();
loop {
visit(cursor.node());
if cursor.goto_first_child() {
continue;
}
loop {
if cursor.goto_next_sibling() {
break;
}
if !cursor.goto_parent() {
return;
}
}
}
}
pub(crate) fn text<'s>(node: &tree_sitter::Node<'_>, source: &'s str) -> &'s str {
source.get(node.byte_range()).unwrap_or_default()
}