A multi-rule DFA: maximal-munch (dfa_mode::munch) or which-matched unanchored scan (dfa_mode::which_matched).
More...
#include <dfa.hpp>
|
| | dfa (std::span< const detail::program_view > programs, dfa_mode mode=dfa_mode::munch) |
| | Builds the DFA from compiled programs (the embedder path).
|
| |
| | dfa (std::span< const regex > patterns, dfa_mode mode=dfa_mode::munch) |
| | Builds the DFA from regexes (a convenience over regex::raw_program).
|
| |
| std::optional< dfa_match > | match (std::string_view rest) const noexcept |
| | Matches the longest pattern anchored at the start of rest.
|
| |
| std::vector< bool > | which_matched (std::string_view text, bool first_byte_skip=true) const |
| | Which patterns match the subject at least once (single-pass).
|
| |
| bool | has_first_byte_skip () const noexcept |
| | True if set-level first-byte skip is armed for which_matched.
|
| |
| bool | is_unanchored () const noexcept |
| | True if this DFA was built with mid-stream restart (which-matched mode).
|
| |
| 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).
|
| |
A multi-rule DFA: maximal-munch (dfa_mode::munch) or which-matched unanchored scan (dfa_mode::which_matched).
Built once (heap-allocated tables), then immutable and cheap to copy-share. match is the lexer munch. which_matched is Stage-2 multi-accept (only valid when built with dfa_mode::which_matched).
◆ dfa() [1/2]
Builds the DFA from compiled programs (the embedder path).
- Parameters
-
| [in] | programs | The patterns' programs, in priority order (see regex::raw_program). |
| [in] | mode | Munch (default) or which-matched unanchored multi-accept. |
- Exceptions
-
| real::dfa_error | if any program holds a non-head zero-width assertion, a lookaround, a code-point class, or a possessive/atomic construct. |
◆ dfa() [2/2]
Builds the DFA from regexes (a convenience over regex::raw_program).
- Parameters
-
| [in] | patterns | The patterns, in priority order; they must outlive this call. |
| [in] | mode | Munch (default) or which-matched. |
- Exceptions
-
| real::dfa_error | if any pattern holds a non-head zero-width assertion, a lookaround, a code-point class, or a possessive/atomic construct. |
◆ class_count()
| std::size_t real::dfa::class_count |
( |
| ) |
const |
|
inlinenoexcept |
The number of byte-equivalence classes (the reduced alphabet width).
- Returns
- The class count.
◆ has_first_byte_skip()
| bool real::dfa::has_first_byte_skip |
( |
| ) |
const |
|
inlinenoexcept |
True if set-level first-byte skip is armed for which_matched.
- Returns
- Whether every rule contributed a valid first-byte set at build time.
◆ is_unanchored()
| bool real::dfa::is_unanchored |
( |
| ) |
const |
|
inlinenoexcept |
True if this DFA was built with mid-stream restart (which-matched mode).
- Returns
- Whether the tables carry self-restart transitions.
◆ 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] | rest | The text to match at its start. |
- Returns
- The winning rule index and byte length, or
std::nullopt if nothing non-empty matches.
◆ rule_count()
| std::size_t real::dfa::rule_count |
( |
| ) |
const |
|
inlinenoexcept |
The number of patterns the DFA was built from.
- Returns
- The rule count, which is also the width of which_matched's answer.
◆ state_count()
| std::size_t real::dfa::state_count |
( |
| ) |
const |
|
inlinenoexcept |
The number of states in the minimized automaton (includes the dead state).
- Returns
- The state count.
◆ views_of()
Materializes program views from patterns (helper for the regex ctor).
- Parameters
-
| [in] | patterns | The compiled regexes, which must outlive the views. |
- Returns
- One view per pattern, in the same order.
◆ which_matched()
| std::vector< bool > real::dfa::which_matched |
( |
std::string_view |
text, |
|
|
bool |
first_byte_skip = true |
|
) |
| const |
|
inline |
Which patterns match the subject at least once (single-pass).
Requires a build with dfa_mode::which_matched. Returns a bitset of length rule_count in construction order. Early-exits when every pattern has hit. Empty matches are excluded (only states that accepted after consuming a byte contribute, via post-move accept masks).
- Parameters
-
| [in] | text | Subject text. |
| [in] | first_byte_skip | When true (default), fast-forward over bytes that cannot start any rule while the walk is in the start state (a pure optimization). Pass false to disable for equivalence tests. |
- Returns
- One bool per rule, in construction order, true where that pattern matched.
The documentation for this class was generated from the following file: