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
- Crate containing diagnostics, i.e. errors and warnings
- Contains different kinds of errors emitted by Pomsky.
- Contains pomsky features that can be individually enabled and disabled.
- Contains parser and compiler options passed to pomsky.
- Re-exports syntax node types related to tests
Structs
- A parsed pomsky expression, which might contain more sub-expressions.
- An error than can occur only during parsing
- 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
returnsNone
. - A warning.
Functions
- Returns the list of all accepted shorthands.