microcad_lang/syntax/expression/
range_expression.rs1use derive_more::Deref;
7
8use crate::{src_ref::*, syntax::*};
9
10#[derive(Clone, Default, Deref, PartialEq)]
12pub struct RangeFirst(pub Box<Expression>);
13
14impl SrcReferrer for RangeFirst {
15 fn src_ref(&self) -> crate::src_ref::SrcRef {
16 self.0.src_ref()
17 }
18}
19
20impl std::fmt::Display for RangeFirst {
21 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
22 write!(f, "{}", self.0)
23 }
24}
25
26impl std::fmt::Debug for RangeFirst {
27 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
28 write!(f, "{:?}", self.0)
29 }
30}
31
32impl TreeDisplay for RangeFirst {
33 fn tree_print(&self, f: &mut std::fmt::Formatter, mut depth: TreeState) -> std::fmt::Result {
34 writeln!(f, "{:depth$}RangeStart:", "")?;
35 depth.indent();
36 self.0.tree_print(f, depth)
37 }
38}
39
40#[derive(Clone, Default, Deref, PartialEq)]
42pub struct RangeLast(pub Box<Expression>);
43
44impl SrcReferrer for RangeLast {
45 fn src_ref(&self) -> crate::src_ref::SrcRef {
46 self.0.src_ref()
47 }
48}
49
50impl std::fmt::Display for RangeLast {
51 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
52 write!(f, "{}", self.0)
53 }
54}
55
56impl std::fmt::Debug for RangeLast {
57 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
58 write!(f, "{:?}", self.0)
59 }
60}
61
62impl TreeDisplay for RangeLast {
63 fn tree_print(&self, f: &mut std::fmt::Formatter, mut depth: TreeState) -> std::fmt::Result {
64 writeln!(f, "{:depth$}RangeLast:", "")?;
65 depth.indent();
66 self.0.tree_print(f, depth)
67 }
68}
69
70#[derive(Clone, Default, PartialEq)]
72pub struct RangeExpression {
73 pub first: RangeFirst,
75 pub last: RangeLast,
77 pub src_ref: SrcRef,
79}
80
81impl SrcReferrer for RangeExpression {
82 fn src_ref(&self) -> crate::src_ref::SrcRef {
83 self.src_ref.clone()
84 }
85}
86
87impl std::fmt::Display for RangeExpression {
88 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
89 write!(f, "{}..{}", self.first, self.last)
90 }
91}
92
93impl std::fmt::Debug for RangeExpression {
94 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
95 write!(f, "{:?}..{:?}", self.first, self.last)
96 }
97}
98
99impl TreeDisplay for RangeExpression {
100 fn tree_print(&self, f: &mut std::fmt::Formatter, mut depth: TreeState) -> std::fmt::Result {
101 writeln!(f, "{:depth$}RangeExpression:", "")?;
102 depth.indent();
103 self.first.tree_print(f, depth)?;
104 self.last.tree_print(f, depth)
105 }
106}