diff options
author | Greg Brown <gmb60@cam.ac.uk> | 2021-05-06 19:40:59 +0100 |
---|---|---|
committer | Greg Brown <gmb60@cam.ac.uk> | 2021-05-06 19:40:59 +0100 |
commit | dfc08ff2c6580bbeb3951b223e0332546ba3b0d9 (patch) | |
tree | 60597dd9492b9c2dfa10ea610289f143dd3e41b7 /autochomp/src/main.rs | |
parent | ef485d6f3e4df6e1a424ba3797388fa0bba6eb2e (diff) |
Introduce lambda expressions.
Diffstat (limited to 'autochomp/src/main.rs')
-rw-r--r-- | autochomp/src/main.rs | 18 |
1 files changed, 10 insertions, 8 deletions
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::<autochomp::Ast>() .map_err(|e| Box::new(e) as Box<dyn Error>) }) - .and_then(|ast| ast.convert().map_err(|e| Box::new(e) as Box<dyn Error>)) - .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<dyn Error>) + }) + .and_then(|expr| { + expr.fold(&mut Reduce) .map_err(|e| Box::new(e) as Box<dyn Error>) }) .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<dyn Error>) |