mrml/prelude/parser/
output.rs1pub struct ParseOutput<E> {
2 pub element: E,
3 pub warnings: Vec<Warning>,
4}
5
6#[derive(Clone, Copy, Debug, PartialEq, Eq)]
7pub enum WarningKind {
8 UnexpectedAttribute,
9}
10
11impl WarningKind {
12 pub const fn as_str(&self) -> &'static str {
13 "unexpected-attribute"
14 }
15}
16
17impl std::fmt::Display for WarningKind {
18 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
19 match self {
20 Self::UnexpectedAttribute => f.write_str("unexpected attribute"),
21 }
22 }
23}
24
25#[derive(Clone, Debug)]
26pub struct Warning {
27 pub kind: WarningKind,
28 pub origin: super::Origin,
29 pub span: super::Span,
30}
31
32impl super::MrmlCursor<'_> {
33 pub(crate) fn add_warning<S: Into<super::Span>>(&mut self, kind: WarningKind, span: S) {
34 self.warnings.push(Warning {
35 kind,
36 origin: self.origin.clone(),
37 span: span.into(),
38 });
39 }
40
41 pub(crate) fn warnings(self) -> Vec<Warning> {
42 self.warnings
43 }
44
45 pub(crate) fn with_warnings(&mut self, others: Vec<Warning>) {
46 self.warnings.extend(others);
47 }
48}
49
50impl std::fmt::Display for Warning {
51 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
52 write!(
53 f,
54 "{} in {} at position {}",
55 self.kind, self.origin, self.span
56 )
57 }
58}