-
Notifications
You must be signed in to change notification settings - Fork 56
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
Basic macro support #752
Comments
I'm not planning on doing this, but it would be cool. It would be pure Diplomat AST code, and would not affect the HIR or backends. |
I found myself wanting something like this when I was redoing ICU4X's constructors over FFI, which follow a pattern. That would be cleaner with a single macro invocation on every formatter type that generates the compiled and buffer ctors. It would also probably be useful in unicode-org/icu4x#5940 in case we decide to make a ton of formatter types. |
Seconding that this would be cool. I love Rust's macro system and I think it'd be great to bring any small part of that to Diplomat |
It'd require some rearchitecture, but you could add full macro support by making the |
Yeah, part of the goal here is that |
Would adding support for |
There are two things that seem brittle with that:
So, worth a shot, but I'm wary it'll be brittle. I'd also not use the builtin macros for this, I'd just make a fake |
For the purposes of cleanly writing code, it would be nice if the AST parser supported using macros. These could expand to types or methods, and would not support nested interpolation.
We'd only support:
This type of thing is relatively straightforward to parse and interpolate.
These macro definitions would be tagged with
diplomat::macro
and used in the source code.The main challenge is that the Diplomat macro would only be able to see macros defined in the same bridge module they are used in. In theory we could apply a
#[diplomat::macro_load = src/macros.rs]
attribute, and have a global cache ofmacro_load
paths to named Diplomat macros to avoid reparsing each time. It's not pretty, but it would work. We'd have to (at runtime) readCARGO_MANIFEST_DIR
.The text was updated successfully, but these errors were encountered: