-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove need for use_attr
and use_proc
#5
Conversation
This is amazing, didn't think this would be possible without a stack of macros calling each other. I will have to go over carefully to understand how you got around that! |
for context, |
I am also OK with changing / breaking the original signature of |
So yeah if you can get the |
core/src/lib.rs
Outdated
let tokens_forwarded_keyword = keywords::__private_macro_magic_tokens_forwarded::default(); | ||
let pound = Punct::new('#', Spacing::Alone); | ||
match parsed.extra { | ||
// no extra, used by attr, so expand to attribute macro |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sam0x17 what I wrote here looks a bit abusive to me, but as long as we use the extra token stuff only for attribute macros we are good.
but maybe it should be refactored together with extra token feature.
otherwise we could have forward_tokens_to_attribute_macro
and forward_tokens_to_proc_macro
.
the implementation would redirect to forward_tokens_inner(attr: true, ...)
and forward_tokens_inner(attr: false, ...)
. and then same for forward_tokens_internal
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah also if I remember correctly the main blocker to having a more general thing like a tt
here is anything but an ident
or a literal limits what types of position you can use forward_tokens stuff with because of how decl macros work. This is the same reason I have to do that crazy manual interpolation of idents with :: instead of just a path in the export tokens macro. Extra as a string works in all positions.
Maybe a tuple like this would be better though:
("extra item 1", "extra item 2", "extra item 3", "extra item 4")
I don't think that would mess up the position capabilities at all, and at least then we wouldn't have to do string interpolation and escaping
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But yes I think it is fine to expand to a proc macro here, and I'd be happy to merge it this way
yes formatted, I only have the little concern above #5 (comment) but the PR is ready. I will attend buidl asia, I won't work on the other points soon I think |
OK I will see if I can get the other parts working and update the docs 👍🏻 |
implements first part of #3
what it does:
import_tokens
macros call themself instead of calling their relatedinner_sig
forward_tokens_inner_internal
will add a keyword at the start of the token stream.if
import_tokens
see the keyword at the start of the token stream then it call theirinner_sig
which is declared inlined.tests are successful
TODO:
forward_token
which doesn't add this extra token in order not to break usage offorward_token
extra
is equivalent to having been called by an attribute macro, or should we pass along this information in another way.