1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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)
}
}