diff options
author | Greg Brown <gmb60@cam.ac.uk> | 2021-01-09 14:31:02 +0000 |
---|---|---|
committer | Greg Brown <gmb60@cam.ac.uk> | 2021-01-09 14:31:02 +0000 |
commit | 0d01692c97ea8ca6fc4b229e5b9678cb252bceda (patch) | |
tree | 6c5ed07740b814f50dddbc6afaefc21c11dc3440 /autochomp/build.rs | |
parent | 487ce4fe0fa081f58d790d7d6417bf7d2659197c (diff) |
Introduce chomp as a procedural macro.
Add a bunch of tests.
Fix chomp and chewed so autochomp compiles.
Diffstat (limited to 'autochomp/build.rs')
-rw-r--r-- | autochomp/build.rs | 78 |
1 files changed, 0 insertions, 78 deletions
diff --git a/autochomp/build.rs b/autochomp/build.rs deleted file mode 100644 index 58c12a1..0000000 --- a/autochomp/build.rs +++ /dev/null @@ -1,78 +0,0 @@ -use std::{ - env, - error::Error, - fmt::Display, - fs, - io::{Read, Write}, - path::Path, - process::Command, -}; - -use chomp::{ - chomp::{ - check::{InlineCall, TypeCheck}, - context::Context, - visit::Visitable, - }, - lower::{rust::RustBackend, Backend, GenerateCode}, - nibble::cst::File, -}; - -const PATH: &str = "src/nibble.nb"; - -#[derive(Debug)] -struct UndecVar; - -impl Display for UndecVar { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "Undeclared variable somewhere.") - } -} -impl Error for UndecVar {} - -fn main() { - println!("cargo:rerun-if-changed={}", PATH); - - let out_dir = env::var("OUT_DIR").unwrap(); - - let mut input = String::new(); - - fs::File::open(PATH) - .map_err(|e| Box::new(e) as Box<dyn Error>) - .and_then(|mut file| { - file.read_to_string(&mut input) - .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| nibble.convert().ok_or(Box::new(UndecVar) as Box<dyn Error>)) - .and_then(|(funs, goal)| { - funs.into_iter() - .try_rfold(goal, |goal, function| { - goal.fold(&mut InlineCall::new(function)) - }) - .map_err(|e| Box::new(e) as Box<dyn Error>) - }) - .and_then(|term| { - let mut context = Context::default(); - term.fold(&mut TypeCheck { - context: &mut context, - }) - .map_err(|e| Box::new(e) as Box<dyn Error>) - }) - .map(|typed| { - let mut backend = RustBackend::default(); - let id = typed.gen(&mut backend); - backend.emit_code(id) - }) - .and_then(|code| { - fs::File::create(Path::new(&out_dir).join("nibble.rs")) - .and_then(|mut f| write!(f, "{}", code)) - .map_err(|e| Box::new(e) as Box<dyn Error>) - }) - .unwrap(); - - Command::new("rustfmt") - .arg(&format!("{}/nibble.rs", out_dir)) - .status() - .unwrap(); -} |