Crate pomsky

Source
Expand description

§Pomsky

To learn about the pomsky language, please read the book.

The pomsky macro can be found here.

§Usage

This library can parse a pomsky expression and generate a regex string:

use pomsky::Expr;
use pomsky::options::{CompileOptions, RegexFlavor};

let options = CompileOptions { flavor: RegexFlavor::Java, ..Default::default() };
let regex = match Expr::parse_and_compile("'test'", options) {
    (Some(regex), _warnings, _tests) => regex,
    (None, diagnostics, _tests) => {
        eprintln!("The input is not a valid pomsky expression");
        return;
    }
};

You can get fancy error messages with miette by enabling the diagnostics feature:

use pomsky::Expr;
use pomsky::options::{CompileOptions, RegexFlavor};
use pomsky::diagnose::Diagnostic;

pub fn compile(input: &str) -> miette::Result<String> {
    let options = CompileOptions { flavor: RegexFlavor::Java, ..Default::default() };
    let compiled = match Expr::parse_and_compile(input, options) {
        (Some(regex), _warnings, _tests) => regex,
        (None, diagnostics, _tests) => {
            for diagnostic in diagnostics {
                eprintln!("{diagnostic}");
            }
            miette::bail!("Failed to compile pomsky expression");
        }
    };
    Ok(compiled)
}

Modules§

diagnose
Crate containing diagnostics, i.e. errors and warnings
error
Contains different kinds of errors emitted by Pomsky.
features
Contains pomsky features that can be individually enabled and disabled.
options
Contains parser and compiler options passed to pomsky.
test
Re-exports syntax node types related to tests

Structs§

Expr
A parsed pomsky expression, which might contain more sub-expressions.
ParseError
An error than can occur only during parsing
Span
A source code location, marked by the start and end byte offset. If both are zero, this is considered as “empty” or “missing”, and Span::range returns None.
Warning
A warning.

Functions§

list_shorthands
Returns the list of all accepted shorthands.