Skip to main content

microcad_lang/syntax/expression/
marker.rs

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