From 1183a0996d560fda9d992a9bb8ca1328465a2b33 Mon Sep 17 00:00:00 2001 From: Greg Brown Date: Sat, 21 Nov 2020 16:35:30 +0000 Subject: Add code generation --- src/main.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/main.rs (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..9eb762a --- /dev/null +++ b/src/main.rs @@ -0,0 +1,22 @@ +use chomp::{ + ast::{ + convert::{Context, Convert}, + typed::Type, + }, + nibble::Expression, +}; +use proc_macro2::Span; +use std::io::{self, Error, ErrorKind, Read, Write}; +use syn::Ident; + +fn main() -> io::Result<()> { + let mut input = String::new(); + io::stdin().read_to_string(&mut input)?; + let nibble: Expression = + syn::parse_str(&input).map_err(|e| Error::new(ErrorKind::InvalidData, e))?; + let term = nibble.convert(&Context::new()); + // FIXME: better error handling here + let typed = term.well_typed(&mut Vec::new()).unwrap(); + let code = typed.emit_code(Ident::new("Ast", Span::call_site())); + write!(io::stdout(), "{:#}", code) +} -- cgit v1.2.3