10#ifndef REAL_PROGRAM_HPP
11#define REAL_PROGRAM_HPP
33 inline constexpr std::size_t
npos {std::numeric_limits<std::size_t>::max()};
71 return static_cast<flags>(
static_cast<std::uint8_t
>(lhs) |
static_cast<std::uint8_t
>(rhs));
83 return static_cast<flags>(
static_cast<std::uint8_t
>(lhs) &
static_cast<std::uint8_t
>(rhs));
142 [[nodiscard]]
const char*
what() const noexcept
override
150 [[nodiscard]] std::size_t
position() const noexcept
344 struct regex_immutables;
394 return {.
code = std::span<const instr>(
code),
395 .classes = std::span<const char_class>(
classes),
396 .names = std::span<const named_group>(
names),
397 .lookarounds = std::span<const lookaround_sub>(
lookarounds),
398 .cp_classes = std::span<const cp_class>(
cp_classes),
399 .cp_ranges = std::span<const code_range>(
cp_ranges),
400 .prefix_code = std::span<const instr>(
prefix_code),
256-bit byte set with O(1) membership, fully constexpr.
error_kind kind_
Malformed (syntax) vs unsupported-by-REAL.
std::size_t position_
Offset in the pattern text.
regex_error(const std::string &message, std::size_t position, error_kind kind=error_kind::syntax)
Builds the error.
const char * what() const noexcept override
Returns the formatted error message (with position).
std::string message_
Formatted message returned by what().
error_kind kind() const noexcept
Whether the pattern is malformed (syntax) or well-formed but unsupported by REAL.
std::size_t position() const noexcept
Returns the byte offset in the pattern where the error was found.
look_dir
Direction of a lookaround sub-pattern.
@ ahead
(?= / (?! — the sub matches starting at the position.
@ behind
(?<= / (?<! — the sub matches ending exactly at the position.
assert_kind
Kind of zero-width assertion carried in assert_position's arg8.
@ word_start
< (non-word/start on the left, word on the right).
@ word_end
> (word on the left, non-word/end on the right).
@ line_start
^ with multiline.
@ line_end
$ with multiline.
@ word_boundary
\b (Unicode word-ness in text mode; ASCII in bytes / re.A).
@ text_start
\A, and ^ without multiline.
@ text_end_or_final_newline
$ without multiline (Python semantics).
opcode
NFA instruction opcodes executed by the Pike VM.
@ klass_cp
Consume one code point tested against cp_classes[arg16] (decode + range bsearch); enters a 3-instr co...
@ byte
Consume one byte equal to arg8; fall through to pc+1.
@ save
Store current position in slot arg16; fall through (epsilon).
@ klass
Consume one byte in classes[arg16]; fall through to pc+1.
@ assert_lookaround
Epsilon; proceeds only if the lookaround sub-program arg16 holds here.
@ assert_position
Epsilon; proceeds only if assertion arg8 holds here.
@ split
Epsilon-branch to x (preferred) and y.
error_kind
Exception thrown for an invalid pattern (or one exceeding a limit).
constexpr std::size_t npos
Sentinel for "no position" / unset capture slot (akin to std::string::npos).
match_semantics
Which match a search returns among those starting at the leftmost position (an experimental,...
@ longest
Leftmost-longest (POSIX / RE2 set_longest_match): the longest overall match wins the bounds.
@ first
Leftmost-first (Perl / Python re / the crate): source-order thread priority decides....
constexpr bool has_flag(flags value, flags flag)
Tests whether flag is set in value.
constexpr flags operator|(flags lhs, flags rhs)
Bitwise-OR of two flag sets.
constexpr flags operator&(flags lhs, flags rhs)
Bitwise-AND of two flag sets.
flags
Compilation flags, mirroring Python's re.I, re.M and re.S.
@ dotall
. also matches \n.
@ verbose
Verbose mode (re.X): ignore unescaped whitespace and # comments outside classes.
@ bytes
Binary mode: . and [^…] match raw bytes, not codepoints.
@ ascii
ASCII mode (re.A): \d \w \s \b stay ASCII and icase folds ASCII only, even in text mode....
@ icase
Case-insensitive (ASCII).
@ ecma
ECMAScript compatibility: $ (no multiline) matches only at the very end (not before a final \n,...
@ multiline
^ and $ also match at line boundaries.
@ dollar_endonly
$ (no multiline) matches only at the very end of the text, never before a final \n — the Rust/\z sema...
A set of byte values (0–255) as a 256-bit bitmap.
An inclusive code-point range [lo, hi]. Shared by character classes (ast.hpp) and the generated Unico...
std::uint32_t lo
First code point (inclusive).
std::uint32_t hi
Last code point (inclusive).
A match-time code-point class for the klass_cp opcode: an ASCII bitmap for code points < 0x80 plus a ...
std::uint32_t range_count
Number of ranges belonging to this class.
std::uint32_t range_begin
First range in the program's cp_ranges buffer.
char_class ascii
Members < 0x80.
Owning, heap-allocated program: the storage backing real::regex.
std::int32_t codepoint_mark_ascii
ASCII sub-class index of an emitted codepoint-class block (-1 = none).
std::vector< cp_class > cp_classes
Match-time code-point classes (for klass_cp).
pattern_hints hints
Search-acceleration hints.
std::vector< instr > prefix_code
IL: the inner-literal prefix sub-program (the part before the literal), for the reverse start-finder....
std::uint16_t slot_count
2 * (capture groups + 1).
std::vector< instr > code
The instruction stream (main program + lookaround sub-program regions).
std::vector< char_class > prefix_classes
IL: classes for prefix_code.
constexpr program_view view() const
Returns a non-owning program_view over this program.
std::int32_t codepoint_mark_offset
Where that block starts (program offset); the whole-pattern hint requires offset 1.
std::vector< cp_class > prefix_cp_classes
IL: code-point classes (klass_cp) for prefix_code.
std::vector< code_range > prefix_cp_ranges
IL: flat range buffer for prefix_cp_classes.
bool unicode_word
\b \B < > use Unicode word-ness (text mode).
std::vector< code_range > cp_ranges
Flat range buffer the cp_class slices index into.
bool byte_mode
flags::bytes mode.
std::vector< lookaround_sub > lookarounds
Bounded lookaround sub-programs (regions of code).
std::vector< char_class > classes
Interned character classes.
std::vector< named_group > names
Named capture groups.
The best required inner literal of a pattern (the memmem candidate). len == 0 means the pattern decli...
One NFA instruction. Field meaning depends on op.
std::int32_t secondary_target
Secondary branch target (split).
std::uint8_t arg8
Byte literal, or assert_kind, depending on op.
std::uint16_t arg16
Class index (klass) or capture slot (save).
std::int32_t primary_target
Primary branch target (split/jump).
A bounded lookaround sub-program, referenced by assert_lookaround's arg16.
std::int32_t code_length
Instruction count of the sub-program.
bool negative
(?! / (?<! (negated assertion).
std::int32_t code_offset
First instruction of the sub-program in code.
std::int32_t l_max
Max bytes the sub-pattern can consume (bounded).
look_dir direction
Ahead or behind.
std::int32_t begin
Start offset of the name in the pattern text.
std::int32_t end
End offset (exclusive) of the name.
std::int32_t group
Capture group number.
Search-acceleration hints extracted from a compiled program.
std::uint8_t exact_literal_len
Length of the pure-literal match, or 0.
bool greedy_cp_class_plus
The greedy_cp_class pattern is a greedy + loop (vs a single code point).
std::int16_t rare_byte
A required literal byte at a fixed offset from the match start that is statically rarer than the patt...
std::array< char, 16 > prefix
Required literal prefix (possibly truncated).
std::int32_t inner_literal_prefix
bool fixed_alternation
Whole pattern is an alternation of straight-line branches (no captures/asserts).
bool anchored_start
\A / ^ (no multiline): only position 0.
std::uint8_t prefix_size
Valid bytes in prefix.
std::int16_t greedy_group_start
For a class-loop wrapped in one capturing group ((\w+), ([a-z]+)): the group's start slot to mirror t...
std::array< char, 6 > stop_set
For a whole-pattern class+ run whose accepted set has a small (<= 6-byte) complement: the STOP bytes ...
bool line_anchored
^ multiline: position 0 or after \n.
std::int16_t greedy_group_end
The enveloping group's end slot (mirrors the whole-match end).
std::int32_t greedy_cp_class
cp_class index if the whole pattern is a code-point class klass_cp (optionally +),...
bool empty_match_possible
The pattern can match the empty string (the nullable gate; conservative: assertions/lookarounds pass ...
std::int32_t greedy_class_loop
Class index if the whole pattern is "class+", else -1.
std::uint8_t small_set_size
Number of valid members in small_set — 0 when not a small set, else 2..4. Drives the memchr-cascade s...
bool fixed_shape
Whole pattern is a fixed-width byte/klass sequence (no branches/asserts/captures).
char_class first_bytes
All possible first bytes.
bool codepoint_class_plus
The codepoint_class_ascii pattern is a greedy + loop (vs a single codepoint).
std::uint8_t inner_literal_len
std::uint8_t stop_set_size
Members in stop_set — 0 when the complement is too large, else 1..6.
bool first_bytes_valid
False when an empty match is possible.
std::array< char, 4 > small_set
The 2..4 possible first bytes, enumerated (the memchr-cascade set). Empty unless small_set_size is se...
std::uint8_t rare_offset
The fixed byte offset of rare_byte from the match start.
std::int32_t codepoint_class_ascii
ASCII-class index when the whole pattern is ./negated-class (optionally +), else -1.
std::int16_t single_first
The unique possible first byte, or -1.
bool byte_mode
flags::bytes mode — positions are raw bytes.
std::span< const instr > prefix_code
IL: inner-literal prefix sub-program (the reverse start-finder). Empty unless there is a required lit...
std::span< const named_group > names
Named capture groups.
regex_immutables * immut
Per-regex DFA/one-pass cache (dynamic storage only; else null).
std::span< const lookaround_sub > lookarounds
Bounded lookaround sub-programs (regions of code).
std::span< const code_range > prefix_cp_ranges
IL: flat range buffer for prefix_cp_classes.
std::uint16_t slot_count
2 * (capture groups + 1).
std::span< const cp_class > prefix_cp_classes
IL: code-point classes for prefix_code.
pattern_hints hints
Search-acceleration hints.
std::span< const code_range > cp_ranges
Flat range buffer the cp_class slices index into.
bool unicode_word
\b \B < > use Unicode word-ness (text mode, not bytes / re.A).
std::span< const char_class > prefix_classes
IL: classes for prefix_code.
std::span< const char_class > classes
Interned character classes.
std::span< const cp_class > cp_classes
Match-time code-point classes (for klass_cp).
std::span< const instr > code
The instruction stream (main + lookaround regions).
The per-regex immutable cache the router shares across every find_iter on a regex: the byte- program ...
REAL's version macros and the C++20 language-standard guard.