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

Extracts a required inner literal from a pattern's AST — the substring that every match must contain ((\w+)@(\w+) -> @, key=(\w+) -> key=, \d{4}-\d{2} -> -). It is the memmem candidate an inner-literal prefilter scans for: find the literal, then confirm the surrounding pattern from that candidate. Pure over the node pool; inert — nothing routes on it yet. More...

#include <real/version.hpp>
#include <array>
#include <cstdint>
#include <span>
#include <string_view>
#include <vector>
#include <real/engine/prefilter.hpp>
#include <real/frontend/ast.hpp>
Include dependency graph for inner_literal.hpp:

Go to the source code of this file.

Classes

struct  real::detail::inner_literal
 The best required inner literal of a pattern (the memmem candidate). len == 0 means the pattern declined: an alternation, an optional (?/*/{0,n}), a lookaround or an anchor at the level walked, or simply no literal run — anything that would make a required literal unsound. More...
 
struct  real::detail::inner_literal_detail::walk_state
 Extraction state threaded through the walk: the growing byte run, the best literal so far, and the top-level concat child each run began at (so the winner carries its prefix boundary). More...
 

Namespaces

namespace  real
 
namespace  real::detail
 
namespace  real::detail::inner_literal_detail
 

Functions

constexpr std::uint32_t real::detail::inner_literal_detail::score_run (std::span< const std::uint8_t > run)
 Selectivity of a byte run: the sum of per-byte rarity (2000 - byte_frequency). A sum (rather than the rarest byte alone) approximates the product of per-byte match probabilities, so it rewards both a rare byte and a longer literal — the two things that shrink the candidate count.
 
constexpr void real::detail::inner_literal_detail::flush (walk_state &st)
 Score the current byte run and keep it (with its prefix boundary) if it beats best, then clear it (capped at inner_literal_max).
 
constexpr bool real::detail::inner_literal_detail::walk (const ast &tree, std::int32_t idx, walk_state &st, std::int32_t top_child)
 Walk one node, appending guaranteed-present literal bytes to st.run. top_child is the top-level concat child index this node belongs to (-1 when nested in a group/repeat, so any run it starts has no clean top-level prefix boundary). Returns false to DECLINE the whole extraction — an alternation, an optional (repeat min 0), a lookaround or an anchor would make a required inner literal unsound (a path could bypass it) or the pattern VM-routed. Every byte appended is present in every match; the confirming scan then verifies the surrounding context.
 
constexpr inner_literal real::detail::extract_inner_literal (const ast &tree)
 Extract the best required inner literal from a pattern's AST (a pure function on the node pool). Returns an empty inner_literal when the pattern declines. Inert: nothing routes on it yet.
 
ast real::detail::build_prefix_ast (const ast &tree, std::int32_t count)
 Build the prefix sub-AST: the first count top-level concat children (count >= 1). Copies the tree and truncates the root concat's child chain after the count-th child — the later children become unreferenced and are simply never reached when it is compiled.
 

Variables

constexpr std::size_t real::detail::inner_literal_max {16}
 The most bytes an inner literal keeps (a longer memmem target is diminishing returns and storage).
 

Detailed Description

Extracts a required inner literal from a pattern's AST — the substring that every match must contain ((\w+)@(\w+) -> @, key=(\w+) -> key=, \d{4}-\d{2} -> -). It is the memmem candidate an inner-literal prefilter scans for: find the literal, then confirm the surrounding pattern from that candidate. Pure over the node pool; inert — nothing routes on it yet.

Definition in file inner_literal.hpp.