pub struct Builder<'a, 'f1, S: State = Empty> { /* private fields */ }
regex-automata
and regex-lita
only.Expand description
Use builder syntax to set the inputs and finish with build_from_hir()
.
Implementations§
Source§impl<'a, 'f1, S: State> Builder<'a, 'f1, S>
impl<'a, 'f1, S: State> Builder<'a, 'f1, S>
Sourcepub fn build_from_hir(self, hir: Hir) -> Result<Regex<'a>, BuildError>where
S: IsComplete,
pub fn build_from_hir(self, hir: Hir) -> Result<Regex<'a>, BuildError>where
S: IsComplete,
Builds a Regex
directly from an Hir
expression.
This is useful if you needed to parse a pattern string into an Hir
for other reasons (such as analysis or transformations). This routine
permits building a Regex
directly from the Hir
expression instead
of first converting the Hir
back to a pattern string.
When using this method, any options set via Builder::syntax
are
ignored. Namely, the syntax options only apply when parsing a pattern
string, which isn’t relevant here.
If there was a problem building the underlying regex matcher for the
given Hir
, then an error is returned.
§Example
This example shows how one can hand-construct an Hir
expression and
build a regex from it without doing any parsing at all.
use ib_matcher::{
regex::{lita::Regex, Match},
syntax::regex::hir::{Hir, Look},
};
// (?Rm)^foo$
let hir = Hir::concat(vec![
Hir::look(Look::StartCRLF),
Hir::literal("foo".as_bytes()),
Hir::look(Look::EndCRLF),
]);
let re = Regex::builder()
.build_from_hir(hir)?;
let hay = "\r\nfoo\r\n";
assert_eq!(Some(Match::must(0, 2..5)), re.find(hay));
Ok::<(), Box<dyn std::error::Error>>(())
Sourcepub fn hir_ascii(self, value: (Hir, bool)) -> Builder<'a, 'f1, SetHirAscii<S>>where
S::HirAscii: IsUnset,
pub fn hir_ascii(self, value: (Hir, bool)) -> Builder<'a, 'f1, SetHirAscii<S>>where
S::HirAscii: IsUnset,
Optional (Some / Option setters).
If the provided hir
is Unicode-aware, providing a ASCII-aware-only Hir
as hir_ascii
can improve performance.
The second bool
is whether the provided hir_ascii
is case insensitive:
- If it’s
false
butib.case_insensitive
istrue
, thenhir_ascii
will be converted to case insensitive. (Used by glob) - If it’s
true
butib.case_insensitive
isfalse
,build()
will panic.
Sourcepub fn maybe_hir_ascii(
self,
value: Option<(Hir, bool)>,
) -> Builder<'a, 'f1, SetHirAscii<S>>where
S::HirAscii: IsUnset,
pub fn maybe_hir_ascii(
self,
value: Option<(Hir, bool)>,
) -> Builder<'a, 'f1, SetHirAscii<S>>where
S::HirAscii: IsUnset,
Optional (Some / Option setters).
If the provided hir
is Unicode-aware, providing a ASCII-aware-only Hir
as hir_ascii
can improve performance.
The second bool
is whether the provided hir_ascii
is case insensitive:
- If it’s
false
butib.case_insensitive
istrue
, thenhir_ascii
will be converted to case insensitive. (Used by glob) - If it’s
true
butib.case_insensitive
isfalse
,build()
will panic.
Sourcepub fn dfa_dense(self, value: Config) -> Builder<'a, 'f1, SetDfaDense<S>>where
S::DfaDense: IsUnset,
pub fn dfa_dense(self, value: Config) -> Builder<'a, 'f1, SetDfaDense<S>>where
S::DfaDense: IsUnset,
Sourcepub fn maybe_dfa_dense(
self,
value: Option<Config>,
) -> Builder<'a, 'f1, SetDfaDense<S>>where
S::DfaDense: IsUnset,
pub fn maybe_dfa_dense(
self,
value: Option<Config>,
) -> Builder<'a, 'f1, SetDfaDense<S>>where
S::DfaDense: IsUnset,
Sourcepub fn thompson(self, value: Config) -> Builder<'a, 'f1, SetThompson<S>>where
S::Thompson: IsUnset,
pub fn thompson(self, value: Config) -> Builder<'a, 'f1, SetThompson<S>>where
S::Thompson: IsUnset,
Optional (Some / Option setters). Default: <thompson::Config as Default>::default()
.
Thompson NFA config. Named configure
to be compatible with regex_automata::meta::Builder
. Although some fields are not supported and utf8_empty
is named as utf8
instead.
Sourcepub fn maybe_thompson(
self,
value: Option<Config>,
) -> Builder<'a, 'f1, SetThompson<S>>where
S::Thompson: IsUnset,
pub fn maybe_thompson(
self,
value: Option<Config>,
) -> Builder<'a, 'f1, SetThompson<S>>where
S::Thompson: IsUnset,
Optional (Some / Option setters). Default: <thompson::Config as Default>::default()
.
Thompson NFA config. Named configure
to be compatible with regex_automata::meta::Builder
. Although some fields are not supported and utf8_empty
is named as utf8
instead.
Sourcepub fn ib(self, value: MatchConfig<'a>) -> Builder<'a, 'f1, SetIb<S>>where
S::Ib: IsUnset,
pub fn ib(self, value: MatchConfig<'a>) -> Builder<'a, 'f1, SetIb<S>>where
S::Ib: IsUnset,
Sourcepub fn maybe_ib(
self,
value: Option<MatchConfig<'a>>,
) -> Builder<'a, 'f1, SetIb<S>>where
S::Ib: IsUnset,
pub fn maybe_ib(
self,
value: Option<MatchConfig<'a>>,
) -> Builder<'a, 'f1, SetIb<S>>where
S::Ib: IsUnset,
Sourcepub fn ib_parser(
self,
value: &'f1 mut dyn FnMut(&str) -> Pattern<'_, str>,
) -> Builder<'a, 'f1, SetIbParser<S>>where
S::IbParser: IsUnset,
pub fn ib_parser(
self,
value: &'f1 mut dyn FnMut(&str) -> Pattern<'_, str>,
) -> Builder<'a, 'f1, SetIbParser<S>>where
S::IbParser: IsUnset,
Optional (Some / Option setters).
IbMatcher
pattern parser.
§Example
use ib_matcher::{regex::lita::Regex, matcher::{MatchConfig, pattern::Pattern}};
let re = Regex::builder()
.ib(MatchConfig::builder().pinyin(Default::default()).build())
.ib_parser(&mut |pattern| Pattern::parse_ev(pattern).call())
.build("pinyin;py")
.unwrap();
assert!(re.is_match("拼音搜索"));
assert!(re.is_match("pinyin") == false);
See crate::syntax::ev
for more details.
Sourcepub fn maybe_ib_parser(
self,
value: Option<&'f1 mut dyn FnMut(&str) -> Pattern<'_, str>>,
) -> Builder<'a, 'f1, SetIbParser<S>>where
S::IbParser: IsUnset,
pub fn maybe_ib_parser(
self,
value: Option<&'f1 mut dyn FnMut(&str) -> Pattern<'_, str>>,
) -> Builder<'a, 'f1, SetIbParser<S>>where
S::IbParser: IsUnset,
Optional (Some / Option setters).
IbMatcher
pattern parser.
§Example
use ib_matcher::{regex::lita::Regex, matcher::{MatchConfig, pattern::Pattern}};
let re = Regex::builder()
.ib(MatchConfig::builder().pinyin(Default::default()).build())
.ib_parser(&mut |pattern| Pattern::parse_ev(pattern).call())
.build("pinyin;py")
.unwrap();
assert!(re.is_match("拼音搜索"));
assert!(re.is_match("pinyin") == false);
See crate::syntax::ev
for more details.
Source§impl<'a, S: State> Builder<'a, '_, S>
impl<'a, S: State> Builder<'a, '_, S>
Sourcepub fn syntax(self, syntax: Config) -> Self
pub fn syntax(self, syntax: Config) -> Self
Configure the syntax options when parsing a pattern string while
building a Regex
.
These options only apply when Builder::build
or [Builder::build_many
]
are used. The other build methods accept Hir
values, which have
already been parsed.
§Example
This example shows how to enable case insensitive mode.
use ib_matcher::regex::{lita::Regex, util::syntax, Match};
let re = Regex::builder()
.syntax(syntax::Config::new().case_insensitive(true))
.build(r"δ")?;
assert_eq!(Some(Match::must(0, 0..2)), re.find(r"Δ"));
Ok::<(), Box<dyn std::error::Error>>(())
Sourcepub fn build(self, pattern: &str) -> Result<Regex<'a>, BuildError>where
S::HirAscii: IsUnset,
pub fn build(self, pattern: &str) -> Result<Regex<'a>, BuildError>where
S::HirAscii: IsUnset,
Builds a Regex
from a single pattern string.
If there was a problem parsing the pattern or a problem turning it into a regex matcher, then an error is returned.
§Example
This example shows how to configure syntax options.
use ib_matcher::regex::{lita::Regex, util::syntax, Match};
let re = Regex::builder()
.syntax(syntax::Config::new().crlf(true).multi_line(true))
.build(r"^foo$")?;
let hay = "\r\nfoo\r\n";
assert_eq!(Some(Match::must(0, 2..5)), re.find(hay));
Auto Trait Implementations§
impl<'a, 'f1, S = Empty> !Freeze for Builder<'a, 'f1, S>
impl<'a, 'f1, S = Empty> !RefUnwindSafe for Builder<'a, 'f1, S>
impl<'a, 'f1, S = Empty> !Send for Builder<'a, 'f1, S>
impl<'a, 'f1, S = Empty> !Sync for Builder<'a, 'f1, S>
impl<'a, 'f1, S> Unpin for Builder<'a, 'f1, S>
impl<'a, 'f1, S = Empty> !UnwindSafe for Builder<'a, 'f1, S>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more