microcad_lang/syntax/
workbench.rs1use crate::{src_ref::*, syntax::*};
7use custom_debug::Debug;
8use strum::Display;
9
10#[derive(Clone, Display, Debug, Copy, PartialEq)]
12pub enum WorkbenchKind {
13 Part,
15 Sketch,
17 Operation,
19}
20
21impl WorkbenchKind {
22 pub fn as_str(&self) -> &'static str {
24 match self {
25 WorkbenchKind::Part => "part",
26 WorkbenchKind::Sketch => "sketch",
27 WorkbenchKind::Operation => "op",
28 }
29 }
30}
31
32#[derive(Clone)]
34pub struct WorkbenchDefinition {
35 pub doc: Option<DocBlock>,
37 pub attribute_list: AttributeList,
39 pub visibility: Visibility,
41 pub kind: Refer<WorkbenchKind>,
43 pub id: Identifier,
45 pub plan: ParameterList,
47 pub body: Body,
49 pub src_ref: SrcRef,
51}
52
53impl WorkbenchDefinition {
54 pub fn src_ref_head(&self) -> SrcRef {
58 SrcRef::merge(&self.kind, &self.plan)
59 }
60}
61
62impl<'a> Initialized<'a> for WorkbenchDefinition {
63 fn statements(&'a self) -> std::slice::Iter<'a, Statement> {
64 self.body.statements.iter()
65 }
66}
67
68impl SrcReferrer for WorkbenchDefinition {
69 fn src_ref(&self) -> SrcRef {
70 self.src_ref.clone()
71 }
72}
73
74impl std::fmt::Display for WorkbenchDefinition {
75 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
76 write!(
77 f,
78 "{visibility}{kind} {id}({plan}) {body}",
79 visibility = self.visibility,
80 kind = self.kind,
81 id = self.id,
82 plan = self.plan,
83 body = self.body
84 )
85 }
86}
87
88impl std::fmt::Debug for WorkbenchDefinition {
89 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
90 write!(
91 f,
92 "{visibility}{kind} {id:?}({plan:?}) {body:?}",
93 visibility = self.visibility,
94 kind = self.kind,
95 id = self.id,
96 plan = self.plan,
97 body = self.body
98 )
99 }
100}
101
102impl TreeDisplay for WorkbenchDefinition {
103 fn tree_print(&self, f: &mut std::fmt::Formatter, mut depth: TreeState) -> std::fmt::Result {
104 writeln!(
105 f,
106 "{:depth$}{visibility}Workbench ({kind}) '{id}':",
107 "",
108 visibility = self.visibility,
109 kind = self.kind,
110 id = self.id
111 )?;
112 depth.indent();
113 if let Some(doc) = &self.doc {
114 doc.tree_print(f, depth)?;
115 }
116 self.plan.tree_print(f, depth)?;
117 self.body.tree_print(f, depth)
118 }
119}
120
121impl Doc for WorkbenchDefinition {
122 fn doc(&self) -> Option<DocBlock> {
123 self.doc.clone()
124 }
125}