Uses old Rust 2015
0.1.0 |
|
---|
#12 in #parse-attributes
Used in 2 crates
34KB
909 lines
prom-attire
Procedural Macro Attributes
For when you need the best dressed procedural macro.
Developing
This project uses clippy and denies warnings in CI builds. To ensure your
changes will be accepted please check them with cargo clippy
(available via
cargo install clippy
on nightly rust) before submitting a pull request (along
with cargo test
as usual).
Both the nightly date and clippy version used in CI are pinned in the
.travis.yml
as clippy sometimes breaks for a few days after a new nightly is
published, feel free to update to a new known good pair anytime as part of a
pull request.
Why Three Crates
Why not three crates?
One issue with current procedural macros is that crates defining procedural
macros can't use their own procedural macros. In this case prom-attire
wants
to have some attributes controlling how it parses the attributes (at the
moment, only the top level "scope" attribute identifier, i.e. the value
attire
in #[attire(scope = shoes)]
), obviously prom-attire
will need to
parse these attributes out to get the details it needs, but the entire point of
prom-attire
is to make parsing attributes pain-free, having a manual parser
in prom-attire
itself mean any upgrades to the parsing code generated by
prom-attire
would probably have to be duplicated in the parsing code inside
prom-attire
itself.
Luckily there is a solution, by using three crates ;-)
The base is prom-attire-impl
, this implements the entirety of the procedural
derive, but does not itself define a procedural derive macro. Instead it
exports a single function taking in the AST provided to a procedural derive and
some configuration and returns the derived implementation.
Next prom-attire-bootstrap
defines a simple procedural derive macro
FromAttributesBootstrap
that calls into prom-attire-impl
with a hardcoded
configuration.
Finally prom-attire
defines a slightly more complicated procedural derive
macro (FromAttributes
) that parses some attributes (using a parser derived
with FromAttributesBootstrap
), then calls into prom-attire-impl
with a
configuration derived from those parsed attributes. This is the "public"
entrypoint to the crates, technically the others could be used but they're
unlikely to be useful.
So, in the end prom-attire
is a crate defining a procedural derive macro, to
help developers write procedural derive macros, that uses a procedural derive
in its implementation (no, that is not inception).
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be dual licensed as above, without any additional terms or conditions.
Dependencies
~4–9.5MB
~110K SLoC