Added support for defining macros in Rust within the macro system
Also fixed a lot of bugs
This commit is contained in:
@@ -3,7 +3,7 @@ use std::path::{Path, PathBuf};
|
||||
|
||||
use futures::FutureExt;
|
||||
use itertools::Itertools;
|
||||
use orchid_base::error::{OrcRes, Reporter, async_io_err, mk_errv, os_str_to_string};
|
||||
use orchid_base::error::{OrcRes, Reporter, async_io_err, os_str_to_string};
|
||||
use orchid_base::location::SrcRange;
|
||||
use orchid_base::name::Sym;
|
||||
use orchid_base::parse::Snippet;
|
||||
@@ -29,16 +29,6 @@ pub async fn parse_folder(
|
||||
async fn recur(path: &Path, ns: Sym, rep: &Reporter, ctx: Ctx) -> OrcRes<Option<ParsedModule>> {
|
||||
let sr = SrcRange::new(0..0, &ns);
|
||||
if path.is_dir() {
|
||||
let Some(name_os) = path.file_name() else {
|
||||
return Err(mk_errv(
|
||||
ctx.i.i("Could not read directory name").await,
|
||||
format!("Path {} ends in ..", path.to_string_lossy()),
|
||||
[sr],
|
||||
));
|
||||
};
|
||||
let name = ctx.i.i(os_str_to_string(name_os, &ctx.i, [sr]).await?).await;
|
||||
let ns = ns.suffix([name.clone()], &ctx.i).await;
|
||||
let sr = SrcRange::new(0..0, &ns);
|
||||
let mut items = Vec::new();
|
||||
let mut stream = match fs::read_dir(path).await {
|
||||
Err(err) => return Err(async_io_err(err, &ctx.i, [sr]).await),
|
||||
@@ -53,6 +43,10 @@ pub async fn parse_folder(
|
||||
continue;
|
||||
},
|
||||
};
|
||||
let os_name = entry.path().file_stem().expect("File name could not be read").to_owned();
|
||||
let name = ctx.i.i(os_str_to_string(&os_name, &ctx.i, [sr.clone()]).await?).await;
|
||||
let ns = ns.suffix([name.clone()], &ctx.i).await;
|
||||
let sr = SrcRange::new(0..0, &ns);
|
||||
match recur(&entry.path(), ns.clone(), rep, ctx.clone()).boxed_local().await {
|
||||
Err(e) => {
|
||||
rep.report(e);
|
||||
@@ -64,10 +58,6 @@ pub async fn parse_folder(
|
||||
}
|
||||
Ok(Some(ParsedModule::new(false, items)))
|
||||
} else if path.extension() == Some(OsStr::new("orc")) {
|
||||
let name_os = path.file_stem().expect("If there is an extension, there must be a stem");
|
||||
let name = ctx.i.i(os_str_to_string(name_os, &ctx.i, [sr]).await?).await;
|
||||
let ns = ns.suffix([name], &ctx.i).await;
|
||||
let sr = SrcRange::new(0..0, &ns);
|
||||
let mut file = match File::open(path).await {
|
||||
Err(e) => return Err(async_io_err(e, &ctx.i, [sr]).await),
|
||||
Ok(file) => file,
|
||||
|
||||
Reference in New Issue
Block a user