diff --git a/hbasm/src/lib.rs b/hbasm/src/lib.rs index c73feff..6c9125f 100644 --- a/hbasm/src/lib.rs +++ b/hbasm/src/lib.rs @@ -1,3 +1,4 @@ +use std::fmt::{Display, Formatter}; use { logos::{Lexer, Logos, Span}, std::{ops::Range, str::FromStr}, @@ -58,6 +59,14 @@ pub struct Error { span: Span, } +impl Display for Error { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "Error {:?} at {:?}", self.kind, self.span) + } +} + +impl std::error::Error for Error {} + macro_rules! expect_matches { ($self:expr, $($pat:pat),* $(,)?) => {$( let $pat = $self.next()? diff --git a/hbasm/src/main.rs b/hbasm/src/main.rs index 171cfe2..bdb6a7a 100644 --- a/hbasm/src/main.rs +++ b/hbasm/src/main.rs @@ -1,3 +1,14 @@ -fn main() { - // TODO +use std::{ + error::Error, + io::{stdin, stdout, Read, Write}, +}; + +fn main() -> Result<(), Box> { + let mut code = String::new(); + stdin().read_to_string(&mut code)?; + + let mut buf = vec![]; + hbasm::assembly(&code, &mut buf)?; + stdout().write_all(&buf)?; + Ok(()) }