From bd783f1b96f0f7d65e0c405cd47497f555b60467 Mon Sep 17 00:00:00 2001 From: imxyy_soope_ Date: Mon, 5 May 2025 14:19:42 +0800 Subject: [PATCH] feat: parse error --- src/compile/mod.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/compile/mod.rs b/src/compile/mod.rs index 9388a3e..029b75d 100644 --- a/src/compile/mod.rs +++ b/src/compile/mod.rs @@ -1,8 +1,15 @@ +use itertools::Itertools; + mod compile; mod ir; pub fn compile(expr: &str) -> anyhow::Result { - let expr = rnix::Root::parse(expr).tree().expr().unwrap(); + let root = rnix::Root::parse(expr); + if !root.errors().is_empty() { + return Err(anyhow::anyhow!(root.errors().iter().map(|err| err.to_string()).join(";"))) + } + assert!(root.errors().is_empty()); + let expr = root.tree().expr().unwrap(); let ir = ir::downgrade(expr)?; Ok(compile::compile(ir)) }