pub struct RegexOptions { /* private fields */ }Expand description
Regular expression parsing options.
§Examples
Initializing a regex with the “ignore whitespace” flag enabled:
use compile_regex::{ast::{Node, Syntax}, RegexOptions};
const SYNTAX: Syntax = RegexOptions::DEFAULT
.ignore_whitespace(true)
.parse(r"(?<digits> # This is a comment
[ \d - ]+ # since `-` is a last non-whitespace char in a set,
# it's a literal '-'
)");
let comment_count = SYNTAX
.iter()
.filter(|spanned| matches!(spanned.node, Node::Comment))
.count();
// Sequential comments are glued together, so the number of comment nodes is 2
// rather than 3.
assert_eq!(comment_count, 2);Implementations§
Source§impl RegexOptions
impl RegexOptions
Sourcepub const fn ignore_whitespace(self, yes: bool) -> Self
pub const fn ignore_whitespace(self, yes: bool) -> Self
Sets whether whitespace should be ignored when parsing. This is equivalent to setting (?x) flag
at the start of the regex.
Sourcepub const fn try_validate(&self, regex: &str) -> Result<ValidationOutput, Error>
pub const fn try_validate(&self, regex: &str) -> Result<ValidationOutput, Error>
Tries to validate the provided regular expression.
§Errors
Returns an error if the provided regex is not a valid regular expression.
Sourcepub const fn validate(&self, regex: &str) -> ValidationOutput
pub const fn validate(&self, regex: &str) -> ValidationOutput
Validates the provided regular expression, panicking on errors. This is a shortcut for
Self::try_validate().unwrap().
§Panics
Panics if the provided regex is not a valid regular expression.
Sourcepub const fn try_parse<const CAP: usize>(
&self,
regex: &str,
) -> Result<Syntax<CAP>, Error>
pub const fn try_parse<const CAP: usize>( &self, regex: &str, ) -> Result<Syntax<CAP>, Error>
Tries to parse the provided regular expression.
The CAP constant specifies the capacity of the produced Syntax. If it is exceeded,
the method will return AstOverflow. Use the parse! macro
to determine the capacity automatically.
§Errors
- Returns an error if the provided
regexis not a valid regular expression. - Errors if one of internal limits is hit (e.g., the number of syntax spans or the number of named captures).
Sourcepub const fn parse<const CAP: usize>(&self, regex: &str) -> Syntax<CAP>
pub const fn parse<const CAP: usize>(&self, regex: &str) -> Syntax<CAP>
Parses the provided regular expression, panicking on errors. This is a shortcut for
Self::try_parse().unwrap().
§Panics
Panics in the same situations in which Self::try_parse() returns an error.