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}
50
51impl<'a> Initialized<'a> for WorkbenchDefinition {
52 fn statements(&'a self) -> std::slice::Iter<'a, Statement> {
53 self.body.statements.iter()
54 }
55}
56
57impl SrcReferrer for WorkbenchDefinition {
58 fn src_ref(&self) -> SrcRef {
59 self.id.src_ref()
60 }
61}
62
63impl std::fmt::Display for WorkbenchDefinition {
64 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
65 write!(
66 f,
67 "{visibility}{kind} {id}({plan}) {body}",
68 visibility = self.visibility,
69 kind = self.kind,
70 id = self.id,
71 plan = self.plan,
72 body = self.body
73 )
74 }
75}
76
77impl std::fmt::Debug for WorkbenchDefinition {
78 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
79 write!(
80 f,
81 "{visibility}{kind} {id:?}({plan:?}) {body:?}",
82 visibility = self.visibility,
83 kind = self.kind,
84 id = self.id,
85 plan = self.plan,
86 body = self.body
87 )
88 }
89}
90
91impl TreeDisplay for WorkbenchDefinition {
92 fn tree_print(&self, f: &mut std::fmt::Formatter, mut depth: TreeState) -> std::fmt::Result {
93 writeln!(
94 f,
95 "{:depth$}{visibility}Workbench ({kind}) '{id}':",
96 "",
97 visibility = self.visibility,
98 kind = self.kind,
99 id = self.id
100 )?;
101 depth.indent();
102 if let Some(doc) = &self.doc {
103 doc.tree_print(f, depth)?;
104 }
105 self.plan.tree_print(f, depth)?;
106 self.body.tree_print(f, depth)
107 }
108}
109
110impl Doc for WorkbenchDefinition {
111 fn doc(&self) -> Option<DocBlock> {
112 self.doc.clone()
113 }
114}