REAL
Regular Expression Algorithmic Library — constexpr C++20 regex
Loading...
Searching...
No Matches
real::dfa Class Reference

A maximal-munch DFA over an ordered set of patterns. More...

#include <dfa.hpp>

Collaboration diagram for real::dfa:
[legend]

Public Member Functions

 dfa (std::span< const detail::program_view > programs)
 Builds the DFA from compiled programs (the embedder path).
 
 dfa (std::span< const regex > patterns)
 Builds the DFA from regexes (a convenience over regex::raw_program).
 
std::optional< dfa_matchmatch (std::string_view rest) const noexcept
 Matches the longest pattern anchored at the start of rest.
 
std::size_t state_count () const noexcept
 The number of states in the minimized automaton (includes the dead state).
 
std::size_t rule_count () const noexcept
 The number of patterns the DFA was built from.
 
std::size_t class_count () const noexcept
 The number of byte-equivalence classes (the reduced alphabet width).
 

Static Private Member Functions

static std::vector< detail::program_viewviews_of (std::span< const regex > patterns)
 Materializes program views from patterns (helper for the regex ctor).
 

Private Attributes

detail::dfa_tables tables_
 The immutable baked tables.
 

Detailed Description

A maximal-munch DFA over an ordered set of patterns.

Built once (heap-allocated tables), then immutable and cheap to copy-share. match returns the longest match at the cursor, breaking ties toward the earliest pattern — the lexer's maximal munch, in one pass over the input.

Definition at line 454 of file dfa.hpp.

Constructor & Destructor Documentation

◆ dfa() [1/2]

real::dfa::dfa ( std::span< const detail::program_view programs)
inlineexplicit

Builds the DFA from compiled programs (the embedder path).

Parameters
[in]programsThe patterns' programs, in priority order (see regex::raw_program).
Exceptions
real::dfa_errorif any program holds a non-head zero-width assertion.

Definition at line 463 of file dfa.hpp.

◆ dfa() [2/2]

real::dfa::dfa ( std::span< const regex patterns)
inlineexplicit

Builds the DFA from regexes (a convenience over regex::raw_program).

Parameters
[in]patternsThe patterns, in priority order; they must outlive this call.
Exceptions
real::dfa_errorif any pattern holds a non-head zero-width assertion.

Definition at line 472 of file dfa.hpp.

Member Function Documentation

◆ class_count()

std::size_t real::dfa::class_count ( ) const
inlinenoexcept

The number of byte-equivalence classes (the reduced alphabet width).

Definition at line 519 of file dfa.hpp.

◆ match()

std::optional< dfa_match > real::dfa::match ( std::string_view  rest) const
inlinenoexcept

Matches the longest pattern anchored at the start of rest.

Maximal munch: the longest match wins; on equal length the earliest pattern (lowest index passed to the constructor) wins; an empty match never wins.

Parameters
[in]restThe text to match at its start.
Returns
The winning rule index and byte length, or std::nullopt if nothing non-empty matches.

Definition at line 486 of file dfa.hpp.

◆ rule_count()

std::size_t real::dfa::rule_count ( ) const
inlinenoexcept

The number of patterns the DFA was built from.

Definition at line 513 of file dfa.hpp.

◆ state_count()

std::size_t real::dfa::state_count ( ) const
inlinenoexcept

The number of states in the minimized automaton (includes the dead state).

Definition at line 507 of file dfa.hpp.

◆ views_of()

static std::vector< detail::program_view > real::dfa::views_of ( std::span< const regex patterns)
inlinestaticprivate

Materializes program views from patterns (helper for the regex ctor).

Definition at line 527 of file dfa.hpp.

Member Data Documentation

◆ tables_

detail::dfa_tables real::dfa::tables_
private

The immutable baked tables.

Definition at line 537 of file dfa.hpp.


The documentation for this class was generated from the following file: