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 <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_fold.hpp"
#include "real/unicode/unicode_property.hpp"
#include "real/unicode/unicode_props.hpp"
#include "real/unicode/unicode_script.hpp"
#include "real/unicode/utf8.hpp"
Include dependency graph for ast.hpp:

Go to the source code of this file.

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 any non-ASCII code-point ranges. Bundling the two (rather than parallel side tables) makes them impossible to 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; UAX44-LM3-ish) built into a fixed buffer, so no heap or <string> is needed at parse time. A name longer than the buffer simply fails to match. More...
 

Namespaces

namespace  real
 
namespace  real::detail
 

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_rangereal::detail::coalesce_ranges (std::vector< code_range > ranges)
 Sorts ranges and merges overlapping / adjacent ones into a minimal, sorted set (the same set of code points, the fewest ranges). Used to keep folded / property classes compact.
 
constexpr std::vector< code_rangereal::detail::complement_code_ranges (std::vector< code_range > ranges)
 Complements a set of code-point ranges within [0x80, 0x10FFFF] (used by negated classes and by an in-class \W/\D/\S). Input may be unsorted/overlapping; the gaps come sorted.
 
constexpr digit_escape_result real::detail::decode_digit_escape (std::string_view text, std::size_t first)
 Decodes a \<digit> escape per CPython's exact rule (shared by the pattern parser and the replacement-template parser, 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).
 

Detailed Description

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

The parser builds nodes in an index-based pool (no pointers, so it is constexpr-friendly). It accepts only the syntax the rest of the pipeline implements; everything else is a real::regex_error.

In code-point mode (the default), a character class carries specific non-ASCII code-point members and ranges ([é], [à-ÿ], [^é]) alongside its ASCII bitmap; they compile to the canonical UTF-8-ranges automaton, so a class matches exactly those code points (and never an overlong / surrogate encoding). . and an ASCII-only negated class ([^x]) still match any non-ASCII code point. In bytes mode a non-ASCII class member is rejected (raw byte semantics). Every construct consumes whole code points, so match boundaries never split a sequence.

Definition in file ast.hpp.