luaur_ast/functions/
pretty_print_pretty_printer.rs1use crate::records::ast_stat_block::AstStatBlock;
2use crate::records::printer::Printer;
3use crate::records::string_writer::StringWriter;
4use crate::type_aliases::cst_node_map::CstNodeMap;
5
6pub fn pretty_print_ast_stat_block_cst_node_map(
7 block: &mut AstStatBlock,
8 cst_node_map: CstNodeMap,
9) -> alloc::string::String {
10 let mut writer = StringWriter {
11 ss: alloc::string::String::new(),
12 pos: crate::records::position::Position::new(0, 0),
13 last_char: '\0',
14 };
15
16 {
17 let mut printer = Printer::new(&mut writer, cst_node_map);
19 printer.visualize_block_ast_stat_block(block);
20 }
21
22 writer.str().clone()
24}
25
26impl crate::records::writer::Writer for StringWriter {
27 fn advance(&mut self, new_pos: &crate::records::position::Position) {
28 self.advance(new_pos);
29 }
30
31 fn maybe_space(&mut self, new_pos: &crate::records::position::Position, reserve: i32) {
32 self.maybe_space(new_pos, reserve);
33 }
34
35 fn newline(&mut self) {
36 self.newline();
37 }
38
39 fn space(&mut self) {
40 self.space();
41 }
42
43 fn write_multiline(&mut self, s: &str) {
44 self.write_multiline(s);
45 }
46
47 fn write(&mut self, s: &str) {
48 self.write(s);
49 }
50
51 fn identifier(&mut self, s: &str) {
52 self.identifier(s);
53 }
54
55 fn keyword(&mut self, s: &str) {
56 self.keyword(s);
57 }
58
59 fn symbol(&mut self, s: &str) {
60 self.symbol(s);
61 }
62
63 fn literal(&mut self, s: &str) {
64 self.literal(s);
65 }
66
67 fn string(&mut self, s: &str) {
68 self.string(s);
69 }
70
71 fn source_string(
72 &mut self,
73 s: &str,
74 quote_style: crate::enums::quote_style_cst::QuoteStyle,
75 block_depth: u32,
76 ) {
77 self.source_string(s, quote_style, block_depth);
78 }
79}