Hello, thank you for this project!
I found that this example fails:
/// main.rs
use macro_rules_rt::{Matcher, Rule, Transcriber};
/// Demonstrates that `macro_rules_rt` 0.1.1 rejects a transcriber where a
/// non-repeating metavariable (`$m`) is referenced inside a `$(...)*` block.
///
/// The equivalent `macro_rules!` is valid Rust and expands correctly — only
/// the runtime expansion library rejects it.
fn main() {
// ── Case 1: OK — only repeating `$cls` inside $(...)* ──────────────
let m1: Matcher = "register!($($cls:ty),*)".parse().expect("parse m1");
let t1: Transcriber = "$(add_class::<$cls>()?;)*".parse().expect("parse t1");
match Rule::new(m1, t1) {
Ok(rule) => {
let result = rule.apply("register!(a, b, c)").expect("apply case 1");
println!("Case 1 (OK): apply result: {result}");
}
Err(e) => eprintln!("Case 1 (FAIL): unexpected error: {e}"),
}
// ── Case 2: FAIL — non-repeating `$m` inside $(...)* ──────────────
let m2: Matcher = "register!($m:expr, $($cls:ty),*)".parse().expect("parse m2");
let t2: Transcriber = "$($m.add_class::<$cls>()?;)*".parse().expect("parse t2");
match Rule::new(m2, t2) {
Ok(rule) => {
let result = rule.apply("register!(obj, a, b, c)").expect("apply case 2");
println!("Case 2 (OK): apply result: {result}");
}
Err(e) => eprintln!("Case 2 (FAIL): {e}"),
}
// ── Equivalent standard macro_rules! (works fine) ─────────────────
//
// macro_rules! register {
// ($m:expr, $($cls:ty),*) => {
// $($m.add_class::<$cls>()?;)*
// };
// }
//
// This is valid Rust. `cargo expand` confirms it expands as expected.
}
# Cargo.toml
[package]
name = "macro_rules_rt_issue"
version = "0.1.0"
edition = "2024"
[workspace]
[dependencies]
macro-rules-rt = "0.1"
# macro-rules-rt = { path = "../macro-rules-rt" }
case 2 is expected to be parsed successfully, but it failed with message "attempted to repeat an expression containing no syntax variables matched as repeating at this depth“
Hello, thank you for this project!
I found that this example fails:
case 2 is expected to be parsed successfully, but it failed with message "attempted to repeat an expression containing no syntax variables matched as repeating at this depth“