microcad_lang/syntax/call/
mod.rs

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