Expand description
Remove metavariable fragment to make it reusable for macro_rules
Resetting span of Group will subtly forget that Group comes from metavariable
§Example
Compile failed case:
ⓘ
macro_rules! foo {
(1+2) => {};
}
macro_rules! bar {
($e:expr) => {
foo!($e)
};
}
bar!(1+2);Use identity macro:
use identity_macro::identity;
macro_rules! foo {
(1+2) => {};
}
macro_rules! bar {
($e:expr) => {
identity!(foo!($e))
};
}
bar!(1+2);After matching with objects like $e:expr,
the content will be wrapped in a Group(Delimiter::None),
and marked with fragments using span related methods to prevent it from being matched by different fragments
This crate utilizes the fragment information lost when setting the span to enable it to be re matched
NOTE:
macro_rules will automatically flatten Group(Delimiter::None) without fragments,
so there is no need to manually unpack them,
but it is also not possible to use tt to pass the entire Group
Macros§
- identity
- Remove metavariable fragment to make it reusable for
macro_rules - identity_
inner - Like
identity, But only handle the content inside#identity(...)