microcad_lang/syntax/
workbench.rs1use crate::{src_ref::*, syntax::*};
7use custom_debug::Debug;
8
9#[derive(Clone, Debug, Copy, PartialEq)]
11pub enum WorkbenchKind {
12 Part,
14 Sketch,
16 Operation,
18}
19
20impl WorkbenchKind {
21 pub fn as_str(&self) -> &'static str {
23 match self {
24 WorkbenchKind::Part => "part",
25 WorkbenchKind::Sketch => "sketch",
26 WorkbenchKind::Operation => "op",
27 }
28 }
29}
30
31impl std::fmt::Display for WorkbenchKind {
32 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33 write!(f, "{}", self.as_str())
34 }
35}
36
37#[derive(Clone, Debug)]
39pub struct WorkbenchDefinition {
40 pub doc: DocBlock,
42 pub attribute_list: AttributeList,
44 pub visibility: Visibility,
46 pub kind: Refer<WorkbenchKind>,
48 pub id: Identifier,
50 pub plan: ParameterList,
52 pub body: Body,
54 pub src_ref: SrcRef,
56}
57
58impl WorkbenchDefinition {
59 pub fn src_ref_head(&self) -> SrcRef {
63 SrcRef::merge(&self.kind, &self.plan)
64 }
65}
66
67impl<'a> Initialized<'a> for WorkbenchDefinition {
68 fn statements(&'a self) -> std::slice::Iter<'a, Statement> {
69 self.body.statements.iter()
70 }
71}
72
73impl SrcReferrer for WorkbenchDefinition {
74 fn src_ref(&self) -> SrcRef {
75 self.src_ref.clone()
76 }
77}
78
79impl std::fmt::Display for WorkbenchDefinition {
80 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
81 write!(
82 f,
83 "{kind} {id}({plan}) {body}",
84 kind = self.kind,
85 id = self.id,
86 plan = self.plan,
87 body = self.body
88 )
89 }
90}
91
92impl TreeDisplay for WorkbenchDefinition {
93 fn tree_print(&self, f: &mut std::fmt::Formatter, mut depth: TreeState) -> std::fmt::Result {
94 writeln!(
95 f,
96 "{:depth$}Workbench ({kind}) '{id}':",
97 "",
98 kind = self.kind,
99 id = self.id
100 )?;
101 depth.indent();
102 self.doc.tree_print(f, depth)?;
103 self.plan.tree_print(f, depth)?;
104 self.body.tree_print(f, depth)
105 }
106}