microcad_lang/syntax/call/
method_call.rs

1// Copyright © 2024-2025 The µcad authors <info@ucad.xyz>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4//! Method call syntax elements.
5
6use crate::{src_ref::*, syntax::*};
7
8/// Method call syntax entity.
9#[derive(Clone)]
10pub struct MethodCall {
11    /// Name of the method.
12    pub name: QualifiedName,
13    /// List of arguments.
14    pub argument_list: ArgumentList,
15    /// Source code reference.
16    pub src_ref: SrcRef,
17}
18
19impl SrcReferrer for MethodCall {
20    fn src_ref(&self) -> SrcRef {
21        self.src_ref.clone()
22    }
23}
24
25impl std::fmt::Display for MethodCall {
26    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
27        write!(f, "{}({})", self.name, self.argument_list)
28    }
29}
30
31impl std::fmt::Debug for MethodCall {
32    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
33        write!(f, "{:?}({:?})", self.name, self.argument_list)
34    }
35}
36
37impl TreeDisplay for MethodCall {
38    fn tree_print(&self, f: &mut std::fmt::Formatter, mut depth: TreeState) -> std::fmt::Result {
39        writeln!(f, "{:depth$}MethodCall '{}':", "", self.name)?;
40        depth.indent();
41        self.argument_list.tree_print(f, depth)
42    }
43}