pomsky!() { /* proc-macro */ }Expand description
Macro to compile a pomsky expression at compile time.
§Example
use pomsky_macro::pomsky;
const REGEX: &str = pomsky! {
let number = '-'? [digit]+;
let op = ["+-*/"];
number (op number)*
};NOTE: Code points (e.g. U+FFEF) should be written without the +
(i.e., UFFEF), because rustfmt surrounds + with spaces by default, which
would break parsing.
The regex flavor defaults to Rust, so it can be used with the regex
crate:
use regex::Regex;
fn get_regex() -> Regex {
Regex::new(pomsky! { "hello world" }).unwrap()
}If you want to use a different flavor, you can specify it in the first line, like so:
pomsky! {
#flavor = Pcre
// your pomsky expression goes here
}Available flavors are
- DotNet (C#, F#)
- Java
- JavaScript (ECMAScript, Dart)
- Pcre (Crystal, Delphi, Elixir, Erlang, Hack, Julia, PHP, R, Vala, …)
- Python (
remodule) - Ruby
- Rust (
regexcrate)