point!(M {
a: "b" + (1, 2, 3, 4) + TopRight,
a: "b" + TopRight,
a: "b",
a: ["b", "c"],
a: M {
a: "b" + (1, 2, 3, 4) + TopRight,
},
});
I am constructing a macro, that accpet above struct where the value is any of
- add-style-expr( <= 3 elements)
- a similar struct
- a similar array
My problem is how to make such a macro.
If I use expr
to extract struct value, the expr can't be accept by the next rule. There seems no way to revert expr to tt.
macro_rules! point {
(M { $($k:ident : $v:expr ),* $(,)? }) => {{
$( point!($v); )*
}};
($x:tt + ($l:expr, $t:expr, $r:expr, $b:expr) + $loc:tt) => {
()
};
}
If I use tt
, the add-style-expr can't be matched. Wrapping all add-style-expr in () works but there are lots of waste typing.
macro_rules! point {
(M { $($k:ident : $v:tt ),* $(,)? }) => {{
$( point!($v); )*
}};
}
If I use tt*
, the comma after add-style-expr is ambiguous.
macro_rules! point {
(M { $($k:ident : $($v:tt)* ),* $(,)? }) => {{
$( point!($v); )*
}};
}
point!(M {
a: "b" + (1, 2, 3, 4) + TopRight, <-- ambiguous
});