microcad_lang/parse/
doc_block.rs

1// Copyright © 2025 The µcad authors <info@ucad.xyz>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4use crate::{parse::*, parser::*, syntax::DocBlock};
5
6impl Parse for DocBlock {
7    fn parse(pair: Pair) -> ParseResult<Self> {
8        Parser::ensure_rule(&pair, Rule::doc_block);
9        let mut lines = Vec::new();
10        for pair in pair.inner() {
11            if pair.as_rule() == Rule::doc_comment {
12                lines.push(String::from(
13                    pair.as_str()
14                        .trim()
15                        .strip_prefix("/// ")
16                        .unwrap_or_default(),
17                ));
18            }
19        }
20
21        Ok(Self {
22            lines,
23            src_ref: pair.src_ref(),
24        })
25    }
26}