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

Pattern text → AST, via a constexpr recursive-descent parser. More...

#include "real/version.hpp"
#include <array>
#include <algorithm>
#include <cstdint>
#include <span>
#include <string_view>
#include <vector>
#include "real/core/charclass.hpp"
#include "real/core/config.hpp"
#include "real/core/program.hpp"
#include "real/unicode/unicode_binprop.hpp"
#include "real/unicode/unicode_fold.hpp"
#include "real/unicode/unicode_property.hpp"
#include "real/unicode/unicode_props.hpp"
#include "real/unicode/unicode_script.hpp"
#include "real/unicode/unicode_scx.hpp"
#include "real/unicode/utf8.hpp"
Include dependency graph for ast.hpp:

Classes

struct  real::detail::ast_node
 One AST node. Active fields depend on kind (noted per field). More...
 
struct  real::detail::class_def
 A parsed character class: its ASCII bitmap plus its non-ASCII code-point ranges, bundled so the two cannot desynchronize. More...
 
struct  real::detail::ast
 A parsed pattern: the node pool plus side tables. More...
 
struct  real::detail::digit_escape_result
 Result of decode_digit_escape. More...
 
class  real::detail::parser
 Recursive-descent parser: a pattern string in, an ast out. More...
 
struct  real::detail::parser::shorthand_spec
 The classification of a \d \D \w \W \s \S shorthand: its ASCII bitmap, its Unicode range table, and whether it is the negated (uppercase) form. More...
 
struct  real::detail::parser::loose_buf
 A loose-match key (lowercase, no _/-/space) in a fixed buffer, so parsing needs no heap or <string>. A name longer than the buffer matches nothing. More...
 
struct  real::detail::parser::property_table_result
 The result of parse_property_table — the ranges, and whether a leading caret was stripped (\p{^L} == \P{L}, RE2/Perl). Callers XOR caret into their own negation so it composes with \P and [^...]. More...
 
struct  real::detail::parser::quoted_span
 What parse_quoted_span emitted: the chained all-but-last prefix plus the final atom, the caller's quantifier target. 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::detail::node_kind : std::uint8_t {
  real::detail::empty , real::detail::byte , real::detail::klass , real::detail::any ,
  real::detail::concat , real::detail::repeat , real::detail::alternation , real::detail::group ,
  real::detail::anchor , real::detail::lookaround
}
 Kind of an AST node; selects which fields of real::detail::ast_node are meaningful. More...
 
enum class  real::detail::anchor_kind : std::uint8_t {
  real::detail::caret , real::detail::dollar , real::detail::text_start , real::detail::text_end ,
  real::detail::word_boundary , real::detail::not_word_boundary , real::detail::word_start , real::detail::word_end
}
 The specific zero-width assertion of an anchor node (see node_kind::anchor). More...
 
enum class  real::detail::digit_escape_kind : std::uint8_t { real::detail::octal , real::detail::group_ref , real::detail::octal_overflow }
 What a \<digit> escape decoded to (see decode_digit_escape()). More...
 

Functions

constexpr std::vector< code_range > real::detail::coalesce_ranges (std::vector< code_range > ranges)
 Sorts ranges and merges overlapping or adjacent ones: the same code points in the fewest ranges.
 
constexpr std::vector< code_range > real::detail::complement_code_ranges (std::vector< code_range > ranges)
 Complements a set of code-point ranges within [0x80, 0x10FFFF] (negated classes, in-class \W/\D/\S). Input may be unsorted or overlapping; the gaps come sorted.
 
constexpr std::uint32_t real::detail::single_codepoint_atom (const ast &tree, std::int32_t index)
 The code point a node spells, when it is exactly one non-ASCII literal character.
 
constexpr digit_escape_result real::detail::decode_digit_escape (std::string_view text, std::size_t first)
 Decodes a \<digit> escape per CPython's rule; shared by the pattern and the replacement-template parsers so the two never drift.
 
constexpr ast real::detail::parse (std::string_view pattern, flags initial_flags=flags::none)
 Parses pattern into an ast (convenience over parser).
 

Variables

constexpr std::uint32_t real::detail::not_a_single_codepoint {0xFFFFFFFFU}
 Returned by single_codepoint_atom when the node is not one code point's bytes.
 

Detailed Description

Pattern text → AST, via a constexpr recursive-descent parser.

Nodes live in an index-based pool (no pointers, so constexpr-friendly). Syntax the pipeline does not implement is a real::regex_error.

Code-point mode (the default): a class carries non-ASCII members and ranges beside its ASCII bitmap and compiles to the canonical UTF-8-ranges automaton (never an overlong or surrogate encoding); every construct consumes whole code points, so a match boundary never splits a sequence. Bytes mode: the unit is a byte, and a non-ASCII class member is the bytes it is written with, as in re on a bytes pattern and std::regex<char>.