summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorGreg Brown <gmb60@cam.ac.uk>2020-11-21 16:35:30 +0000
committerGreg Brown <gmb60@cam.ac.uk>2020-11-21 16:35:30 +0000
commit1183a0996d560fda9d992a9bb8ca1328465a2b33 (patch)
tree56e0dd9643f206739d04793fa278d37bb301c874 /src/main.rs
parentba1a9b1d5259f022e298c385841a39f420ce4155 (diff)
Add code generation
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs22
1 files changed, 22 insertions, 0 deletions
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)
+}