From 52a1f03824d538b5886bacef67df66c22508eb07 Mon Sep 17 00:00:00 2001 From: Greg Brown Date: Tue, 8 Dec 2020 15:07:16 +0000 Subject: Make substitution into a macro. --- src/main.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 7c4babd..5026085 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +use chomp::ast::InlineCall; use chomp::{ast::TypeCheck, nibble::File}; use proc_macro2::Span; use std::{ @@ -14,9 +15,16 @@ fn main() { .map_err(|e| Box::new(e) as Box) .and_then(|_| syn::parse_str(&input).map_err(|e| Box::new(e) as Box)) .and_then(|nibble: File| { - dbg!(nibble - .convert_with_substitution()) - .fold(&mut TypeCheck::new()) + let (funs, goal) = nibble.convert(); + + funs.into_iter() + .try_rfold(goal, |goal, (name, term, args)| { + goal.fold(&mut InlineCall::new(name, term, args)) + }) + .map_err(|e| Box::new(e) as Box) + }) + .and_then(|term| { + term.fold(&mut TypeCheck::new()) .map_err(|e| Box::new(e) as Box) }) .map(|(typed, _)| typed.emit_code(Ident::new("Ast", Span::call_site()))) -- cgit v1.2.3