use chomp::{ ast::{ convert::{Context, Convert}, typed::{FlastContext, Type}, }, nibble::Expression, }; use proc_macro2::Span; use std::process::exit; use std::{ error::Error, io::{self, Read, Write}, }; use syn::Ident; fn main() { let mut input = String::new(); let res = io::stdin() .read_to_string(&mut input) .map_err(|e| Box::new(e) as Box) .and_then(|_| syn::parse_str(&input).map_err(|e| Box::new(e) as Box)) .map(|nibble: Expression| { nibble .convert(&Context::new()) .well_typed(&mut FlastContext::new()) }) .map(|res| match res { Ok((typed, _)) => typed.emit_code(Ident::new("Ast", Span::call_site())), Err(e) => syn::Error::from(e).to_compile_error(), }) .and_then(|code| { write!(io::stdout(), "{:#}", code).map_err(|e| Box::new(e) as Box) }); if let Err(e) = res { eprintln!("{}", e); drop(e); exit(1) } }