#![cfg_attr(feature = "strict_docs", allow(missing_docs))]
pub(crate) mod sealed {
pub trait Sealed {}
}
pub type SymbolId = u32;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Span {
pub start: u32,
pub end: u32,
}
pub trait ForestView: sealed::Sealed + Send + Sync {
fn roots(&self) -> &[u32];
fn kind(&self, id: u32) -> SymbolId;
fn span(&self, id: u32) -> Span;
fn best_children(&self, id: u32) -> &[u32];
}
#[cfg(any(test, feature = "test-api", feature = "test_helpers"))]
pub struct ForestTestHooks {
pub error_stats: (bool, usize, u32),
}
pub struct Forest {
pub(crate) view: Box<dyn ForestView>,
#[cfg(any(test, feature = "test-api", feature = "test_helpers"))]
pub(crate) test_hooks: Option<ForestTestHooks>,
}
impl Forest {
pub fn view(&self) -> &dyn ForestView {
&*self.view
}
#[cfg(any(test, feature = "test-api", feature = "test_helpers"))]
pub fn debug_error_stats(&self) -> (bool, usize, u32) {
let hooks = self
.test_hooks
.as_ref()
.expect("Forest built without test hooks");
hooks.error_stats
}
}