sun::parsing::DFA
class · Source (opens in a new tab)
class sun::parsing::DFALazily determinized NFA (subset construction with a transition cache)
A DFA state is a set of NFA states. Transitions are materialized the first time they are taken and then cached, so a scan costs one array load per input byte instead of a walk over the NFA's active set. The state count is bounded by the regex, not by the input.
Captures survive determinization because the NFA's capture bookkeeping only ever depended on which states are active, not on the path taken: a group's candidate start is written by any active enterGroup state and its end is committed by any active exitGroup state (both single global slots per group id). Those are properties of the state set, so they are precomputed per DFA state. This reproduces the NFA's semantics exactly, including its "last writer wins per group id" approximation. Path-accurate captures would need a tagged DFA with per-transition register copies; that is not built here.
The Lexer bypasses captures entirely and uses acceptKind()/step() directly.
Types
- sun::parsing::DFA::SetHash (private)
- sun::parsing::DFA::ExitInfo (private)
Public Functions
- DFA
- acceptKind
- acceptingState
- bestCapture
- canReachAcceptingWithNonEmptyInput
- captureFor
- fullReset
- isDead
- matches
- resetToPosition
- simulate
- startState
- stateCount
- step
- transitionMisses
DFA
public · function · Source (opens in a new tab)
sun::parsing::DFA::DFA(NFA nfa)Creates a deterministic matcher from a nondeterministic automaton.
Related: NFA
acceptKind
public · function · Source (opens in a new tab)
int32_t sun::parsing::DFA::acceptKind(int32_t s) constToken kind of the alternative accepted in this state, or kNoAccept.
Related: Token
acceptingState
public · function · Source (opens in a new tab)
bool sun::parsing::DFA::acceptingState(int32_t s) constReturns the acceptance information for a deterministic state.
bestCapture
public · function · Source (opens in a new tab)
const RegexCapture * sun::parsing::DFA::bestCapture() constWinning capture of the current scan: longest match among NAMED groups, ties broken by lowest numeric group name (= token declaration order).
Related: RegexCapture
canReachAcceptingWithNonEmptyInput
public · function · Source (opens in a new tab)
bool sun::parsing::DFA::canReachAcceptingWithNonEmptyInput() constReports whether a nonempty continuation can reach an accepting state.
captureFor
public · function · Source (opens in a new tab)
const RegexCapture * sun::parsing::DFA::captureFor(int groupIdx) constCapture recorded for a group in the current scan, or nullptr.
Related: RegexCapture, Capture
fullReset
public · function · Source (opens in a new tab)
void sun::parsing::DFA::fullReset()Clears matching progress and restores the initial position.
isDead
public · function · static · Source (opens in a new tab)
static bool sun::parsing::DFA::isDead(int32_t s)Reports whether a state cannot continue a match.
matches
public · function · Source (opens in a new tab)
bool sun::parsing::DFA::matches(const std::string &input)Reports whether the automaton accepts the complete input string.
resetToPosition
public · function · Source (opens in a new tab)
void sun::parsing::DFA::resetToPosition(sun::support::Position pos)Restarts matching at the supplied source position.
Related: sun::support::Position
simulate
public · function · Source (opens in a new tab)
void sun::parsing::DFA::simulate(const std::string &input)Runs the automaton over the supplied input text.
startState
public · function · Source (opens in a new tab)
int32_t sun::parsing::DFA::startState() constReturns the state from which matching begins.
stateCount
public · function · Source (opens in a new tab)
int sun::parsing::DFA::stateCount() constReturns the number of deterministic states created so far.
step
step(int32_t s, unsigned char c)
public · function · Source (opens in a new tab)
int32_t sun::parsing::DFA::step(int32_t s, unsigned char c)Consumes a character and advances to the corresponding automaton state.
step(char c)
public · function · Source (opens in a new tab)
bool sun::parsing::DFA::step(char c)Consumes a character and advances to the corresponding automaton state.
transitionMisses
public · function · Source (opens in a new tab)
long long sun::parsing::DFA::transitionMisses() constReturns the number of transitions requiring uncached computation.
Public Fields
isAccepting
public · variable · Source (opens in a new tab)
bool sun::parsing::DFA::isAccepting = falseNo documentation comment.
kAlphabet
public · variable · static · Source (opens in a new tab)
int sun::parsing::DFA::kAlphabet = 256No documentation comment.
kDead
public · variable · static · Source (opens in a new tab)
int32_t sun::parsing::DFA::kDead = 0No documentation comment.
kNoAccept
public · variable · static · Source (opens in a new tab)
int32_t sun::parsing::DFA::kNoAccept = -1No documentation comment.
kUncomputed
public · variable · static · Source (opens in a new tab)
int32_t sun::parsing::DFA::kUncomputed = -1No documentation comment.
Private Functions
addClosure
private · function · Source (opens in a new tab)
void sun::parsing::DFA::addClosure(int32_t id)Adds a state and the states reachable through empty transitions.
intern
private · function · Source (opens in a new tab)
int32_t sun::parsing::DFA::intern(const std::vector< int32_t > &set)Look up a sorted state set, creating the DFA state if it is new.
Related: DFA
materialize
private · function · Source (opens in a new tab)
int32_t sun::parsing::DFA::materialize(int32_t from, unsigned char c)Compute and cache the transition out of from on byte c.
Private Fields
- acceptKind_
- accepting_
- canExtend_
- candidateGen_
- candidateStart_
- captureGen_
- captureSlots_
- cur_
- enterOff_
- enterPool_
- exitOff_
- exitPool_
- gen_
- interner_
- markGen_
- mark_
- misses_
- nfa_
- position_
- scratch_
- sets_
- start_
- trans_
acceptKind_
private · variable · Source (opens in a new tab)
std::vector<int32_t> sun::parsing::DFA::acceptKind_No documentation comment.
accepting_
private · variable · Source (opens in a new tab)
std::vector<uint8_t> sun::parsing::DFA::accepting_No documentation comment.
canExtend_
private · variable · Source (opens in a new tab)
std::vector<uint8_t> sun::parsing::DFA::canExtend_No documentation comment.
candidateGen_
private · variable · Source (opens in a new tab)
std::vector<uint32_t> sun::parsing::DFA::candidateGen_No documentation comment.
candidateStart_
private · variable · Source (opens in a new tab)
std::vector<sun::support::Position> sun::parsing::DFA::candidateStart_No documentation comment.
Related: sun::support::Position
captureGen_
private · variable · Source (opens in a new tab)
std::vector<uint32_t> sun::parsing::DFA::captureGen_No documentation comment.
captureSlots_
private · variable · Source (opens in a new tab)
std::vector<RegexCapture> sun::parsing::DFA::captureSlots_No documentation comment.
Related: RegexCapture
cur_
private · variable · Source (opens in a new tab)
int32_t sun::parsing::DFA::cur_ = kDeadNo documentation comment.
Related: kDead
enterOff_
private · variable · Source (opens in a new tab)
std::vector<int32_t> sun::parsing::DFA::enterOff_No documentation comment.
enterPool_
private · variable · Source (opens in a new tab)
std::vector<int32_t> sun::parsing::DFA::enterPool_No documentation comment.
exitOff_
private · variable · Source (opens in a new tab)
std::vector<int32_t> sun::parsing::DFA::exitOff_No documentation comment.
exitPool_
private · variable · Source (opens in a new tab)
std::vector<ExitInfo> sun::parsing::DFA::exitPool_No documentation comment.
Related: ExitInfo
gen_
private · variable · Source (opens in a new tab)
uint32_t sun::parsing::DFA::gen_ = 0No documentation comment.
interner_
private · variable · Source (opens in a new tab)
std::unordered_map<std::vector<int32_t>, int32_t, SetHash> sun::parsing::DFA::interner_No documentation comment.
Related: SetHash
markGen_
private · variable · Source (opens in a new tab)
uint32_t sun::parsing::DFA::markGen_ = 0No documentation comment.
mark_
private · variable · Source (opens in a new tab)
std::vector<uint32_t> sun::parsing::DFA::mark_No documentation comment.
misses_
private · variable · Source (opens in a new tab)
long long sun::parsing::DFA::misses_ = 0No documentation comment.
nfa_
private · variable · Source (opens in a new tab)
NFA sun::parsing::DFA::nfa_No documentation comment.
Related: NFA
position_
private · variable · Source (opens in a new tab)
sun::support::Position sun::parsing::DFA::position_No documentation comment.
Related: sun::support::Position
scratch_
private · variable · Source (opens in a new tab)
std::vector<int32_t> sun::parsing::DFA::scratch_No documentation comment.
sets_
private · variable · Source (opens in a new tab)
std::vector<std::vector<int32_t> > sun::parsing::DFA::sets_No documentation comment.
start_
private · variable · Source (opens in a new tab)
int32_t sun::parsing::DFA::start_ = kDeadNo documentation comment.
Related: kDead
trans_
private · variable · Source (opens in a new tab)
std::vector<int32_t> sun::parsing::DFA::trans_No documentation comment.