Skip to main content

microcad_lang/parse/
workbench.rs

1// Copyright © 2025-2026 The µcad authors <info@microcad.xyz>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4use crate::{parse::*, parser::*, syntax::*};
5use microcad_syntax::ast;
6
7impl From<ast::WorkbenchKind> for WorkbenchKind {
8    fn from(value: ast::WorkbenchKind) -> Self {
9        match value {
10            ast::WorkbenchKind::Sketch => WorkbenchKind::Sketch,
11            ast::WorkbenchKind::Part => WorkbenchKind::Part,
12            ast::WorkbenchKind::Op => WorkbenchKind::Operation,
13        }
14    }
15}
16impl FromAst for std::rc::Rc<WorkbenchDefinition> {
17    type AstNode = ast::WorkbenchDefinition;
18
19    fn from_ast(node: &Self::AstNode, context: &ParseContext) -> Result<Self, ParseError> {
20        Ok(std::rc::Rc::new(WorkbenchDefinition {
21            keyword_ref: context.src_ref(&node.keyword_span),
22            doc: node
23                .doc
24                .as_ref()
25                .map(|doc| DocBlock::from_ast(doc, context))
26                .transpose()?,
27            attribute_list: AttributeList::from_ast(&node.attributes, context)?,
28            visibility: node
29                .visibility
30                .as_ref()
31                .map(|v| Visibility::from_ast(v, context))
32                .transpose()?
33                .unwrap_or_default(),
34            kind: Refer::new(node.kind.into(), context.src_ref(&node.span)),
35            id: Identifier::from_ast(&node.name, context)?,
36            plan: ParameterList::from_ast(&node.plan, context)?,
37            body: Body::from_ast(&node.body, context)?,
38        }))
39    }
40}