1fad3a1d3Sopenharmony_ciAn example of parsing a custom syntax within a `functionlike!(...)` procedural
2fad3a1d3Sopenharmony_cimacro. Demonstrates how to trigger custom warnings and error messages on
3fad3a1d3Sopenharmony_ciindividual tokens of the input.
4fad3a1d3Sopenharmony_ci
5fad3a1d3Sopenharmony_ci- [`lazy-static/src/lib.rs`](lazy-static/src/lib.rs)
6fad3a1d3Sopenharmony_ci- [`example/src/main.rs`](example/src/main.rs)
7fad3a1d3Sopenharmony_ci
8fad3a1d3Sopenharmony_ciThe library implements a `lazy_static!` macro similar to the one from the real
9fad3a1d3Sopenharmony_ci[`lazy_static`](https://docs.rs/lazy_static/1.0/lazy_static/) crate on
10fad3a1d3Sopenharmony_cicrates.io.
11fad3a1d3Sopenharmony_ci
12fad3a1d3Sopenharmony_ci```rust
13fad3a1d3Sopenharmony_cilazy_static! {
14fad3a1d3Sopenharmony_ci    static ref USERNAME: Regex = Regex::new("^[a-z0-9_-]{3,16}$").unwrap();
15fad3a1d3Sopenharmony_ci}
16fad3a1d3Sopenharmony_ci```
17fad3a1d3Sopenharmony_ci
18fad3a1d3Sopenharmony_ciCompile and run the example by doing `cargo run` in the directory of the
19fad3a1d3Sopenharmony_ci`example` crate.
20fad3a1d3Sopenharmony_ci
21fad3a1d3Sopenharmony_ciThe implementation shows how to trigger custom warnings and error messages on
22fad3a1d3Sopenharmony_cithe macro input. For example if you try adding an uncreatively named `FOO` lazy
23fad3a1d3Sopenharmony_cistatic, the macro will scold you with the following warning.
24fad3a1d3Sopenharmony_ci
25fad3a1d3Sopenharmony_ci```
26fad3a1d3Sopenharmony_ciwarning: come on, pick a more creative name
27fad3a1d3Sopenharmony_ci  --> src/main.rs:10:16
28fad3a1d3Sopenharmony_ci   |
29fad3a1d3Sopenharmony_ci10 |     static ref FOO: String = "lazy_static".to_owned();
30fad3a1d3Sopenharmony_ci   |                ^^^
31fad3a1d3Sopenharmony_ci```
32fad3a1d3Sopenharmony_ci
33fad3a1d3Sopenharmony_ciAnd if you try to lazily initialize `() = ()`, the macro will outright refuse to
34fad3a1d3Sopenharmony_cicompile it for you.
35fad3a1d3Sopenharmony_ci
36fad3a1d3Sopenharmony_ci```
37fad3a1d3Sopenharmony_cierror: I can't think of a legitimate use for lazily initializing the value `()`
38fad3a1d3Sopenharmony_ci  --> src/main.rs:10:27
39fad3a1d3Sopenharmony_ci   |
40fad3a1d3Sopenharmony_ci10 |     static ref UNIT: () = ();
41fad3a1d3Sopenharmony_ci   |                           ^^
42fad3a1d3Sopenharmony_ci```
43