rstest_bdd_patterns/lib.rs
1//! Shared step-pattern parsing utilities for rstest-bdd.
2//!
3//! The crate exposes placeholder parsing helpers reused by both the runtime
4//! and proc-macro crates so they can share validation logic without duplicating
5//! the regex construction code paths.
6
7mod capture;
8mod errors;
9mod hint;
10mod keyword;
11pub mod pattern;
12mod specificity;
13
14pub use capture::extract_captured_values;
15pub use errors::{PatternError, PlaceholderErrorInfo};
16pub use hint::{get_type_pattern, requires_quote_stripping};
17pub use keyword::{StepKeyword, StepKeywordParseError, UnsupportedStepType};
18pub use pattern::build_regex_from_pattern;
19pub use specificity::SpecificityScore;
20
21/// Build and compile a `Regex` from a step pattern.
22///
23/// # Errors
24/// Returns [`PatternError`] if the pattern translation or regex compilation fails.
25///
26/// # Examples
27/// ```
28/// use rstest_bdd_patterns::compile_regex_from_pattern;
29/// let regex = compile_regex_from_pattern("Given {n:u32}").unwrap();
30/// assert!(regex.is_match("Given 42"));
31/// ```
32pub fn compile_regex_from_pattern(pat: &str) -> Result<regex::Regex, PatternError> {
33 let src = build_regex_from_pattern(pat)?;
34 regex::Regex::new(&src).map_err(PatternError::from)
35}