REAL
Regular Expression Algorithmic Library — constexpr C++20 regex
Loading...
Searching...
No Matches
inner_literal_reverse.hpp
Go to the documentation of this file.
1
9#ifndef REAL_FRONTEND_INNER_LITERAL_REVERSE_HPP
10#define REAL_FRONTEND_INNER_LITERAL_REVERSE_HPP
11
12#include <real/version.hpp>
13
14#include <cstddef>
15#include <cstdint>
16#include <string_view>
17
18#include <real/automata/lazy_dfa.hpp> // build_byte_program, reverse_dfa
19#include <real/frontend/ast.hpp>
20#include <real/frontend/compiler.hpp> // compile
22
23namespace real::detail {
24
35 inline std::size_t prefix_reverse_start(const ast& tree,
36 std::int32_t count,
37 flags compile_flags,
38 std::string_view text,
39 std::size_t h,
40 std::size_t min_start)
41 {
42 if (count == 0) {
43 return h; // literal at the head: start == candidate
44 }
45 const ast prefix {build_prefix_ast(tree, count)};
46 const dynamic_program prog {compile(prefix, compile_flags | prefix.inline_flags)};
47 const byte_program bp {build_byte_program(prog.view())};
48 if (!bp.eligible) {
49 return npos; // an assertion/lookaround in the prefix — unreachable for an extracted pattern
50 }
51 reverse_dfa rev {bp.code, bp.classes};
52 return rev.reverse_start(text, h, min_start);
53 }
54} // namespace real::detail
55
56#endif // REAL_FRONTEND_INNER_LITERAL_REVERSE_HPP
Pattern text → AST, via a constexpr recursive-descent parser.
The start-finder companion to lazy_dfa. Given a match end, it finds the leftmost start (the design gu...
Definition lazy_dfa.hpp:868
std::size_t reverse_start(std::string_view text, std::size_t e, std::size_t resume)
The leftmost start of the match ending at e, not before resume. Scans the text backward from e over t...
Definition lazy_dfa.hpp:924
AST → NFA program, via Thompson construction.
Extracts a required inner literal from a pattern's AST — the substring that every match must contain ...
A lazy, priority-preserving forward DFA over the Pike program (the kFirstMatch forward pass + cache).
constexpr dynamic_program compile(const ast &tree, flags compile_flags)
Compiles tree to an NFA program (convenience over compiler).
Definition compiler.hpp:901
@ prefix
Anchored at the start position (Python re.match).
std::size_t prefix_reverse_start(const ast &tree, std::int32_t count, flags compile_flags, std::string_view text, std::size_t h, std::size_t min_start)
The match start for a literal candidate at h: reverse-match the prefix (the first count top-level chi...
byte_program build_byte_program(const program_view &prog, bool keep_assertions=false)
Builds the byte-level DFA program for prog (see byte_program). A klass_cp at P (a four- instruction c...
Definition lazy_dfa.hpp:295
ast 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...
constexpr std::size_t npos
Sentinel for "no position" / unset capture slot (akin to std::string::npos).
Definition program.hpp:33
flags
Compilation flags, mirroring Python's re.I, re.M and re.S.
Definition program.hpp:42
A parsed pattern: the node pool plus side tables.
Definition ast.hpp:164
A byte-level program derived from a Pike program for the DFA passes: every klass_cp construct is expa...
Definition lazy_dfa.hpp:72
Owning, heap-allocated program: the storage backing real::regex.
Definition program.hpp:368
REAL's version macros and the C++20 language-standard guard.