diff options
author | Greg Brown <gmb60@cam.ac.uk> | 2020-12-08 15:07:16 +0000 |
---|---|---|
committer | Greg Brown <gmb60@cam.ac.uk> | 2020-12-08 15:07:16 +0000 |
commit | 52a1f03824d538b5886bacef67df66c22508eb07 (patch) | |
tree | f2ed2b58bbe531bda7b96d665110bddc6e9b7ef4 /src/main.rs | |
parent | 7e9a41f578be2ec2de13fdd512df37884e514e10 (diff) |
Make substitution into a macro.
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 14 |
1 files changed, 11 insertions, 3 deletions
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<dyn Error>) .and_then(|_| syn::parse_str(&input).map_err(|e| Box::new(e) as Box<dyn Error>)) .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<dyn Error>) + }) + .and_then(|term| { + term.fold(&mut TypeCheck::new()) .map_err(|e| Box::new(e) as Box<dyn Error>) }) .map(|(typed, _)| typed.emit_code(Ident::new("Ast", Span::call_site()))) |