use crate::export;
use crate::output::diagnostic;
use crate::output::tree;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Validity {
Valid,
MaybeValid,
Invalid,
}
impl From<diagnostic::Level> for Validity {
fn from(level: diagnostic::Level) -> Self {
match level {
diagnostic::Level::Info => Validity::Valid,
diagnostic::Level::Warning => Validity::MaybeValid,
diagnostic::Level::Error => Validity::Invalid,
}
}
}
impl From<Validity> for diagnostic::Level {
fn from(validity: Validity) -> Self {
match validity {
Validity::Valid => diagnostic::Level::Info,
Validity::MaybeValid => diagnostic::Level::Warning,
Validity::Invalid => diagnostic::Level::Error,
}
}
}
pub struct ParseResult {
pub root: tree::Node,
}
impl ParseResult {
pub fn iter_diagnostics(&self) -> impl Iterator<Item = &diagnostic::Diagnostic> + '_ {
self.root.iter_diagnostics()
}
pub fn get_diagnostic(&self) -> Option<&diagnostic::Diagnostic> {
self.root.get_diagnostic()
}
pub fn check(&self) -> Validity {
if let Some(diag) = self.get_diagnostic() {
diag.adjusted_level.into()
} else {
Validity::Valid
}
}
pub fn export<T: std::io::Write>(
&self,
out: &mut T,
format: export::Format,
) -> std::io::Result<()> {
export::export(out, format, "plan", self)
}
}