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