microcad_lang/syntax/expression/
tuple_expression.rs1use crate::{src_ref::*, syntax::*};
7
8#[derive(Clone, Debug, Default)]
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.value)
32 } else {
33 arg.to_string()
34 })
35 .collect::<Vec<String>>()
36 .join(", ")
37 )?;
38 Ok(())
39 }
40}
41
42impl TreeDisplay for TupleExpression {
43 fn tree_print(&self, f: &mut std::fmt::Formatter, mut depth: TreeState) -> std::fmt::Result {
44 writeln!(f, "{:depth$}TupleExpression:", "")?;
45 depth.indent();
46 self.args.tree_print(f, depth)
47 }
48}