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
impl Compiler
sourcepub fn new() -> Compiler
pub fn new() -> Compiler
Create a new regular expression compiler.
Various options can be set before calling compile
on an expression.
sourcepub fn size_limit(self, size_limit: usize) -> Compiler
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.
sourcepub fn bytes(self, yes: bool) -> Compiler
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)
.
sourcepub fn only_utf8(self, yes: bool) -> Compiler
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.
sourcepub fn dfa(self, yes: bool) -> Compiler
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.)