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: StateIDThe anchored starting state of this NFA.
start_unanchored: StateIDThe 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: GroupInfoInfo 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: ByteClassSetA 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: ByteClassesThis 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: boolWhether this NFA has a Capture state anywhere.
has_empty: boolWhen the empty string is in the language matched by this NFA.
utf8: boolWhether 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: boolWhether this NFA is meant to be matched in reverse or not.
look_matcher: LookMatcherThe matcher to be used for look-around assertions.
look_set_any: LookSetThe 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: LookSetThe union of all look-around assertions that occur as a zero-length prefix for any of the patterns in this NFA.
memory_extra: usizeHeap 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
impl Inner
Sourcepub(super) fn into_nfa(self) -> NFA
pub(super) fn into_nfa(self) -> NFA
Runs any last finalization bits and turns this into a full NFA.
Sourcepub(super) fn group_info(&self) -> &GroupInfo
pub(super) fn group_info(&self) -> &GroupInfo
Returns the capturing group info for this NFA.
Sourcepub(super) fn add(&mut self, state: State) -> StateID
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.)
Sourcepub(super) fn set_starts(
&mut self,
start_anchored: StateID,
start_unanchored: StateID,
start_pattern: &[StateID],
)
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.
Sourcepub(super) fn set_reverse(&mut self, yes: bool)
pub(super) fn set_reverse(&mut self, yes: bool)
Sets the reverse mode of this NFA.
Sourcepub(super) fn set_look_matcher(&mut self, m: LookMatcher)
pub(super) fn set_look_matcher(&mut self, m: LookMatcher)
Sets the look-around assertion matcher for this NFA.
Sourcepub(super) fn set_captures(
&mut self,
captures: &[Vec<Option<Arc<str>>>],
) -> Result<(), GroupInfoError>
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.
Sourcepub(super) fn remap(&mut self, old_to_new: &[StateID])
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.