Fixed macro system by reintroducing MacTok::Resolved

This commit is contained in:
2026-04-16 20:12:28 +00:00
parent 23180b66e3
commit 286040c3ec
14 changed files with 130 additions and 58 deletions

View File

@@ -1,7 +1,9 @@
use orchid_extension::gen_expr::new_atom;
use orchid_extension::tree::{GenMember, fun, prefix};
use orchid_extension::{TAtom, exec};
use substack::Substack;
use crate::macros::lower::lower;
use crate::macros::mactree::MacTree;
use crate::macros::resolve::resolve;
use crate::macros::utils::{build_macro, mactree, mactreev};
@@ -12,9 +14,10 @@ pub async fn gen_macro_lib() -> Vec<GenMember> {
fun(true, "resolve", async |tpl: TAtom<MacTree>| {
exec(async move |mut h| new_atom(resolve(&mut h, tpl.own().await).await)).await
}),
fun(true, "lower", async |mt: TAtom<MacTree>| lower(&mt.own().await, Substack::Bottom).await),
prefix("common", [
build_macro(None, ["..", "_", "="]).finish(),
build_macro(Some(1), ["+"])
build_macro(Some(30), ["+"])
.rule(
mactreev!("...$" lhs 1 "macros::common::+" "...$" rhs 0),
async |mut cx, [lhs, rhs]| {
@@ -24,7 +27,7 @@ pub async fn gen_macro_lib() -> Vec<GenMember> {
},
)
.finish(),
build_macro(Some(1), ["-"])
build_macro(Some(30), ["-"])
.rule(
mactreev!("...$" lhs 1 "macros::common::-" "...$" rhs 0),
async |mut cx, [lhs, rhs]| {
@@ -34,7 +37,7 @@ pub async fn gen_macro_lib() -> Vec<GenMember> {
},
)
.finish(),
build_macro(Some(2), ["*"])
build_macro(Some(20), ["*"])
.rule(
mactreev!("...$" lhs 1 "macros::common::*" "...$" rhs 0),
async |mut cx, [lhs, rhs]| {
@@ -44,7 +47,7 @@ pub async fn gen_macro_lib() -> Vec<GenMember> {
},
)
.finish(),
build_macro(Some(2), ["/"])
build_macro(Some(20), ["/"])
.rule(
mactreev!("...$" lhs 1 "macros::common::/" "...$" rhs 0),
async |mut cx, [lhs, rhs]| {
@@ -54,7 +57,7 @@ pub async fn gen_macro_lib() -> Vec<GenMember> {
},
)
.finish(),
build_macro(Some(2), ["%"])
build_macro(Some(20), ["%"])
.rule(
mactreev!("...$" lhs 1 "macros::common::%" "...$" rhs 0),
async |mut cx, [lhs, rhs]| {
@@ -64,7 +67,7 @@ pub async fn gen_macro_lib() -> Vec<GenMember> {
},
)
.finish(),
build_macro(Some(3), ["."])
build_macro(Some(10), ["."])
.rule(
mactreev!("...$" lhs 1 "macros::common::." "...$" rhs 0),
async |mut cx, [lhs, rhs]| {