microcad_lang/syntax/
body.rs1use derive_more::Deref;
7
8use crate::{src_ref::*, syntax::*};
9
10#[derive(Clone, Debug, 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 TreeDisplay for Body {
36 fn tree_print(&self, f: &mut std::fmt::Formatter, mut depth: TreeState) -> std::fmt::Result {
37 writeln!(f, "{:depth$}Body:", "")?;
38 depth.indent();
39 self.statements
40 .iter()
41 .try_for_each(|s| s.tree_print(f, depth))
42 }
43}