pub trait Node {
fn kind(&self) -> &str;
fn start_byte(&self) -> usize;
fn end_byte(&self) -> usize;
fn child_count(&self) -> usize;
fn child(&self, i: usize) -> Option<Self>
where
Self: Sized;
fn is_named(&self) -> bool;
fn is_missing(&self) -> bool;
fn is_error(&self) -> bool;
fn extract_label(&self, text: &[u8]) -> Option<Vec<u8>> {
let pos = self.start_byte();
let end = self.end_byte();
if self.has_label() {
Some(text[pos..end].to_vec())
} else {
None
}
}
fn has_label(&self) -> bool {
if self.child_count() >= 1 {
false
} else if self.is_named() {
true
} else {
false
}
}
}
pub trait NodeWithU16TypeId: Node {
fn kind_id(&self) -> u16;
}
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
pub enum Visibility {
Visible,
Hidden,
}
pub trait TreeCursor {
type N: Node;
fn node(&self) -> Self::N;
fn role(&self) -> Option<std::num::NonZeroU16>;
fn goto_parent(&mut self) -> bool;
fn goto_first_child_extended(&mut self) -> Option<Visibility> {
if self.goto_first_child() {
Some(Visibility::Visible)
} else {
None
}
}
fn goto_next_sibling_extended(&mut self) -> Option<Visibility> {
if self.goto_next_sibling() {
Some(Visibility::Visible)
} else {
None
}
}
fn goto_first_child(&mut self) -> bool;
fn goto_next_sibling(&mut self) -> bool;
}