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/// Call of a *workbench* or *function*.
17#[derive(Clone, Debug, Default)]
18pub struct Call {
19    /// Qualified name of the call.
20    pub name: QualifiedName,
21    /// Argument list of the call.
22    pub argument_list: ArgumentList,
23    /// Source code reference.
24    pub src_ref: SrcRef,
25}
26
27impl SrcReferrer for Call {
28    fn src_ref(&self) -> SrcRef {
29        self.src_ref.clone()
30    }
31}
32
33impl std::fmt::Display for Call {
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 Call {
40    fn tree_print(&self, f: &mut std::fmt::Formatter, mut depth: TreeState) -> std::fmt::Result {
41        writeln!(f, "{:depth$}Call '{}':", "", self.name)?;
42        depth.indent();
43        self.argument_list
44            .iter()
45            .try_for_each(|a| a.tree_print(f, depth))
46    }
47}
48
49/// Result of a call.
50pub enum CallResult {
51    /// Call returned models.
52    Models(Vec<Model>),
53
54    /// Call returned a single value.
55    Value(Value),
56
57    /// Call returned nothing.
58    None,
59}