rust_regex_dsl_creator/
lib.rs

1//! This crate can be used to create a regular expression DSL (see [here](https://crates.io/crates/rust-regex-dsl)).
2//! To use it, run something like:
3//! ```rust
4//! use rust_regex_dsl_creator::ToDsl;
5//!
6//! let dsl = "[a-z]+".to_dsl().unwrap();
7//! assert_eq!(dsl, "repeat {\n  any_of {\n    from: 'a', to: 'z',\n  },\n}\n")
8//! ```
9
10mod ast_impl;
11mod basic_impls;
12mod printer;
13
14/// Import this trait to enable the `to_dsl` function for anything that implements the [ToString] trait.
15pub trait ToDsl {
16    /// This function (implemented by default for anything that implement the [ToString] trait) convert a regular expression to a DSL
17    /// that can be used by the [regex_dsl](https://docs.rs/rust-regex-dsl/latest/rust_regex_dsl/macro.regex_dsl.html)
18    /// or [create_capture](https://docs.rs/rust-regex-dsl/latest/rust_regex_dsl/macro.create_capture.html) macros.
19    /// For example:
20    /// ```rust
21    /// use rust_regex_dsl_creator::ToDsl;
22    ///
23    /// let dsl = "[a-z]+[0-9]{2,3}$".to_dsl().unwrap();
24    /// assert_eq!(dsl, "concat {\n  repeat {\n    any_of {\n      from: 'a', to: 'z',\n    },\n  },\n  times {\n    at_least: 2, at_most: 3,\n    any_of {\n      from: '0', to: '9',\n    },\n  },\n  end_of_line,\n}\n")
25    /// ```
26    fn to_dsl(&self) -> Result<String, regex::Error>;
27}