1use std::fmt::Display;
2
3use super::*;
4
5impl Debug for VosAST {
6 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
7 f.debug_list().entries(self.statements.iter()).finish()
8 }
9}
10
11impl Debug for VosStatement {
12 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
13 match self {
14 VosStatement::Table(v) => Debug::fmt(v, f),
15 VosStatement::Object(v) => Debug::fmt(v, f),
16 VosStatement::Union(v) => Debug::fmt(v, f),
17 }
18 }
19}
20
21impl Debug for GenericStatement {
22 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
23 match self {
24 GenericStatement::Nothing => f.write_str("[]"),
25 GenericStatement::NumberBound { symbol, number, inclusive } => {
26 write!(f, "[{}{}]", GenericStatement::operator(*symbol, *inclusive), number,)
27 }
28 GenericStatement::NumberRange { min, min_inclusive, max, max_inclusive } => {
29 write!(
30 f,
31 "[{} {} _ {} {}]",
32 min,
33 GenericStatement::operator(Ordering::Less, *min_inclusive),
34 GenericStatement::operator(Ordering::Less, *max_inclusive),
35 max
36 )
37 }
38 GenericStatement::Arguments { arguments } => f.debug_list().entries(arguments.iter()).finish(),
39 }
40 }
41}
42
43impl Debug for FieldStatement {
44 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
45 let mut w = &mut f.debug_struct("FieldStatement");
46 w = w.field("type", &self.typing);
47 w = w.field("value", &self.value);
48 w.finish()
49 }
50}
51
52impl Debug for FieldTyping {
53 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
54 match self.generics == GenericStatement::Nothing {
55 true => Debug::fmt(&self.namespace, f),
56 false => f.debug_struct("FieldType").field("namespace", &self.namespace).field("generics", &self.generics).finish(),
57 }
58 }
59}
60
61impl Debug for ValueStatement {
62 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
63 Debug::fmt(&self.kind, f)
64 }
65}
66
67impl Debug for ValueKind {
68 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
69 match self {
70 ValueKind::Default => f.write_str("default"),
71 ValueKind::Boolean(v) => write!(f, "{}", v),
72 ValueKind::String(v) => write!(f, "{:?}", v),
73 ValueKind::Number(v) => write!(f, "{}", v),
74 ValueKind::Symbol(v) => write!(f, "{}", v),
75 ValueKind::List(v) => f.debug_list().entries(v.iter()).finish(),
76 ValueKind::Dict(v) => f.debug_map().entries(v.iter()).finish(),
77 }
78 }
79}
80
81impl Debug for Namespace {
82 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
83 let scope: Vec<_> = self.scope.iter().map(|v| v.id.as_str()).collect();
84 f.write_str(&scope.join("."))
85 }
86}
87
88impl Display for Namespace {
89 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
90 Debug::fmt(self, f)
91 }
92}
93
94impl Debug for Identifier {
95 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
96 f.write_str(&self.id)
97 }
98}
99
100impl Display for Identifier {
101 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
102 Debug::fmt(self, f)
103 }
104}