Struct re_set::parse::Compiler

source ·
pub struct Compiler { /* private fields */ }
Expand description

A compiler translates a regular expression AST to a sequence of instructions. The sequence of instructions represents an NFA.

Implementations§

source§

impl Compiler

source

pub fn new() -> Compiler

Create a new regular expression compiler.

Various options can be set before calling compile on an expression.

source

pub fn size_limit(self, size_limit: usize) -> Compiler

The size of the resulting program is limited by size_limit. If the program approximately exceeds the given size (in bytes), then compilation will stop and return an error.

source

pub fn bytes(self, yes: bool) -> Compiler

If bytes is true, then the program is compiled as a byte based automaton, which incorporates UTF-8 decoding into the machine. If it’s false, then the automaton is Unicode scalar value based, e.g., an engine utilizing such an automaton is responsible for UTF-8 decoding.

The specific invariant is that when returning a byte based machine, the neither the Char nor Ranges instructions are produced. Conversely, when producing a Unicode scalar value machine, the Bytes instruction is never produced.

Note that dfa(true) implies bytes(true).

source

pub fn only_utf8(self, yes: bool) -> Compiler

When disabled, the program compiled may match arbitrary bytes.

When enabled (the default), all compiled programs exclusively match valid UTF-8 bytes.

source

pub fn dfa(self, yes: bool) -> Compiler

When set, the machine returned is suitable for use in the DFA matching engine.

In particular, this ensures that if the regex is not anchored in the beginning, then a preceding .*? is included in the program. (The NFA based engines handle the preceding .*? explicitly, which is difficult or impossible in the DFA engine.)

source

pub fn reverse(self, yes: bool) -> Compiler

When set, the machine returned is suitable for matching text in reverse. In particular, all concatenations are flipped.

source

pub fn compile(self, exprs: &[Hir]) -> Result<Program, Error>

Compile a regular expression given its AST.

The compiler is guaranteed to succeed unless the program exceeds the specified size limit. If the size limit is exceeded, then compilation stops and returns an error.

Auto Trait Implementations§

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, 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.