Crate rulex

Source
Expand description

§rulex

⚠️ DEPRECATED ⚠️ Use the pomsky crate instead. Rulex was renamed to pomsky.

To learn about the 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 };
let regex: String = match Rulex::parse_and_compile("'test'", Default::default(), 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 };
    let compiled: String = Rulex::parse_and_compile(input, Default::default(), options)
        .map_err(|e| e.diagnostic(input))?;
    Ok(compiled)
}

Modules§

error
Contains different kinds of errors emitted by rulex.
features
Contains rulex features that can be individually enabled and disabled.
options
Contains parser and compiler options passed to rulex.

Structs§

RulexDeprecated
A parsed rulex expression, which might contain more sub-expressions.