pub struct PatternBuilder<'s> { /* private fields */ }Expand description
A pattern’s source together with the readings it is to be parsed under.
Implementations§
Source§impl<'s> PatternBuilder<'s>
impl<'s> PatternBuilder<'s>
Sourcepub fn new(src: &'s str) -> Self
pub fn new(src: &'s str) -> Self
A builder over src with every reading at its default, so
PatternBuilder::new(s).build() is crate::parse.
Sourcepub fn as_str(&self) -> &'s str
pub fn as_str(&self) -> &'s str
The pattern text this builder was given.
The nearest thing to the regex crate’s as_str, which exists because a
compiled Regex is opaque: once built, the source is the only window
into what it matches. A Pattern is a public tree the caller can walk
and match on, so the question as_str answers does not arise for one -
and a builder is the only place in this crate that holds the text after
parsing, so it is the only place the accessor belongs.
Sourcepub fn case_insensitive(self, yes: bool) -> Self
pub fn case_insensitive(self, yes: bool) -> Self
Compare every literal in the pattern under case folding, so "Cat"
matches cat and CAT.
A register-equality atom keeps whichever group its own spelling gave
it: =case x is a comparison the author named, and widening it here
would make the pattern mean something other than what was written.
Sourcepub fn orbit(self, group: OrbitGroup) -> Self
pub fn orbit(self, group: OrbitGroup) -> Self
Compare every literal in the pattern under group.
Self::case_insensitive is this with OrbitGroup::Case, and it is
the only rung the regex crate has a name for. The others have no
counterpart there because a regular expression compares bytes and
these are equivalences over tokens:
OrbitGroup::Notationfolds case and notation together, sotheta,\thetaand the Greek letter are one token.OrbitGroup::Shapecompares a token’s consonant-vowel-digit shape, so"cat"matchesdogandbat. A whole pattern under this rung is a structural search: find anything shaped like this, whatever it says.OrbitGroup::E8compares the token’s eight-channel profile quotiented by the E8 reflection group, which is the one rung whose equivalence is not a string relation at all.
A register-equality atom keeps whichever group its own spelling gave
it, at every rung: =shape x is a comparison the author named.
Sourcepub fn swap_greed(self, yes: bool) -> Self
pub fn swap_greed(self, yes: bool) -> Self
Swap every quantifier’s preference, so * prefers the shortest match
and *? the longest.
Sourcepub fn nest_limit(self, limit: u32) -> Self
pub fn nest_limit(self, limit: u32) -> Self
Refuse a pattern nesting deeper than limit groups.
Sourcepub fn empty_loop(self, empty: EmptyLoop) -> Self
pub fn empty_loop(self, empty: EmptyLoop) -> Self
Which reading a repetition whose body can match nothing takes.
Sourcepub fn build(self) -> Result<Pattern, ParseError>
pub fn build(self) -> Result<Pattern, ParseError>
The pattern, or the error that says why the source is not one.
§Errors
A malformed pattern, or one nesting deeper than the limit.
Sourcepub fn reading(&self) -> Result<EmptyLoop, ParseError>
pub fn reading(&self) -> Result<EmptyLoop, ParseError>
The empty-loop reading a scan of this pattern should take: the one the
source named with (?empty:...), or the one this builder was given.
The source wins because it is part of the pattern, and a pattern that says how its own empty loops read is making a claim about what it means rather than about how some caller wants it run.
§Errors
A malformed (?empty:...) directive.