rulex
To learn about the rulex language, please read the book.
The rulex macro can be found here.
Usage
This library can parse a rulex expression and generate a regex string:
use rulex::Rulex;
use rulex::options::{CompileOptions, RegexFlavor};
let options = CompileOptions { flavor: RegexFlavor::Java, ..Default::default() };
let regex: String = match Rulex::parse_and_compile("'test'", options) {
Ok(regex) => regex,
Err(_) => {
eprintln!("The input is not a valid rulex");
return;
}
};
You can get fancy error messages with miette
by enabling the diagnostics feature:
use rulex::Rulex;
use rulex::options::{CompileOptions, RegexFlavor};
use rulex::error::Diagnostic;
pub fn compile(input: &str) -> miette::Result<String> {
let options = CompileOptions { flavor: RegexFlavor::Java, ..Default::default() };
let compiled: String = Rulex::parse_and_compile(input, options)
.map_err(|e| e.diagnostic(input))?;
Ok(compiled)
}