Function mamba::generate::gen_arguments
source · pub fn gen_arguments(
ast_ty: &ASTTy,
gen_args: &GenArguments,
ctx: &Context
) -> GenResult
Expand description
Consumes the given AST and produces a Core node.
Note that the given AST must be correctly formed. Therefore, malformed AST’s should be caught by either the parser or the type checker.
Examples
let node = Node::ReturnEmpty;
let ast = AST::new(Position::new(CaretPos::new(1, 1), CaretPos::new(1, 5)), node);
let ast_ty = ASTTy::from(&ast);
let core_result = gen(&ast_ty).unwrap();
assert_eq!(core_result, Core::Return { expr: Box::from(Core::None) });
Failures
Fails if converting a construct which has not been implemented yet.
let cond_node = Node::Int { lit: String::from("56") };
let cond_pos = AST::new(Position::new(CaretPos::new(0, 0), CaretPos::new(0, 5)), cond_node);
let node = Node::Condition { cond: Box::from(cond_pos), el: None };
let ast = AST::new(Position::new(CaretPos::new(0, 0), CaretPos::new(0, 5)), node);
let ast_ty = ASTTy::from(&ast);
let core_result = gen(&ast_ty);
assert!(core_result.is_err());
Panics
A malformed AST causes this stage to panic.