1 | pub(crate) struct Pretty; |
2 | |
3 | impl crate::visit_mut::VisitMut for Pretty { |
4 | fn visit_document_mut(&mut self, node: &mut crate::DocumentMut) { |
5 | crate::visit_mut::visit_document_mut(self, node); |
6 | } |
7 | |
8 | fn visit_item_mut(&mut self, node: &mut crate::Item) { |
9 | node.make_item(); |
10 | |
11 | crate::visit_mut::visit_item_mut(self, node); |
12 | } |
13 | |
14 | fn visit_table_mut(&mut self, node: &mut crate::Table) { |
15 | node.decor_mut().clear(); |
16 | |
17 | // Empty tables could be semantically meaningful, so make sure they are not implicit |
18 | if !node.is_empty() { |
19 | node.set_implicit(true); |
20 | } |
21 | |
22 | crate::visit_mut::visit_table_mut(self, node); |
23 | } |
24 | |
25 | fn visit_value_mut(&mut self, node: &mut crate::Value) { |
26 | node.decor_mut().clear(); |
27 | |
28 | crate::visit_mut::visit_value_mut(self, node); |
29 | } |
30 | |
31 | fn visit_array_mut(&mut self, node: &mut crate::Array) { |
32 | crate::visit_mut::visit_array_mut(self, node); |
33 | |
34 | if (0..=1).contains(&node.len()) { |
35 | node.set_trailing("" ); |
36 | node.set_trailing_comma(false); |
37 | } else { |
38 | for item in node.iter_mut() { |
39 | item.decor_mut().set_prefix(" \n " ); |
40 | } |
41 | node.set_trailing(" \n" ); |
42 | node.set_trailing_comma(true); |
43 | } |
44 | } |
45 | } |
46 | |