microcad_lang/syntax/
doc_block.rs

1// Copyright © 2025 The µcad authors <info@ucad.xyz>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4//! Documentation block syntax element
5
6use crate::{src_ref::*, syntax::*};
7
8/// Block of documentation comments, starting with `/// `.
9#[derive(Clone, Debug, Default)]
10pub struct DocBlock {
11    /// Doc comment lines.
12    pub lines: Vec<String>,
13    /// Source reference.
14    pub src_ref: SrcRef,
15}
16
17impl SrcReferrer for DocBlock {
18    fn src_ref(&self) -> SrcRef {
19        self.src_ref.clone()
20    }
21}
22
23impl std::fmt::Display for DocBlock {
24    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25        self.lines
26            .iter()
27            .try_for_each(|doc| writeln!(f, "/// {doc}"))
28    }
29}
30
31impl TreeDisplay for DocBlock {
32    fn tree_print(&self, f: &mut std::fmt::Formatter, mut depth: TreeState) -> std::fmt::Result {
33        writeln!(f, "{:depth$}DocBlock:", "")?;
34        depth.indent();
35        self.lines
36            .iter()
37            .try_for_each(|doc| writeln!(f, "{:depth$}/// {doc}", ""))
38    }
39}