pomsky/lib.rs
1//! # Pomsky
2//!
3//! To learn about the _pomsky language_, please read [the book][book].
4//!
5//! The _pomsky macro_ can be [found here][macro].
6//!
7//! ## Usage
8//!
9//! This library can parse a pomsky expression and generate a regex string:
10//!
11//! ```
12//! use pomsky::Expr;
13//! use pomsky::options::{CompileOptions, RegexFlavor};
14//!
15//! let options = CompileOptions { flavor: RegexFlavor::Java, ..Default::default() };
16//! let regex = match Expr::parse_and_compile("'test'", options) {
17//! (Some(regex), _warnings, _tests) => regex,
18//! (None, diagnostics, _tests) => {
19//! eprintln!("The input is not a valid pomsky expression");
20//! return;
21//! }
22//! };
23//! ```
24//!
25//! You can get fancy error messages with [miette] by enabling the `diagnostics`
26//! feature:
27//!
28//! ```
29//! use pomsky::Expr;
30//! use pomsky::options::{CompileOptions, RegexFlavor};
31//! use pomsky::diagnose::Diagnostic;
32//!
33//! pub fn compile(input: &str) -> miette::Result<String> {
34//! let options = CompileOptions { flavor: RegexFlavor::Java, ..Default::default() };
35//! let compiled = match Expr::parse_and_compile(input, options) {
36//! (Some(regex), _warnings, _tests) => regex,
37//! (None, diagnostics, _tests) => {
38//! for diagnostic in diagnostics {
39//! eprintln!("{diagnostic}");
40//! }
41//! miette::bail!("Failed to compile pomsky expression");
42//! }
43//! };
44//! Ok(compiled)
45//! }
46//! ```
47//!
48//! [book]: https://pomsky-lang.org/docs/
49//! [macro]: https://docs.rs/pomsky-macro/latest/pomsky_macro/
50//! [miette]: https://docs.rs/miette/latest/miette/
51
52#![warn(missing_docs)]
53
54#[macro_use]
55mod defer;
56
57pub mod diagnose;
58pub mod error;
59pub mod features;
60pub mod options;
61
62mod capturing_groups;
63mod compile;
64mod exprs;
65mod regex;
66mod unicode_set;
67mod validation;
68mod visitor;
69
70/// Re-exports syntax node types related to tests
71pub mod test {
72 pub use pomsky_syntax::exprs::test::*;
73}
74
75pub use exprs::Expr;
76pub use pomsky_syntax::{
77 Span,
78 diagnose::{ParseError, ParseWarning as Warning},
79};
80
81pub use pomsky_syntax::list_shorthands;