Skip to main content

microcad_lang/syntax/call/
method_call.rs

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