Updated macro system to process and return mactree and then lower it separately to gexpr
Some checks failed
Rust / build (push) Has been cancelled
Some checks failed
Rust / build (push) Has been cancelled
This commit is contained in:
@@ -1,19 +1,17 @@
|
||||
use futures::StreamExt;
|
||||
use orchid_base::sym;
|
||||
use orchid_extension::gen_expr::{call, new_atom};
|
||||
use orchid_extension::gen_expr::new_atom;
|
||||
use orchid_extension::tree::{GenMember, fun, prefix};
|
||||
use orchid_extension::{Expr, TAtom, ToExpr, exec};
|
||||
use orchid_extension::{Expr, TAtom, exec};
|
||||
|
||||
use crate::macros::match_macros::MatcherAtom;
|
||||
use crate::macros::match_macros::{MatcherAtom, match_one};
|
||||
use crate::macros::utils::{build_macro, mactree, mactreev};
|
||||
use crate::{OrcOpt, Tpl};
|
||||
|
||||
pub async fn gen_option_macro_lib() -> Vec<GenMember> {
|
||||
prefix("std::option", [
|
||||
fun(false, "is_some_body", |sub: TAtom<MatcherAtom>, val: OrcOpt<Expr>| {
|
||||
fun(false, "is_some_body", |sub: Expr, val: OrcOpt<Expr>| {
|
||||
exec(async move |mut h| {
|
||||
let Some(sub_val) = val.0 else { return Ok(OrcOpt(None)) };
|
||||
sub.run_matcher(&mut h, sub_val).await
|
||||
match_one(&mut h, sub, sub_val).await
|
||||
})
|
||||
}),
|
||||
fun(
|
||||
@@ -24,22 +22,25 @@ pub async fn gen_option_macro_lib() -> Vec<GenMember> {
|
||||
},
|
||||
),
|
||||
build_macro(None, ["some", "none"])
|
||||
.rule(mactreev!(pattern::match_rule ( std::option::some "...$" sub_pattern 0)), [
|
||||
.rule(
|
||||
mactreev!("pattern::match_rule" ( "std::option::some" "...$" sub_pattern 0)),
|
||||
async |mut cx, [sub]| {
|
||||
let sub: TAtom<MatcherAtom> =
|
||||
cx.exec(cx.recur(mactree!(pattern::match_rule "push" sub;))).await?;
|
||||
Ok(new_atom(MatcherAtom {
|
||||
keys: sub.keys().collect().await,
|
||||
matcher: call(sym!(std::option::is_some_body), sub).await.create().await,
|
||||
}))
|
||||
cx.recur_call(mactree!("pattern::match_rule" "push" sub;)).await?;
|
||||
let sub = sub.own().await;
|
||||
let matcher = new_atom(MatcherAtom {
|
||||
keys: sub.keys,
|
||||
matcher: mactree!("std::option::is_some_body" "push" sub.matcher),
|
||||
});
|
||||
Ok(mactree!("Val" matcher))
|
||||
},
|
||||
])
|
||||
.rule(mactreev!(pattern::match_rule(std::option::none)), [async |_cx, []| {
|
||||
new_atom(MatcherAtom {
|
||||
)
|
||||
.rule(mactreev!("pattern::match_rule"("std::option::none")), async |_cx, []| {
|
||||
Ok(mactree!("Val" new_atom(MatcherAtom {
|
||||
keys: vec![],
|
||||
matcher: sym!(std::option::is_none_body).to_expr().await,
|
||||
})
|
||||
}])
|
||||
matcher: mactree!("std::option::is_none_body"),
|
||||
})))
|
||||
})
|
||||
.finish(),
|
||||
])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user