microcad_lang/syntax/expression/
marker.rs

1// Copyright © 2025 The µcad authors <info@ucad.xyz>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4//! Node marker syntax element
5
6use crate::{src_ref::*, syntax::*};
7
8/// Node marker, e.g. `@input`.
9#[derive(Clone)]
10pub struct Marker {
11    /// Marker name, e.g. `input`
12    pub id: Identifier,
13    /// Source code reference
14    pub src_ref: SrcRef,
15}
16
17impl Marker {
18    /// Returns true if the marker is an input placeholder
19    pub fn is_input_placeholder(&self) -> bool {
20        &self.id == "input"
21    }
22}
23
24impl SrcReferrer for Marker {
25    fn src_ref(&self) -> crate::src_ref::SrcRef {
26        self.src_ref.clone()
27    }
28}
29
30impl std::fmt::Display for Marker {
31    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32        write!(f, "@{}", self.id)
33    }
34}
35
36impl std::fmt::Debug for Marker {
37    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
38        write!(f, "@{:?}", self.id)
39    }
40}
41
42impl TreeDisplay for Marker {
43    fn tree_print(&self, f: &mut std::fmt::Formatter, depth: TreeState) -> std::fmt::Result {
44        writeln!(f, "{:depth$}Marker '{}'", "", self.id)
45    }
46}