Skip to main content

Inner

Struct Inner 

Source
pub(super) struct Inner {
Show 15 fields states: Vec<State>, start_anchored: StateID, start_unanchored: StateID, start_pattern: Vec<StateID>, group_info: GroupInfo, byte_class_set: ByteClassSet, byte_classes: ByteClasses, has_capture: bool, has_empty: bool, utf8: bool, reverse: bool, look_matcher: LookMatcher, look_set_any: LookSet, look_set_prefix_any: LookSet, memory_extra: usize,
}
Expand description

The “inner” part of the NFA. We split this part out so that we can easily wrap it in an Arc above in the definition of NFA.

See builder.rs for the code that actually builds this type. This module does provide (internal) mutable methods for adding things to this NFA before finalizing it, but the high level construction process is controlled by the builder abstraction. (Which is complicated enough to get its own module.)

Fields§

§states: Vec<State>

The state sequence. This sequence is guaranteed to be indexable by all starting state IDs, and it is also guaranteed to contain at most one Match state for each pattern compiled into this NFA. (A pattern may not have a corresponding Match state if a Match state is impossible to reach.)

§start_anchored: StateID

The anchored starting state of this NFA.

§start_unanchored: StateID

The unanchored starting state of this NFA.

§start_pattern: Vec<StateID>

The starting states for each individual pattern. Starting at any of these states will result in only an anchored search for the corresponding pattern. The vec is indexed by pattern ID. When the NFA contains a single regex, then start_pattern[0] and start_anchored are always equivalent.

§group_info: GroupInfo

Info about the capturing groups in this NFA. This is responsible for mapping groups to slots, mapping groups to names and names to groups.

§byte_class_set: ByteClassSet

A representation of equivalence classes over the transitions in this NFA. Two bytes in the same equivalence class must not discriminate between a match or a non-match. This map can be used to shrink the total size of a DFA’s transition table with a small match-time cost.

Note that the NFA’s transitions are not defined in terms of these equivalence classes. The NFA’s transitions are defined on the original byte values. For the most part, this is because they wouldn’t really help the NFA much since the NFA already uses a sparse representation to represent transitions. Byte classes are most effective in a dense representation.

§byte_classes: ByteClasses

This is generated from byte_class_set, and essentially represents the same thing but supports different access patterns. Namely, this permits looking up the equivalence class of a byte very cheaply.

Ideally we would just store this, but because of annoying code structure reasons, we keep both this and byte_class_set around for now. I think I would prefer that byte_class_set were computed in the Builder, but right now, we compute it as states are added to the NFA.

§has_capture: bool

Whether this NFA has a Capture state anywhere.

§has_empty: bool

When the empty string is in the language matched by this NFA.

§utf8: bool

Whether UTF-8 mode is enabled for this NFA. Briefly, this means that all non-empty matches produced by this NFA correspond to spans of valid UTF-8, and any empty matches produced by this NFA that split a UTF-8 encoded codepoint should be filtered out by the corresponding regex engine.

§reverse: bool

Whether this NFA is meant to be matched in reverse or not.

§look_matcher: LookMatcher

The matcher to be used for look-around assertions.

§look_set_any: LookSet

The union of all look-around assertions that occur anywhere within this NFA. If this set is empty, then it means there are precisely zero conditional epsilon transitions in the NFA.

§look_set_prefix_any: LookSet

The union of all look-around assertions that occur as a zero-length prefix for any of the patterns in this NFA.

§memory_extra: usize

Heap memory used indirectly by NFA states and other things (like the various capturing group representations above). Since each state might use a different amount of heap, we need to keep track of this incrementally.

Implementations§

Source§

impl Inner

Source

pub(super) fn into_nfa(self) -> NFA

Runs any last finalization bits and turns this into a full NFA.

Source

pub(super) fn group_info(&self) -> &GroupInfo

Returns the capturing group info for this NFA.

Source

pub(super) fn add(&mut self, state: State) -> StateID

Add the given state to this NFA after allocating a fresh identifier for it.

This panics if too many states are added such that a fresh identifier could not be created. (Currently, the only caller of this routine is a Builder, and it upholds this invariant.)

Source

pub(super) fn set_starts( &mut self, start_anchored: StateID, start_unanchored: StateID, start_pattern: &[StateID], )

Set the starting state identifiers for this NFA.

start_anchored and start_unanchored may be equivalent. When they are, then the NFA can only execute anchored searches. This might occur, for example, for patterns that are unconditionally anchored. e.g., ^foo.

Source

pub(super) fn set_utf8(&mut self, yes: bool)

Sets the UTF-8 mode of this NFA.

Source

pub(super) fn set_reverse(&mut self, yes: bool)

Sets the reverse mode of this NFA.

Source

pub(super) fn set_look_matcher(&mut self, m: LookMatcher)

Sets the look-around assertion matcher for this NFA.

Source

pub(super) fn set_captures( &mut self, captures: &[Vec<Option<Arc<str>>>], ) -> Result<(), GroupInfoError>

Set the capturing groups for this NFA.

The given slice should contain the capturing groups for each pattern, The capturing groups in turn should correspond to the total number of capturing groups in the pattern, including the anonymous first capture group for each pattern. If a capturing group does have a name, then it should be provided as a Arc.

This returns an error if a corresponding GroupInfo could not be built.

Source

pub(super) fn remap(&mut self, old_to_new: &[StateID])

Remap the transitions in every state of this NFA using the given map. The given map should be indexed according to state ID namespace used by the transitions of the states currently in this NFA.

This is particularly useful to the NFA builder, since it is convenient to add NFA states in order to produce their final IDs. Then, after all of the intermediate “empty” states (unconditional epsilon transitions) have been removed from the builder’s representation, we can re-map all of the transitions in the states already added to their final IDs.

Trait Implementations§

Source§

impl Debug for Inner

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Inner

Source§

fn default() -> Inner

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Inner

§

impl RefUnwindSafe for Inner

§

impl Send for Inner

§

impl Sync for Inner

§

impl Unpin for Inner

§

impl UnsafeUnpin for Inner

§

impl UnwindSafe for Inner

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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 T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.