Skip to main content

these_macros_should_be_illegal/
lib.rs

1//! Experimental procedural macros for compact local DSLs, recursive token
2//! rewriting, and transformations of macro structure.
3//!
4//! The main entry points are [`enum_fn`] for per-variant methods,
5//! [`discriminated_str`] for reversible string discriminants, [`strutuct`] for
6//! nested algebraic declarations, and [`expand`] for applying recursive syntax
7//! extensions to an out-of-line module. Every macro is independent; import only
8//! the syntax used by the caller.
9//!
10//! ```
11//! # use these_macros_should_be_illegal::enum_fn;
12//!
13//! #[enum_fn(code: usize)]
14//! enum Status {
15//!     Ready = 200,
16//!     Missing,
17//! }
18//!
19//! assert_eq!(Status::Ready.code(), Some(200));
20//! assert_eq!(Status::Missing.code(), None);
21//! ```
22//!
23//! The [crate repository](https://github.com/AlexanderGolys/these-macros-should-be-illegal)
24//! contains the complete book and runnable examples.
25
26use proc_macro::TokenStream;
27
28#[macro_use]
29mod lib_mbe;
30
31macro_cat_mod! { dust
32    //! Whole-stream syntax extensions applied recursively before ordinary parsing.
33    literally_literal_string;
34    shared_match_arms;
35}
36
37attr_macro_cat_mod! { attr
38    //! Attribute macros extending the items they are applied to.
39    callable;
40    discriminated_str;
41    enum_fn;
42    overload_op;
43    complete_ops;
44    excluded_macros;
45    forward_attributes;
46}
47
48macro_cat_mod! { generate
49    //! Generators of compound structures with a fixed layout.
50    strutuct [emmun];
51}
52
53macro_cat_mod! { rast
54    //! Remaining conveniences over ordinary Rust syntax.
55    qf;
56    stringify_as;
57    make_fn;
58}
59
60macro_cat_mod! { meta
61    //! Macros transforming other macros.
62    perm;
63    reflect;
64    expand;
65}
66
67/// Internal plumbing shared by the macro implementations.
68mod helpers {
69    pub mod arguments;
70    pub mod fresh_name;
71    pub mod preprocessing;
72    pub mod ungroup;
73}