microcad_lang/syntax/call/
argument_list.rs1use crate::{ord_map::*, src_ref::*, syntax::*};
7use derive_more::{Deref, DerefMut};
8
9#[derive(Clone, Debug, Default, Deref, DerefMut)]
11pub struct ArgumentList(pub Refer<OrdMap<Identifier, Argument>>);
12
13impl SrcReferrer for ArgumentList {
14 fn src_ref(&self) -> SrcRef {
15 self.0.src_ref()
16 }
17}
18
19impl std::fmt::Display for ArgumentList {
20 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21 write!(f, "{}", {
22 let mut v = self
23 .0
24 .value
25 .iter()
26 .map(|p| p.to_string())
27 .collect::<Vec<_>>();
28 v.sort();
29 v.join(", ")
30 })
31 }
32}
33
34impl TreeDisplay for ArgumentList {
35 fn tree_print(&self, f: &mut std::fmt::Formatter, mut depth: TreeState) -> std::fmt::Result {
36 writeln!(f, "{:depth$}ArgumentList:", "")?;
37 depth.indent();
38 self.0.value.iter().try_for_each(|p| p.tree_print(f, depth))
39 }
40}
41
42impl std::ops::Index<&Identifier> for ArgumentList {
43 type Output = Argument;
44
45 fn index(&self, name: &Identifier) -> &Self::Output {
46 self.0.get(name).expect("key not found")
47 }
48}
49
50impl std::ops::Index<usize> for ArgumentList {
51 type Output = Argument;
52
53 fn index(&self, idx: usize) -> &Self::Output {
54 &self.0.value[idx]
55 }
56}