From dfc08ff2c6580bbeb3951b223e0332546ba3b0d9 Mon Sep 17 00:00:00 2001 From: Greg Brown Date: Thu, 6 May 2021 19:40:59 +0100 Subject: Introduce lambda expressions. --- autochomp/src/main.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'autochomp/src/main.rs') diff --git a/autochomp/src/main.rs b/autochomp/src/main.rs index cbc0646..d8a78e1 100644 --- a/autochomp/src/main.rs +++ b/autochomp/src/main.rs @@ -7,7 +7,7 @@ use std::{ use chewed::{IterWrapper, Parser}; use chomp::{ chomp::{ - ast::substitute::InlineCalls, + ast::substitute::Reduce, typed::{ context::Context, lower::{Backend, GenerateCode}, @@ -16,7 +16,9 @@ use chomp::{ visit::Visitable, }, lower::RustBackend, + nibble::convert::{self, Convert}, }; +use proc_macro2::Span; fn main() { let mut input = String::new(); @@ -28,12 +30,12 @@ fn main() { .parse::() .map_err(|e| Box::new(e) as Box) }) - .and_then(|ast| ast.convert().map_err(|e| Box::new(e) as Box)) - .and_then(|(funs, goal)| { - funs.into_iter() - .try_rfold(goal, |goal, function| { - goal.fold(&mut InlineCalls { function }) - }) + .and_then(|ast| { + ast.convert(&mut convert::Context::default()) + .map_err(|e| Box::new(e) as Box) + }) + .and_then(|expr| { + expr.fold(&mut Reduce) .map_err(|e| Box::new(e) as Box) }) .and_then(|term| { @@ -46,7 +48,7 @@ fn main() { .map(|typed| { let mut backend = RustBackend::default(); let id = typed.gen(&mut backend); - backend.emit_code(None, None, id) + backend.emit_code(None, Span::call_site(), id) }) .and_then(|code| { write!(io::stdout(), "{:#}", code).map_err(|e| Box::new(e) as Box) -- cgit v1.2.3