Skip to main content

microcad_lang/parse/
module.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 ModuleDefinition {
8    type AstNode = ast::ModuleDefinition;
9
10    fn from_ast(node: &Self::AstNode, context: &ParseContext) -> Result<Self, ParseError> {
11        Ok(ModuleDefinition {
12            doc: None, // todo
13            visibility: node
14                .visibility
15                .as_ref()
16                .map(|visibility| Visibility::from_ast(visibility, context))
17                .transpose()?
18                .unwrap_or_default(),
19            id: Identifier::from_ast(&node.name, context)?,
20            body: node
21                .body
22                .as_ref()
23                .map(|body| Body::from_ast(body, context))
24                .transpose()?,
25        })
26    }
27}