microcad_lang/syntax/
body.rs1use derive_more::Deref;
7
8use crate::{src_ref::*, syntax::*};
9
10#[derive(Clone, Default, Deref)]
12pub struct Body {
13 #[deref]
15 pub statements: StatementList,
16 pub src_ref: SrcRef,
18}
19
20impl SrcReferrer for Body {
21 fn src_ref(&self) -> SrcRef {
22 self.src_ref.clone()
23 }
24}
25
26impl std::fmt::Display for Body {
27 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
28 writeln!(f, " {{")?;
29 writeln!(f, "{}", self.statements)?;
30 writeln!(f, "}}")?;
31 Ok(())
32 }
33}
34
35impl std::fmt::Debug for Body {
36 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
37 writeln!(f, " {{")?;
38 writeln!(f, "{:?}", self.statements)?;
39 writeln!(f, "}}")?;
40 Ok(())
41 }
42}
43
44impl TreeDisplay for Body {
45 fn tree_print(&self, f: &mut std::fmt::Formatter, mut depth: TreeState) -> std::fmt::Result {
46 writeln!(f, "{:depth$}Body:", "")?;
47 depth.indent();
48 self.statements
49 .iter()
50 .try_for_each(|s| s.tree_print(f, depth))
51 }
52}