macrottutils

Procedural Macro Utilities (tt_ident, throw_diagnostics, deref_span).

Build Status Mit/Apache licensed crates.io Documentation

// Experimental API

tt_ident

Manipulation of input names in macros, currently only name comparison is possible.

```rust

![feature(procmacrohygiene)]

use macrottutils::ttident; use macrottutils::throwcompilewarning; use macrottutils::throwcompile_error;

[macro_export]

macrorules! macrosgenerate { ( fn namechecker($i:ident) -> | $i2:ident | $b:block ) => { throwcompilewarning!(@root "We are testing warning."); ttident! { if ($i == $i2 || $i == "hiddena" || $i2 == "hiddena") { throwcompileerror!(@root "Perhaps undefined behavior"); } } } }

fn main() { macrosgenerate! { fn namechecker(a) -> |a| { ff } } }

/* warning: We are testing warning. --> src/main.rs:21:2 | 21 | macrosgenerate! { | ^ 22 | | fn namechecker(a) -> |a| { 23 | | ff 24 | | } 25 | | } | |^

error: Perhaps undefined behavior --> src/main.rs:21:2 | 21 | macrosgenerate! { | ^ 22 | | fn namechecker(a) -> |a| { 23 | | ff 24 | | } 25 | | } | |^ */ ```

throw_diagnostics

Macros to throw compiler errors or warnings (throw_compile_error, throw_compile_warning, throw_compile_note, throw_compile_help).

```rust

![feature(procmacrohygiene)]

use macrottutils::throwcompilewarning;

[macro_export]

macrorules! macrosgenerate { { fn namechecker($i:ident) -> | $i2:ident | $b:block } => { throwcompilewarning!("#1 We are testing warning."); throwcompile_warning!(@root "#2 We are testing warning."); } }

fn main() { macrosgenerate! { fn namechecker(a) -> |a| {} } }

/* warning: #1 We are testing warning. --> src/main.rs:8:3 | 8 | throwcompilewarning!("#1 We are testing warning."); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ... 14 | macrosgenerate! { | - 15 | | fn namechecker(a) -> |a| {} 16 | | } | |- in this macro invocation

warning: #2 We are testing warning. --> src/main.rs:14:2 | 14 | macrosgenerate! { | ^ 15 | | fn namechecker(a) -> |a| {} 16 | | } | |^

*/ ```

deref_span

Unpacks the current span.

```rust

![feature(procmacrohygiene)]

use macrottutils::deref_span;

[macro_export]

macrorules! macrosgenerate { { fn namechecker($i:ident) -> | $i2:ident | $b:block } => { compileerror!("#1 Test");

    deref_span! {
        compile_error!("#2 Test");
    }
}

}

fn main() { macrosgenerate! { fn namechecker(a) -> |a| {} } }

/* error: #1 Test --> src/main.rs:8:3 | 8 | compileerror!("#1 Test"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ ... 17 | macrosgenerate! { | - 18 | | fn namechecker(a) -> |a| {} 19 | | } | |_- in this macro invocation

error: #2 Test --> src/main.rs:17:2 | 17 | macrosgenerate! { | ^ 18 | | fn namechecker(a) -> |a| {} 19 | | } | |^

error: aborting due to 2 previous errors */ ```

License

Copyright 2019 #UlinProject (Denis Kotlyarov) Денис Котляров

Licensed under the MIT License

Licensed under the Apache License, Version 2.0