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

Builds and holds the one-pass classification (and table, when eligible) of a byte-program. More...

#include <onepass.hpp>

Collaboration diagram for real::detail::onepass:
[legend]

Public Member Functions

constexpr onepass (const byte_program &bp, std::size_t max_bytes=max_table_bytes)
 
bool eligible () const
 
const std::string & bail_reason () const
 
std::size_t node_count () const
 
std::uint16_t num_classes () const
 
const std::vector< onepass_node > & nodes () const
 
std::uint8_t class_of (std::uint8_t byte) const
 The byte-class of byte, for a runtime that walks this table.
 
std::size_t slot_count () const
 The number of capture slots (group 0 start/end plus each group's).
 
template<typename OutSlots >
bool extract (std::string_view text, std::size_t s, std::size_t e, OutSlots &out) const
 Fills out with the capture slots of the one-pass match on text[s, e) — the single left-to- right pass the whole arc is for, no thread lists. text is the full subject (never a substring: assertions look at s - 1 and e). Anchored at s; this is fullmatch-on-span (the span the router located): it consumes to e and requires the run to accept exactly there. \ref real::npos marks a slot no edge wrote. Returns false (leaving out unspecified) if the pattern is ineligible or the span does not in fact match — which the caller has already ruled out for a router-supplied span.
 
bool asserts_hold (std::uint32_t mask, std::string_view text, std::size_t pos) const
 Whether every assertion in mask (a set of assert_kind bits) holds at pos in text.
 

Static Public Attributes

static constexpr std::uint32_t no_node {0xFFFFFFFFU}
 "No node yet" sentinel in the pc->node map.
 
static constexpr std::size_t max_nodes {65000}
 Node cap (RE2's), a memory/DoS bound.
 
static constexpr std::size_t max_slots {10}
 Slot-pointer cap: group 0 + four user groups.
 
static constexpr std::size_t minimize_buckets {4096}
 Hash buckets for the Moore-refinement dedup.
 
static constexpr std::size_t max_table_bytes {8U << 20}
 Table-memory cap (~8 MB): larger declines to the VM.
 

Private Member Functions

constexpr void bail (const char *reason, std::int32_t node=-1, std::int32_t klass=-1, std::int32_t pc=-1)
 Reject as not one-pass, recording a category and the offending node / byte-class / pc (kept as integers rather than formatted into the string so the whole builder stays constexpr — a constexpr real::regex embeds an (empty) one-pass table in its literal state).
 
constexpr std::uint32_t node_of (std::int32_t pc, std::vector< std::int32_t > &queue)
 Get-or-create the node whose entry pc is pc, enqueueing a fresh one for the flood.
 
constexpr void build (const byte_program &bp)
 
constexpr void minimize ()
 Moore partition refinement of the one-pass automaton: merge nodes that are behaviourally identical (same accept + match captures, and for every byte-class the same edge — target partition AND capture mask). The one-pass graph has cycles (\w+ loops), so bottom-up hash-consing is not enough; refinement to a fixpoint is. Merged nodes have identical capture masks by construction, so captures are unchanged. The dense per-node edge table is preserved, so extract's O(1) lookup is unchanged — the whole point of not going sparse.
 
constexpr void build_edges (std::int32_t pc, std::uint64_t cap_mask, std::uint32_t assert_mask, std::vector< char > &on_path, std::uint32_t node_id, std::vector< std::int32_t > &queue)
 Walk the epsilon-closure from pc, writing this node's edges. on_path detects epsilon cycles (a nullable loop => not one-pass). cap_mask accumulates the slots crossed so far.
 

Static Private Member Functions

static constexpr std::size_t sig_hash (const std::vector< std::uint64_t > &v)
 FNV-1a hash of a partition signature (for the constexpr-friendly bucket dedup). Accumulates in a fixed 64-bit width and truncates only at the return, so a 32-bit size_t (Win32) never sees a narrowing brace-init of the 64-bit offset basis.
 

Private Attributes

std::span< const instrcode_
 
std::span< const char_classclasses_
 
lazy_byte_alphabet alpha_
 
std::vector< std::vector< std::uint16_t > > class_cover_
 char-class index -> the byte-classes it consumes.
 
std::vector< std::uint32_t > pc_to_node_
 pc -> node id (or no_node).
 
std::vector< onepass_nodenodes_
 
std::size_t slot_count_ {0}
 
std::size_t max_bytes_ {max_table_bytes}
 
bool ascii_word_ {true}
 
std::int32_t bail_node_ {-1}
 
std::int32_t bail_class_ {-1}
 
std::int32_t bail_pc_ {-1}
 
bool eligible_ {true}
 
std::string bail_reason_
 

Detailed Description

Builds and holds the one-pass classification (and table, when eligible) of a byte-program.

Construction floods the program from the start: for each node it walks the epsilon-closure (split, jump, save) accumulating the capture mask, and every consuming instruction (byte, klass) writes the edge for its byte-class(es). A byte-class written twice with a different edge, a second reachable match with different captures, or an epsilon cycle (a nullable loop) each means not one-pass and the build bails with a human-readable reason. Node and slot counts are capped, so a pathological program is rejected rather than explored without bound.

Definition at line 74 of file onepass.hpp.

Constructor & Destructor Documentation

◆ onepass()

constexpr real::detail::onepass::onepass ( const byte_program bp,
std::size_t  max_bytes = max_table_bytes 
)
inlineexplicitconstexpr
Parameters
[in]bpThe byte-program to classify.
[in]max_bytesTable-memory cap; larger tables decline. Defaults to max_table_bytes; a smaller value is a test hook to exercise the cap without a huge pattern.

Definition at line 87 of file onepass.hpp.

Member Function Documentation

◆ asserts_hold()

bool real::detail::onepass::asserts_hold ( std::uint32_t  mask,
std::string_view  text,
std::size_t  pos 
) const
inline

Whether every assertion in mask (a set of assert_kind bits) holds at pos in text.

Definition at line 188 of file onepass.hpp.

◆ bail()

constexpr void real::detail::onepass::bail ( const char *  reason,
std::int32_t  node = -1,
std::int32_t  klass = -1,
std::int32_t  pc = -1 
)
inlineconstexprprivate

Reject as not one-pass, recording a category and the offending node / byte-class / pc (kept as integers rather than formatted into the string so the whole builder stays constexpr — a constexpr real::regex embeds an (empty) one-pass table in its literal state).

Definition at line 206 of file onepass.hpp.

◆ bail_reason()

const std::string & real::detail::onepass::bail_reason ( ) const
inline

Definition at line 104 of file onepass.hpp.

◆ build()

constexpr void real::detail::onepass::build ( const byte_program bp)
inlineconstexprprivate

Definition at line 233 of file onepass.hpp.

◆ build_edges()

constexpr void real::detail::onepass::build_edges ( std::int32_t  pc,
std::uint64_t  cap_mask,
std::uint32_t  assert_mask,
std::vector< char > &  on_path,
std::uint32_t  node_id,
std::vector< std::int32_t > &  queue 
)
inlineconstexprprivate

Walk the epsilon-closure from pc, writing this node's edges. on_path detects epsilon cycles (a nullable loop => not one-pass). cap_mask accumulates the slots crossed so far.

Definition at line 394 of file onepass.hpp.

◆ class_of()

std::uint8_t real::detail::onepass::class_of ( std::uint8_t  byte) const
inline

The byte-class of byte, for a runtime that walks this table.

Definition at line 125 of file onepass.hpp.

◆ eligible()

bool real::detail::onepass::eligible ( ) const
inline

Definition at line 99 of file onepass.hpp.

◆ extract()

template<typename OutSlots >
bool real::detail::onepass::extract ( std::string_view  text,
std::size_t  s,
std::size_t  e,
OutSlots &  out 
) const
inline

Fills out with the capture slots of the one-pass match on text[s, e) — the single left-to- right pass the whole arc is for, no thread lists. text is the full subject (never a substring: assertions look at s - 1 and e). Anchored at s; this is fullmatch-on-span (the span the router located): it consumes to e and requires the run to accept exactly there. \ref real::npos marks a slot no edge wrote. Returns false (leaving out unspecified) if the pattern is ineligible or the span does not in fact match — which the caller has already ruled out for a router-supplied span.

Parameters
[in]textThe full subject.
[in]sMatch start (anchor).
[in]eMatch end (the run must accept here).
[out]outCapture slots, sized to slot_count.

Definition at line 151 of file onepass.hpp.

◆ minimize()

constexpr void real::detail::onepass::minimize ( )
inlineconstexprprivate

Moore partition refinement of the one-pass automaton: merge nodes that are behaviourally identical (same accept + match captures, and for every byte-class the same edge — target partition AND capture mask). The one-pass graph has cycles (\w+ loops), so bottom-up hash-consing is not enough; refinement to a fixpoint is. Merged nodes have identical capture masks by construction, so captures are unchanged. The dense per-node edge table is preserved, so extract's O(1) lookup is unchanged — the whole point of not going sparse.

Definition at line 299 of file onepass.hpp.

◆ node_count()

std::size_t real::detail::onepass::node_count ( ) const
inline

Definition at line 109 of file onepass.hpp.

◆ node_of()

constexpr std::uint32_t real::detail::onepass::node_of ( std::int32_t  pc,
std::vector< std::int32_t > &  queue 
)
inlineconstexprprivate

Get-or-create the node whose entry pc is pc, enqueueing a fresh one for the flood.

Definition at line 219 of file onepass.hpp.

◆ nodes()

const std::vector< onepass_node > & real::detail::onepass::nodes ( ) const
inline

Definition at line 119 of file onepass.hpp.

◆ num_classes()

std::uint16_t real::detail::onepass::num_classes ( ) const
inline

Definition at line 114 of file onepass.hpp.

◆ sig_hash()

static constexpr std::size_t real::detail::onepass::sig_hash ( const std::vector< std::uint64_t > &  v)
inlinestaticconstexprprivate

FNV-1a hash of a partition signature (for the constexpr-friendly bucket dedup). Accumulates in a fixed 64-bit width and truncates only at the return, so a 32-bit size_t (Win32) never sees a narrowing brace-init of the 64-bit offset basis.

Definition at line 383 of file onepass.hpp.

◆ slot_count()

std::size_t real::detail::onepass::slot_count ( ) const
inline

The number of capture slots (group 0 start/end plus each group's).

Definition at line 131 of file onepass.hpp.

Member Data Documentation

◆ alpha_

lazy_byte_alphabet real::detail::onepass::alpha_
private

Definition at line 482 of file onepass.hpp.

◆ ascii_word_

bool real::detail::onepass::ascii_word_ {true}
private

Definition at line 488 of file onepass.hpp.

◆ bail_class_

std::int32_t real::detail::onepass::bail_class_ {-1}
private

Definition at line 490 of file onepass.hpp.

◆ bail_node_

std::int32_t real::detail::onepass::bail_node_ {-1}
private

Definition at line 489 of file onepass.hpp.

◆ bail_pc_

std::int32_t real::detail::onepass::bail_pc_ {-1}
private

Definition at line 491 of file onepass.hpp.

◆ bail_reason_

std::string real::detail::onepass::bail_reason_
private

Definition at line 493 of file onepass.hpp.

◆ class_cover_

std::vector<std::vector<std::uint16_t> > real::detail::onepass::class_cover_
private

char-class index -> the byte-classes it consumes.

Definition at line 483 of file onepass.hpp.

◆ classes_

std::span<const char_class> real::detail::onepass::classes_
private

Definition at line 481 of file onepass.hpp.

◆ code_

std::span<const instr> real::detail::onepass::code_
private

Definition at line 480 of file onepass.hpp.

◆ eligible_

bool real::detail::onepass::eligible_ {true}
private

Definition at line 492 of file onepass.hpp.

◆ max_bytes_

std::size_t real::detail::onepass::max_bytes_ {max_table_bytes}
private

Definition at line 487 of file onepass.hpp.

◆ max_nodes

constexpr std::size_t real::detail::onepass::max_nodes {65000}
staticconstexpr

Node cap (RE2's), a memory/DoS bound.

Definition at line 79 of file onepass.hpp.

◆ max_slots

constexpr std::size_t real::detail::onepass::max_slots {10}
staticconstexpr

Slot-pointer cap: group 0 + four user groups.

Definition at line 80 of file onepass.hpp.

◆ max_table_bytes

constexpr std::size_t real::detail::onepass::max_table_bytes {8U << 20}
staticconstexpr

Table-memory cap (~8 MB): larger declines to the VM.

Definition at line 82 of file onepass.hpp.

◆ minimize_buckets

constexpr std::size_t real::detail::onepass::minimize_buckets {4096}
staticconstexpr

Hash buckets for the Moore-refinement dedup.

Definition at line 81 of file onepass.hpp.

◆ no_node

constexpr std::uint32_t real::detail::onepass::no_node {0xFFFFFFFFU}
staticconstexpr

"No node yet" sentinel in the pc->node map.

Definition at line 78 of file onepass.hpp.

◆ nodes_

std::vector<onepass_node> real::detail::onepass::nodes_
private

Definition at line 485 of file onepass.hpp.

◆ pc_to_node_

std::vector<std::uint32_t> real::detail::onepass::pc_to_node_
private

pc -> node id (or no_node).

Definition at line 484 of file onepass.hpp.

◆ slot_count_

std::size_t real::detail::onepass::slot_count_ {0}
private

Definition at line 486 of file onepass.hpp.


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