use tree_sitter::{Node, Tree};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ObligationScope {
Function,
Block,
}
impl ObligationScope {
#[must_use]
pub fn parse(name: &str) -> Option<Self> {
match name {
"function" => Some(Self::Function),
"block" => Some(Self::Block),
_ => None,
}
}
}
#[derive(Debug, Clone)]
pub struct UnmetObligation<'t> {
pub acquire: Node<'t>,
pub exit: Node<'t>,
pub partial: bool,
}
pub trait ObligationAnalyzer: Send + Sync {
fn analyze<'t>(
&self,
tree: &'t Tree,
source: &str,
scope: ObligationScope,
acquires: &[Node<'t>],
releases: &[Node<'t>],
) -> Vec<UnmetObligation<'t>>;
}
#[cfg(test)]
mod tests {
use super::ObligationScope;
#[test]
fn scope_parses_the_two_names_and_nothing_else() {
assert_eq!(
ObligationScope::parse("function"),
Some(ObligationScope::Function)
);
assert_eq!(
ObligationScope::parse("block"),
Some(ObligationScope::Block)
);
assert_eq!(ObligationScope::parse("loop"), None);
}
}