Enum re_set::parse::Inst

source ·
pub enum Inst {
    Match(usize),
    Save(InstSave),
    Split(InstSplit),
    EmptyLook(InstEmptyLook),
    Char(InstChar),
    Ranges(InstRanges),
    Bytes(InstBytes),
}
Expand description

Inst is an instruction code in a Regex program.

Regrettably, a regex program either contains Unicode codepoint instructions (Char and Ranges) or it contains byte instructions (Bytes). A regex program can never contain both.

It would be worth investigating splitting this into two distinct types and then figuring out how to make the matching engines polymorphic over those types without sacrificing performance.

Other than the benefit of moving invariants into the type system, another benefit is the decreased size. If we remove the Char and Ranges instructions from the Inst enum, then its size shrinks from 32 bytes to 24 bytes. (This is because of the removal of a Box<[]> in the Ranges variant.) Given that byte based machines are typically much bigger than their Unicode analogues (because they can decode UTF-8 directly), this ends up being a pretty significant savings.

Variants§

§

Match(usize)

Match indicates that the program has reached a match state.

The number in the match corresponds to the Nth logical regular expression in this program. This index is always 0 for normal regex programs. Values greater than 0 appear when compiling regex sets, and each match instruction gets its own unique value. The value corresponds to the Nth regex in the set.

§

Save(InstSave)

Save causes the program to save the current location of the input in the slot indicated by InstSave.

§

Split(InstSplit)

Split causes the program to diverge to one of two paths in the program, preferring goto1 in InstSplit.

§

EmptyLook(InstEmptyLook)

EmptyLook represents a zero-width assertion in a regex program. A zero-width assertion does not consume any of the input text.

§

Char(InstChar)

Char requires the regex program to match the character in InstChar at the current position in the input.

§

Ranges(InstRanges)

Ranges requires the regex program to match the character at the current position in the input with one of the ranges specified in InstRanges.

§

Bytes(InstBytes)

Bytes is like Ranges, except it expresses a single byte range. It is used in conjunction with Split instructions to implement multi-byte character classes.

Implementations§

source§

impl Inst

source

pub fn is_match(&self) -> bool

Returns true if and only if this is a match instruction.

Trait Implementations§

source§

impl Clone for Inst

source§

fn clone(&self) -> Inst

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Inst

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl RefUnwindSafe for Inst

§

impl Send for Inst

§

impl Sync for Inst

§

impl Unpin for Inst

§

impl UnwindSafe for Inst

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.