forked from Orchid/orchid
partway towards commands
I got very confused and started mucking about with "spawn" when in fact all I needed was the "inline" extension type in orcx that allows the interpreter to expose custom constants.
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
use futures::{StreamExt, stream};
|
||||
use orchid_base::error::OrcRes;
|
||||
use orchid_base::sym;
|
||||
use orchid_extension::atom::TAtom;
|
||||
use orchid_extension::atom_owned::own;
|
||||
use orchid_base::{OrcRes, sym};
|
||||
use orchid_extension::TAtom;
|
||||
use orchid_extension::conv::ToExpr;
|
||||
use orchid_extension::coroutine_exec::exec;
|
||||
use orchid_extension::expr::Expr;
|
||||
use orchid_extension::gen_expr::{GExpr, call, new_atom, sym_ref};
|
||||
use orchid_extension::gen_expr::{GExpr, call, new_atom};
|
||||
use orchid_extension::tree::{GenMember, fun, prefix};
|
||||
|
||||
use crate::macros::match_macros::MatcherAtom;
|
||||
@@ -19,19 +17,19 @@ pub async fn gen_tuple_macro_lib() -> Vec<GenMember> {
|
||||
.rule(mactreev!(std::tuple::t [ "...$" elements 0 ]), [|[elements]: [_; _]| {
|
||||
exec(async move |mut h| {
|
||||
let tup = h
|
||||
.exec::<HomoTpl<TAtom<MacTree>>>(call(sym_ref(sym!(macros::resolve)), [
|
||||
.exec::<HomoTpl<TAtom<MacTree>>>(call(sym!(macros::resolve),
|
||||
new_atom(mactree!((macros::common::comma_list "push" elements ;))),
|
||||
]))
|
||||
))
|
||||
.await?;
|
||||
let val = stream::iter(&tup.0[..])
|
||||
.fold(sym_ref(sym!(std::tuple::empty)), async |head, new| {
|
||||
call(sym_ref(sym!(std::tuple::cat)), [
|
||||
.fold(sym!(std::tuple::empty).to_gen().await, async |head, new| {
|
||||
call(sym!(std::tuple::cat), (
|
||||
head,
|
||||
call(sym_ref(sym!(std::tuple::one)), [call(
|
||||
sym_ref(sym!(macros::resolve)),
|
||||
[new.clone().to_gen().await],
|
||||
)]),
|
||||
])
|
||||
call(sym!(std::tuple::one), call(
|
||||
sym!(macros::resolve),
|
||||
new.clone(),
|
||||
)),
|
||||
)).await
|
||||
})
|
||||
.await;
|
||||
Ok(val)
|
||||
@@ -58,25 +56,24 @@ pub async fn gen_tuple_macro_lib() -> Vec<GenMember> {
|
||||
fn parse_tpl(elements: MacTree, tail_matcher: Option<MacTree>) -> impl Future<Output = GExpr> {
|
||||
exec(async move |mut h| -> OrcRes<GExpr> {
|
||||
let tup = h
|
||||
.exec::<HomoTpl<TAtom<MacTree>>>(call(sym_ref(sym!(macros::resolve)), [new_atom(
|
||||
.exec::<HomoTpl<TAtom<MacTree>>>(call(sym!(macros::resolve), new_atom(
|
||||
mactree!((macros::common::comma_list "push" elements ;)),
|
||||
)]))
|
||||
)))
|
||||
.await?;
|
||||
let mut subs = Vec::with_capacity(tup.0.len());
|
||||
for mac_a in &tup.0[..] {
|
||||
let mac = own(mac_a).await;
|
||||
let sub = h
|
||||
.exec::<TAtom<MatcherAtom>>(call(sym_ref(sym!(macros::resolve)), [new_atom(
|
||||
mactree!(pattern::match_rule ("push" mac ;)),
|
||||
)]))
|
||||
.exec::<TAtom<MatcherAtom>>(call(sym!(macros::resolve), new_atom(
|
||||
mactree!(pattern::match_rule ("push" mac_a.own().await ;)),
|
||||
)))
|
||||
.await?;
|
||||
subs.push(sub);
|
||||
}
|
||||
let tail_matcher = match tail_matcher {
|
||||
Some(mac) => Some(
|
||||
h.exec::<TAtom<MatcherAtom>>(call(sym_ref(sym!(macros::resolve)), [new_atom(
|
||||
h.exec::<TAtom<MatcherAtom>>(call(sym!(macros::resolve), new_atom(
|
||||
mactree!(pattern::match_rule "push" mac ;),
|
||||
)]))
|
||||
)))
|
||||
.await?,
|
||||
),
|
||||
None => None,
|
||||
@@ -87,10 +84,10 @@ fn parse_tpl(elements: MacTree, tail_matcher: Option<MacTree>) -> impl Future<Ou
|
||||
.chain(stream::iter(&tail_matcher).flat_map(|mat| mat.keys()))
|
||||
.collect()
|
||||
.await,
|
||||
matcher: call(sym_ref(sym!(std::tuple::matcher_body)), [
|
||||
HomoTpl(subs).to_gen().await,
|
||||
OrcOpt(tail_matcher).to_gen().await,
|
||||
])
|
||||
matcher: call(sym!(std::tuple::matcher_body), (
|
||||
HomoTpl(subs),
|
||||
OrcOpt(tail_matcher),
|
||||
))
|
||||
.to_expr()
|
||||
.await,
|
||||
}))
|
||||
@@ -118,8 +115,8 @@ fn tuple_matcher_body(
|
||||
None => (),
|
||||
Some(tail_mat) => {
|
||||
let tail_tpl = stream::iter(&value.0[children.0.len()..])
|
||||
.fold(sym_ref(sym!(std::tuple::empty)), async |prefix, new| {
|
||||
call(sym_ref(sym!(std::tuple::cat)), [prefix, new.clone().to_gen().await])
|
||||
.fold(sym!(std::tuple::empty).to_gen().await, async |prefix, new| {
|
||||
call(sym!(std::tuple::cat), (prefix, new.clone())).await
|
||||
})
|
||||
.await;
|
||||
match tail_mat.run_matcher(&mut h, tail_tpl).await? {
|
||||
|
||||
Reference in New Issue
Block a user