Struct ParserBuilder
struct ParserBuilder { ... }
A builder for a regular expression parser.
This builder permits modifying configuration options for the parser.
Implementations
impl ParserBuilder
fn new() -> ParserBuilderCreate a new parser builder with a default configuration.
fn build(self: &Self) -> ParserBuild a parser from this configuration with the given pattern.
fn nest_limit(self: &mut Self, limit: u32) -> &mut ParserBuilderSet the nesting limit for this parser.
The nesting limit controls how deep the abstract syntax tree is allowed to be. If the AST exceeds the given limit (e.g., with too many nested groups), then an error is returned by the parser.
The purpose of this limit is to act as a heuristic to prevent stack overflow for consumers that do structural induction on an
Astusing explicit recursion. While this crate never does this (instead using constant stack space and moving the call stack to the heap), other crates may.This limit is not checked until the entire AST is parsed. Therefore, if callers want to put a limit on the amount of heap space used, then they should impose a limit on the length, in bytes, of the concrete pattern string. In particular, this is viable since this parser implementation will limit itself to heap space proportional to the length of the pattern string.
Note that a nest limit of
0will return a nest limit error for most patterns but not all. For example, a nest limit of0permitsabut notab, sinceabrequires a concatenation, which results in a nest depth of1. In general, a nest limit is not something that manifests in an obvious way in the concrete syntax, therefore, it should not be used in a granular way.fn octal(self: &mut Self, yes: bool) -> &mut ParserBuilderWhether to support octal syntax or not.
Octal syntax is a little-known way of uttering Unicode codepoints in a regular expression. For example,
a,\x61,\u0061and\141are all equivalent regular expressions, where the last example shows octal syntax.While supporting octal syntax isn't in and of itself a problem, it does make good error messages harder. That is, in PCRE based regex engines, syntax like
\0invokes a backreference, which is explicitly unsupported in Rust's regex engine. However, many users expect it to be supported. Therefore, when octal support is disabled, the error message will explicitly mention that backreferences aren't supported.Octal syntax is disabled by default.
fn ignore_whitespace(self: &mut Self, yes: bool) -> &mut ParserBuilderEnable verbose mode in the regular expression.
When enabled, verbose mode permits insignificant whitespace in many places in the regular expression, as well as comments. Comments are started using
#and continue until the end of the line.By default, this is disabled. It may be selectively enabled in the regular expression by using the
xflag regardless of this setting.fn empty_min_range(self: &mut Self, yes: bool) -> &mut ParserBuilderAllow using
{,n}as an equivalent to{0,n}.When enabled, the parser accepts
{,n}as valid syntax for{0,n}. Most regular expression engines don't support the{,n}syntax, but some others do it, namely Python'srelibrary.This is disabled by default.
impl Clone for ParserBuilder
fn clone(self: &Self) -> ParserBuilder
impl Debug for ParserBuilder
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl Default for ParserBuilder
fn default() -> ParserBuilder
impl Freeze for ParserBuilder
impl RefUnwindSafe for ParserBuilder
impl Send for ParserBuilder
impl Sync for ParserBuilder
impl Unpin for ParserBuilder
impl UnsafeUnpin for ParserBuilder
impl UnwindSafe for ParserBuilder
impl<T> Any for ParserBuilder
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for ParserBuilder
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for ParserBuilder
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for ParserBuilder
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> From for ParserBuilder
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for ParserBuilder
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T, U> Into for ParserBuilder
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for ParserBuilder
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for ParserBuilder
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>