| Crates.io | identity-macro |
| lib.rs | identity-macro |
| version | 0.1.0 |
| created_at | 2025-05-24 00:36:38.321303+00 |
| updated_at | 2025-05-24 00:36:38.321303+00 |
| description | Remove metavariable fragment to make it reusable for macro_rules |
| homepage | |
| repository | https://github.com/A4-Tacks/identity-macro-rs |
| max_upload_size | |
| id | 1686880 |
| size | 5,141 |
Remove metavariable fragment to make it reusable for macro_rules
Resetting span of Group will subtly forget that Group comes from metavariable
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