microcad_lang/parse/
call.rs1use microcad_syntax::ast;
5use crate::{ord_map::*, parse::*, parser::*, syntax::*};
6
7impl FromAst for Call {
8 type AstNode = ast::Call;
9
10 fn from_ast(node: &Self::AstNode, context: &ParseContext) -> Result<Self, ParseError> {
11 Ok(Call {
12 src_ref: context.src_ref(&node.span),
13 name: QualifiedName::from_ast(&node.name, context)?,
14 argument_list: ArgumentList::from_ast(&node.arguments, context)?,
15 })
16 }
17}
18
19impl FromAst for ArgumentList {
20 type AstNode = ast::ArgumentList;
21
22 fn from_ast(node: &Self::AstNode, context: &ParseContext) -> Result<Self, ParseError> {
23 let mut argument_list = ArgumentList(Refer::new(OrdMap::default(), context.src_ref(&node.span)));
24 for arg in &node.arguments {
25 argument_list
26 .try_push(Argument::from_ast(arg, context)?)
27 .map_err(ParseError::DuplicateArgument)?;
28 }
29 Ok(argument_list)
30 }
31}
32
33impl FromAst for Argument {
34 type AstNode = ast::Argument;
35
36 fn from_ast(node: &Self::AstNode, context: &ParseContext) -> Result<Self, ParseError> {
37 Ok(Argument {
38 id: node.name().map(|name| Identifier::from_ast(name, context)).transpose()?,
39 src_ref: context.src_ref(node.span()),
40 expression: Expression::from_ast(node.value(), context)?
41 })
42 }
43}
44
45impl FromAst for MethodCall {
46 type AstNode = ast::Call;
47
48 fn from_ast(node: &Self::AstNode, context: &ParseContext) -> Result<Self, ParseError> {
49 Ok(MethodCall {
50 name: QualifiedName::from_ast(&node.name, context)?,
51 argument_list: ArgumentList::from_ast(&node.arguments, context)?,
52 src_ref: context.src_ref(&node.span),
53 })
54 }
55}