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)]
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 "{visibility}{kind} {id}({plan}) {body}",
84 visibility = self.visibility,
85 kind = self.kind,
86 id = self.id,
87 plan = self.plan,
88 body = self.body
89 )
90 }
91}
92
93impl std::fmt::Debug for WorkbenchDefinition {
94 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
95 write!(
96 f,
97 "{visibility}{kind} {id:?}({plan:?}) {body:?}",
98 visibility = self.visibility,
99 kind = self.kind,
100 id = self.id,
101 plan = self.plan,
102 body = self.body
103 )
104 }
105}
106
107impl TreeDisplay for WorkbenchDefinition {
108 fn tree_print(&self, f: &mut std::fmt::Formatter, mut depth: TreeState) -> std::fmt::Result {
109 writeln!(
110 f,
111 "{:depth$}{visibility}Workbench ({kind}) '{id}':",
112 "",
113 visibility = self.visibility,
114 kind = self.kind,
115 id = self.id
116 )?;
117 depth.indent();
118 self.doc.tree_print(f, depth)?;
119 self.plan.tree_print(f, depth)?;
120 self.body.tree_print(f, depth)
121 }
122}