Skip to main content

microcad_lang/syntax/call/
mod.rs

1// Copyright © 2024-2026 The µcad authors <info@microcad.xyz>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4//! Syntax elements related to calls.
5
6mod argument;
7mod argument_list;
8mod method_call;
9
10pub use argument::*;
11pub use argument_list::*;
12pub use method_call::*;
13use microcad_lang_base::{SrcRef, SrcReferrer, TreeDisplay, TreeState};
14
15use crate::{model::*, syntax::*, value::*};
16
17/// Result of a call.
18pub enum CallResult {
19    /// Call returned models.
20    Models(Vec<Model>),
21    /// Call returned a single value.
22    Value(Value),
23    /// Call returned nothing.
24    None,
25}
26
27/// Call of a *workbench* or *function*.
28#[derive(Clone, Default)]
29pub struct Call {
30    /// Qualified name of the call.
31    pub name: QualifiedName,
32    /// Argument list of the call.
33    pub argument_list: ArgumentList,
34    /// Source code reference.
35    pub src_ref: SrcRef,
36}
37
38impl SrcReferrer for Call {
39    fn src_ref(&self) -> SrcRef {
40        self.src_ref.clone()
41    }
42}
43
44impl std::fmt::Display for Call {
45    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
46        write!(f, "{}({})", self.name, self.argument_list)
47    }
48}
49
50impl std::fmt::Debug for Call {
51    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
52        write!(f, "{:?}({:?})", self.name, self.argument_list)
53    }
54}
55
56impl TreeDisplay for Call {
57    fn tree_print(&self, f: &mut std::fmt::Formatter, mut depth: TreeState) -> std::fmt::Result {
58        writeln!(f, "{:depth$}Call '{}':", "", self.name)?;
59        depth.indent();
60        self.argument_list
61            .iter()
62            .try_for_each(|a| a.tree_print(f, depth))
63    }
64}