microcad_lang/syntax/statement/
expression_statement.rs

1// Copyright © 2025 The µcad authors <info@ucad.xyz>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4//! Expression statement syntax elements
5
6use crate::{src_ref::*, syntax::*};
7
8/// An assignment statement, e.g. `#[aux] s = Sphere(3.0mm);`.
9#[derive(Debug, Clone)]
10pub struct ExpressionStatement {
11    /// Optional attributes.
12    pub attribute_list: AttributeList,
13    /// The actual expression.
14    pub expression: Expression,
15    /// Source code reference.
16    pub src_ref: SrcRef,
17}
18
19impl SrcReferrer for ExpressionStatement {
20    fn src_ref(&self) -> SrcRef {
21        self.src_ref.clone()
22    }
23}
24
25impl TreeDisplay for ExpressionStatement {
26    fn tree_print(&self, f: &mut std::fmt::Formatter, depth: TreeState) -> std::fmt::Result {
27        self.expression.tree_print(f, depth)
28    }
29}
30
31impl std::fmt::Display for ExpressionStatement {
32    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33        if !self.attribute_list.is_empty() {
34            write!(f, "{} ", self.attribute_list)?;
35        }
36        write!(f, "{};", self.expression)
37    }
38}