microcad_lang/syntax/expression/
tuple_expression.rs1use crate::{src_ref::*, syntax::*};
7
8#[derive(Clone, Default, PartialEq)]
10pub struct TupleExpression {
11 pub args: ArgumentList,
13 pub src_ref: SrcRef,
15}
16
17impl SrcReferrer for TupleExpression {
18 fn src_ref(&self) -> crate::src_ref::SrcRef {
19 self.src_ref.clone()
20 }
21}
22
23impl std::fmt::Display for TupleExpression {
24 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
25 write!(
26 f,
27 "({})",
28 self.args
29 .iter()
30 .map(|arg| if let Some(name) = &arg.id {
31 format!("{} = {}", &name, arg.expression)
32 } else {
33 arg.to_string()
34 })
35 .collect::<Vec<String>>()
36 .join(", ")
37 )?;
38 Ok(())
39 }
40}
41
42impl std::fmt::Debug for TupleExpression {
43 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
44 write!(
45 f,
46 "({})",
47 self.args
48 .iter()
49 .map(|arg| if let Some(name) = &arg.id {
50 format!("{:?} = {:?}", &name, arg.expression)
51 } else {
52 arg.to_string()
53 })
54 .collect::<Vec<String>>()
55 .join(", ")
56 )?;
57 Ok(())
58 }
59}
60
61impl TreeDisplay for TupleExpression {
62 fn tree_print(&self, f: &mut std::fmt::Formatter, mut depth: TreeState) -> std::fmt::Result {
63 writeln!(f, "{:depth$}TupleExpression:", "")?;
64 depth.indent();
65 self.args.tree_print(f, depth)
66 }
67}