REAL
Regular Expression Algorithmic Library — constexpr C++20 regex
Loading...
Searching...
No Matches
program.hpp File Reference

Compiled form of a pattern and the public flags / error types. More...

#include "real/version.hpp"
#include <array>
#include <cstdint>
#include <exception>
#include <limits>
#include <span>
#include <string>
#include <vector>
#include "real/core/charclass.hpp"
Include dependency graph for program.hpp:

Classes

class  real::regex_error
 The exception every rejected pattern throws: a message with the pattern offset it was found at, plus an error_kind a caller can branch on without parsing what. In a constexpr context (static_regex) reaching the throw is a compile-time error, the message appearing in the diagnostic trace. More...
 
struct  real::detail::code_range
 An inclusive code-point range [lo, hi]. Shared by character classes (ast.hpp) and the generated Unicode property / fold tables; lives here so those low-level headers need not pull in the parser. More...
 
struct  real::detail::cp_class
 A match-time code-point class for the klass_cp opcode: an ASCII bitmap for code points < 0x80 plus a slice of sorted non-ASCII ranges (indexing the program's flat cp_ranges buffer). It is the already-effective set (any \W/[^…] negation is materialised at compile time). Unlike the byte-NFA klass, the ranges are kept and binary-searched at match time — O(log ranges) per position, independent of the range count. More...
 
struct  real::detail::lookaround_sub
 A bounded lookaround sub-program, referenced by assert_lookaround's arg16. More...
 
struct  real::detail::instr
 One NFA instruction. Field meaning depends on op. More...
 
struct  real::detail::class_ref
 A typed reference into one of the three possessive-loop-body opcodes' own operand spaces. More...
 
struct  real::detail::pattern_hints
 Search-acceleration hints extracted from a compiled program. More...
 
struct  real::detail::named_group
 A named capture group. More...
 
struct  real::detail::program_view
 A non-owning view of everything the engine needs to run one compiled pattern: the borrowed spans, the slot count, the mode flags, the search hints, and the per-regex cache. Both storages hand one of these to the VM, which is why the engine is storage-agnostic. Valid only as long as the program it views is alive. More...
 
struct  real::detail::dynamic_program
 This view is COPIED ON EVERY find_iter AND count_matches CALL, so its size is a per-call cost and growing it is a decision, not a detail. More...
 

Namespaces

namespace  real
 REAL's public API: real::regex, real::static_regex, real::flags and the match/iterator types built on them.
 
namespace  real::detail
 DFA construction internals: subset construction over a flattened NFA. Not a stable API.
 

Enumerations

enum class  real::flags : std::uint16_t {
  real::none = 0 , real::icase = 1 , real::multiline = 2 , real::dotall = 4 ,
  real::bytes = 8 , real::verbose = 16 , real::ecma = 32 , real::ascii = 64 ,
  real::dollar_endonly = 128 , real::allow_raw_byte = 256 , real::ungreedy = 512
}
 Compilation flags, mirroring Python's re.I, re.M and re.S. More...
 
enum class  real::match_semantics : std::uint8_t { real::first = 0 , real::longest = 1 }
 Which match a search returns among those starting at the leftmost position. Opt-in: first below is what a search uses unless asked otherwise. More...
 
enum class  real::error_kind : std::uint8_t { syntax , unsupported }
 Whether a rejected pattern is malformed (syntax) or well formed but beyond REAL's linear engine (unsupported). More...
 
enum class  real::detail::opcode : std::uint8_t {
  real::detail::byte , real::detail::klass , real::detail::klass_cp , real::detail::split ,
  real::detail::jump , real::detail::save , real::detail::assert_position , real::detail::match ,
  real::detail::assert_lookaround , real::detail::byte_loop_possessive , real::detail::klass_loop_possessive , real::detail::klass_cp_loop_possessive
}
 NFA instruction opcodes executed by the Pike VM. More...
 
enum class  real::detail::assert_kind : std::uint8_t {
  real::detail::text_start , real::detail::text_end , real::detail::text_end_or_final_newline , real::detail::line_start ,
  real::detail::line_end , real::detail::word_boundary , real::detail::not_word_boundary , real::detail::word_start ,
  real::detail::word_end
}
 Kind of zero-width assertion carried in assert_position's arg8. More...
 
enum class  real::detail::look_dir : std::uint8_t { real::detail::ahead , real::detail::behind }
 Direction of a lookaround sub-pattern. More...
 
enum class  real::detail::class_kind : std::uint8_t { none , byte , klass , klass_cp }
 Which operand space a class_ref indexes: byte_loop_possessive's own literal byte value (not a table at all), classes[] (klass_loop_possessive), or cp_classes[] (klass_cp_loop_possessive). none = unarmed.
 

Functions

constexpr flags real::operator| (flags lhs, flags rhs)
 Bitwise-OR of two flag sets.
 
constexpr flags real::operator& (flags lhs, flags rhs)
 Bitwise-AND of two flag sets.
 
constexpr flags real::flags_without (flags value, flags removed)
 value with every flag in removed cleared – the (?flags-flags) removal.
 
constexpr bool real::has_flag (flags value, flags flag)
 Tests whether flag is set in value.
 
constexpr std::uint64_t real::detail::fingerprint_cp_class_content (const char_class &ascii, const code_range *ranges, std::uint32_t range_count)
 FNV-1a 64-bit content fingerprint of an ASCII bitmap + a contiguous range span. Used once at intern_cp_class (compile time / first intern); match time only reads cp_class::fingerprint. Constexpr so static_regex stays happy.
 

Variables

constexpr std::size_t real::npos {std::numeric_limits<std::size_t>::max()}
 Sentinel for "no position" / unset capture slot (akin to std::string::npos).
 
constexpr std::uint64_t real::detail::fnv1a_offset_basis {14695981039346656037ULL}
 FNV-1a 64-bit offset basis. Defined once and referenced everywhere, never re-typed: a constant copied by hand drifts, and a wrong basis still hashes perfectly well – it simply is not FNV-1a, so nothing downstream notices.
 
constexpr std::uint64_t real::detail::fnv1a_prime {1099511628211ULL}
 FNV-1a 64-bit prime, paired with fnv1a_offset_basis.
 

Detailed Description

Compiled form of a pattern and the public flags / error types.

Defines the NFA instruction set executed by the engine, the heap-allocated program the compiler produces, the non-owning view the engine runs over, the compilation real::flags, and real::regex_error (thrown on an invalid pattern).