use corpora_core::subscriber::ek;
use corpora_core::{Context, Diagnostic, Event, Interest, Subscriber};
pub struct Gate;
impl Subscriber for Gate {
fn name(&self) -> &'static str {
"gate"
}
fn interest(&self) -> Interest {
Interest::only(ek::DIAGNOSTIC)
}
fn handle(&mut self, ev: &Event, _cx: &mut Context<'_>) {
if let Event::Diagnostic(d) = ev {
eprintln!("{d}");
}
}
}
pub struct FailureReporter;
impl Subscriber for FailureReporter {
fn name(&self) -> &'static str {
"failures"
}
fn interest(&self) -> Interest {
Interest::only(ek::PARSE_FAILED)
}
fn handle(&mut self, ev: &Event, cx: &mut Context<'_>) {
if let Event::ParseFailed { path, error } = ev {
cx.error(Diagnostic::warn("PARSE", path, error.0.clone()));
}
}
}