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