Fixed match, and enabled macro keywords to share names with constants

This commit is contained in:
2025-11-30 02:30:42 +01:00
parent ecf151158d
commit 4e4dc381ea
7 changed files with 82 additions and 73 deletions

View File

@@ -100,7 +100,7 @@ impl MacroBuilder {
pub(crate) fn finish(self) -> Vec<GenMember> {
let Self { own_kws, prio, patterns, body_consts } = self;
let name = own_kws[0];
let main_const = lazy(true, name, async move |path| {
let main_const = lazy(true, &format!("__macro__{name}"), async move |path| {
let module = (Sym::new(path.split_last_seg().1.iter().cloned(), &i()).await)
.expect("Default macro in global root");
MemKind::Const(
@@ -120,8 +120,8 @@ impl MacroBuilder {
h.emit(Rule {
matcher: Matcher::new(pattern.clone()).await.unwrap(),
pattern,
placeholders,
body_name: i().i(&format!("({name})::{counter}")).await,
ph_names: placeholders,
body: i().i(&format!("({name})::{counter}")).await,
})
.await;
}
@@ -134,9 +134,9 @@ impl MacroBuilder {
)
});
let kw_consts = own_kws[1..].iter().flat_map(|kw| {
lazy(true, kw, async |path| {
lazy(true, &format!("__macro__{kw}"), async move |path| {
let main_const_name = VPath::new(path.split_last_seg().1.iter().cloned())
.name_with_suffix(i().i(name).await)
.name_with_suffix(i().i(&format!("__macro__{name}")).await)
.to_sym(&i())
.await;
MemKind::Const(sym_ref(main_const_name))