Enum Look
pub enum Look
A look-around assertion.
An assertion matches at a position between characters in a haystack. Namely, it does not actually "consume" any input as most parts of a regular expression do. Assertions are a way of stating that some property must be true at a particular point during matching.
For example, (?m)^[a-z]+$ is a pattern that:
- Scans the haystack for a position at which
(?m:^)is satisfied. That occurs at either the beginning of the haystack, or immediately following a\ncharacter. - Looks for one or more occurrences of
[a-z]. - Once
[a-z]+has matched as much as it can, an overall match is only reported when[a-z]+stops just before a\n.
So in this case, abc and \nabc\n match, but \nabc1\n does not.
Assertions are also called "look-around," "look-behind" and "look-ahead."
Specifically, some assertions are look-behind (like ^), other assertions
are look-ahead (like $) and yet other assertions are both look-ahead and
look-behind (like \b).
Assertions in an NFA
An assertion in a thompson::NFA can be
thought of as a conditional epsilon transition. That is, a matching engine
like the PikeVM only permits
moving through conditional epsilon transitions when their condition
is satisfied at whatever position the PikeVM is currently at in the
haystack.
How assertions are handled in a DFA is trickier, since a DFA does not
have epsilon transitions at all. In this case, they are compiled into the
automaton itself, at the expense of more states than what would be required
without an assertion.
Variants
-
Start = { _ } Match the beginning of text. Specifically, this matches at the starting position of the input.
-
End = { _ } Match the end of text. Specifically, this matches at the ending position of the input.
-
StartLF = { _ } Match the beginning of a line or the beginning of text. Specifically, this matches at the starting position of the input, or at the position immediately following a
\ncharacter.-
EndLF = { _ } Match the end of a line or the end of text. Specifically, this matches at the end position of the input, or at the position immediately preceding a
\ncharacter.-
StartCRLF = { _ } Match the beginning of a line or the beginning of text. Specifically, this matches at the starting position of the input, or at the position immediately following either a
\ror\ncharacter, but never after a\rwhen a\nfollows.-
EndCRLF = { _ } Match the end of a line or the end of text. Specifically, this matches at the end position of the input, or at the position immediately preceding a
\ror\ncharacter, but never before a\nwhen a\rprecedes it.-
WordAscii = { _ } Match an ASCII-only word boundary. That is, this matches a position where the left adjacent character and right adjacent character correspond to a word and non-word or a non-word and word character.
-
WordAsciiNegate = { _ } Match an ASCII-only negation of a word boundary.
-
WordUnicode = { _ } Match a Unicode-aware word boundary. That is, this matches a position where the left adjacent character and right adjacent character correspond to a word and non-word or a non-word and word character.
-
WordUnicodeNegate = { _ } Match a Unicode-aware negation of a word boundary.
-
WordStartAscii = { _ } Match the start of an ASCII-only word boundary. That is, this matches a position at either the beginning of the haystack or where the previous character is not a word character and the following character is a word character.
-
WordEndAscii = { _ } Match the end of an ASCII-only word boundary. That is, this matches a position at either the end of the haystack or where the previous character is a word character and the following character is not a word character.
-
WordStartUnicode = { _ } Match the start of a Unicode word boundary. That is, this matches a position at either the beginning of the haystack or where the previous character is not a word character and the following character is a word character.
-
WordEndUnicode = { _ } Match the end of a Unicode word boundary. That is, this matches a position at either the end of the haystack or where the previous character is a word character and the following character is not a word character.
-
WordStartHalfAscii = { _ } Match the start half of an ASCII-only word boundary. That is, this matches a position at either the beginning of the haystack or where the previous character is not a word character.
-
WordEndHalfAscii = { _ } Match the end half of an ASCII-only word boundary. That is, this matches a position at either the end of the haystack or where the following character is not a word character.
-
WordStartHalfUnicode = { _ } Match the start half of a Unicode word boundary. That is, this matches a position at either the beginning of the haystack or where the previous character is not a word character.
-
WordEndHalfUnicode = { _ } Match the end half of a Unicode word boundary. That is, this matches a position at either the end of the haystack or where the following character is not a word character.
Implementations
impl Look
const fn reversed(self) -> LookFlip the look-around assertion to its equivalent for reverse searches. For example,
StartLFgets translated toEndLF.Some assertions, such as
WordUnicode, remain the same since they match the same positions regardless of the direction of the search.const fn as_repr(self) -> u32Return the underlying representation of this look-around enumeration as an integer. Giving the return value to the
Look::from_reprconstructor is guaranteed to return the same look-around variant that one started with within a semver compatible release of this crate.const fn from_repr(repr: u32) -> Option<Look>Given the underlying representation of a
Lookvalue, return the correspondingLookvalue if the representation is valid. OtherwiseNoneis returned.const fn as_char(self) -> charReturns a convenient single codepoint representation of this look-around assertion. Each assertion is guaranteed to be represented by a distinct character.
This is useful for succinctly representing a look-around assertion in human friendly but succinct output intended for a programmer working on regex internals.
Trait Implementations
impl Clone for Look
fn clone(&self) -> Self
impl Copy for Look
impl Debug for Look
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Eq for Look
impl PartialEq for Look
fn eq(&self, other: &Self) -> bool
impl StructuralPartialEq for Look
Auto Trait Implementations
impl Freeze for Look
impl RefUnwindSafe for Look
impl Send for Look
impl Sync for Look
impl Unpin for Look
impl UnsafeUnpin for Look
impl UnwindSafe for Look
Blanket Implementations
impl<T> Any for Look
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for Look
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for Look
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for Look
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for Look
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for Look
where
T: Clone,
type Owned = T;fn to_owned(&self) -> Tfn clone_into(&self, target: &mut T)
impl<T, U> Into<U> for Look
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for Look
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for Look
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>