[][src]Function mamba::desugar::desugar

pub fn desugar(input: &AST) -> DesugarResult

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 core_result = desugar(&ast).unwrap();

assert_eq!(core_result, Core::Return { expr: Box::from(Core::None) });

Failures

Fails if desugaring a construct which has not been implemented yet.

use mamba::common::position::{CaretPos, Position};
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 core_result = desugar(&ast);

assert!(core_result.is_err());

Panics

A malformed AST causes this stage to panic.