microcad_lang/parse/
workbench.rs1use crate::{parse::*, parser::*, rc::*, 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 Rc<WorkbenchDefinition> {
17 type AstNode = ast::WorkbenchDefinition;
18
19 fn from_ast(node: &Self::AstNode, context: &ParseContext) -> Result<Self, ParseError> {
20 Ok(Rc::new(WorkbenchDefinition {
21 doc: node
22 .doc
23 .as_ref()
24 .map(|doc| DocBlock::from_ast(doc, context))
25 .transpose()?,
26 attribute_list: AttributeList::from_ast(&node.attributes, context)?,
27 visibility: node
28 .visibility
29 .as_ref()
30 .map(|v| Visibility::from_ast(v, context))
31 .transpose()?
32 .unwrap_or_default(),
33 kind: Refer::new(node.kind.into(), context.src_ref(&node.span)),
34 id: Identifier::from_ast(&node.name, context)?,
35 plan: ParameterList::from_ast(&node.arguments, context)?,
36 body: Body::from_ast(&node.body, context)?,
37 }))
38 }
39}