Skip to main content

microcad_lang/parse/
init_definition.rs

1// Copyright © 2025-2026 The µcad authors <info@ucad.xyz>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4use crate::{parse::*, parser::*, syntax::*};
5use microcad_syntax::ast;
6
7impl FromAst for InitDefinition {
8    type AstNode = ast::InitDefinition;
9
10    fn from_ast(node: &Self::AstNode, context: &ParseContext) -> Result<Self, ParseError> {
11        Ok(InitDefinition {
12            doc: node
13                .doc
14                .as_ref()
15                .map(|doc| DocBlock::from_ast(doc, context))
16                .transpose()?,
17            keyword_ref: context.src_ref(&node.keyword_span),
18            parameters: ParameterList::from_ast(&node.arguments, context)?,
19            body: Body::from_ast(&node.body, context)?,
20            src_ref: context.src_ref(&node.span),
21        })
22    }
23}