feat: parse error
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use itertools::Itertools;
|
||||
use inkwell::context::Context;
|
||||
use rustyline::error::ReadlineError;
|
||||
use rustyline::{DefaultEditor, Result};
|
||||
@@ -5,6 +6,7 @@ use rustyline::{DefaultEditor, Result};
|
||||
use nixjit::compile::compile;
|
||||
use nixjit::ir::downgrade;
|
||||
use nixjit::vm::{run, JITContext};
|
||||
use nixjit::error::Error;
|
||||
|
||||
macro_rules! unwrap {
|
||||
($e:expr) => {
|
||||
@@ -28,9 +30,13 @@ fn main() -> Result<()> {
|
||||
continue;
|
||||
}
|
||||
rl.add_history_entry(expr.as_str())?;
|
||||
let downgraded = unwrap!(downgrade(
|
||||
rnix::Root::parse(expr.as_str()).tree().expr().unwrap()
|
||||
));
|
||||
let root = rnix::Root::parse(&expr);
|
||||
if !root.errors().is_empty() {
|
||||
println!("{}", Error::ParseError(root.errors().iter().map(|err| err.to_string()).join(";")));
|
||||
continue;
|
||||
}
|
||||
let expr = root.tree().expr().unwrap();
|
||||
let downgraded = unwrap!(downgrade(expr));
|
||||
let prog = compile(downgraded);
|
||||
let ctx = Context::create();
|
||||
let jit = JITContext::new(&ctx);
|
||||
|
||||
@@ -4,6 +4,8 @@ pub type Result<T> = core::result::Result<T, Error>;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum Error {
|
||||
#[error("error occurred during parse stage: {0}")]
|
||||
ParseError(String),
|
||||
#[error("error occurred during downgrade stage: {0}")]
|
||||
DowngradeError(String),
|
||||
#[error("error occurred during evaluation stage: {0}")]
|
||||
|
||||
Reference in New Issue
Block a user