microcad_lang/syntax/statement/
mod.rs1use crate::{rc::*, src_ref::*, syntax::*};
7
8mod assignment_statement;
9mod expression_statement;
10mod if_statement;
11mod return_statement;
12mod statement_list;
13
14pub use assignment_statement::*;
15pub use expression_statement::*;
16pub use if_statement::*;
17pub use return_statement::*;
18pub use statement_list::*;
19
20#[derive(Clone, Debug, strum::IntoStaticStr)]
22pub enum Statement {
23 Workbench(Rc<WorkbenchDefinition>),
25 Module(Rc<ModuleDefinition>),
27 Function(Rc<FunctionDefinition>),
29 Init(Rc<InitDefinition>),
31
32 Use(UseStatement),
34 Return(ReturnStatement),
36 If(IfStatement),
38 InnerAttribute(Attribute),
40
41 Assignment(AssignmentStatement),
43 Expression(ExpressionStatement),
45}
46
47impl SrcReferrer for Statement {
48 fn src_ref(&self) -> SrcRef {
49 match self {
50 Self::Workbench(w) => w.src_ref(),
51 Self::Module(m) => m.src_ref(),
52 Self::Function(fd) => fd.src_ref(),
53 Self::Init(mid) => mid.src_ref(),
54
55 Self::Use(us) => us.src_ref(),
56 Self::Return(r) => r.src_ref(),
57 Self::If(i) => i.src_ref(),
58 Self::InnerAttribute(i) => i.src_ref(),
59
60 Self::Assignment(a) => a.src_ref(),
61 Self::Expression(e) => e.src_ref(),
62 }
63 }
64}
65
66impl std::fmt::Display for Statement {
67 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
68 match self {
69 Self::Workbench(w) => {
70 write!(f, "{w}")
71 }
72 Self::Module(m) => {
73 write!(f, "{}", m.id)
74 }
75 Self::Function(_f) => {
76 write!(f, "{}", _f.id)
77 }
78 Self::Init(mi) => {
79 write!(f, "{mi}")
80 }
81
82 Self::Use(u) => write!(f, "{u};"),
83 Self::Return(r) => write!(f, "{r};"),
84 Self::If(i) => write!(f, "{i}"),
85 Self::InnerAttribute(i) => write!(f, "{i}"),
86
87 Self::Assignment(a) => write!(f, "{a}"),
88 Self::Expression(e) => write!(f, "{e}"),
89 }
90 }
91}
92
93impl TreeDisplay for Statement {
94 fn tree_print(&self, f: &mut std::fmt::Formatter, depth: TreeState) -> std::fmt::Result {
95 match self {
97 Self::Workbench(w) => w.tree_print(f, depth),
98 Self::Module(m) => m.tree_print(f, depth),
99 Self::Function(func) => func.tree_print(f, depth),
100 Self::Init(i) => i.tree_print(f, depth),
101
102 Self::Use(u) => u.tree_print(f, depth),
103 Self::Return(r) => r.tree_print(f, depth),
104 Self::If(i) => i.tree_print(f, depth),
105 Self::InnerAttribute(i) => i.tree_print(f, depth),
106
107 Self::Assignment(a) => a.tree_print(f, depth),
108 Self::Expression(e) => e.tree_print(f, depth),
109 }
110 }
111}