REAL
Regular Expression Algorithmic Library — constexpr C++20 regex
Loading...
Searching...
No Matches
real::detail::parser Class Reference

Recursive-descent parser: a pattern string in, an ast out. More...

#include <ast.hpp>

Classes

struct  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...
 
struct  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...
 

Public Member Functions

constexpr parser (std::string_view pattern, flags initial_flags=flags::none)
 Binds the parser to a pattern and the constructor flags.
 
constexpr ast parse ()
 Parses the whole pattern.
 

Private Member Functions

constexpr flags current_flags () const
 The flag set in force at the current nesting level (the scope-stack top).
 
constexpr bool is_verbose () const
 True when verbose mode (re.X) is in force here — read from the scope stack, so a scoped (?x:...) is honoured without a global flag read.
 
constexpr bool is_icase () const
 True when icase (re.I) is in force at the current scope (a scoped (?i:...) honoured).
 
constexpr bool is_ascii_mode () const
 True when ascii (re.A) is in force at the current scope (a scoped (?a:...) honoured).
 
constexpr void skip_insignificant ()
 In verbose mode, consumes insignificant whitespace and # comments.
 
template<typename Error = regex_error>
constexpr void fail (const char *message) const
 Aborts the parse with a real::regex_error at the current offset.
 
template<typename = void>
constexpr void fail_unsupported (const char *message) const
 Like fail, but tags the error as unsupported (well-formed but beyond REAL's linear engine — a backreference, \p{…}, a nested lookaround) so a binding can classify it without matching on the message text. Templated like fail so it stays a valid constexpr.
 
constexpr bool eof () const
 Returns true if the read offset is at or past the end of the pattern.
 
constexpr char peek () const
 Returns the current character without consuming it (undefined at eof()).
 
constexpr bool accept (char ch)
 Consumes the current character if it equals ch.
 
constexpr std::int32_t add_node (ast &out, ast_node node)
 Appends node to the pool.
 
constexpr std::int32_t add_class_node (ast &out, const char_class &klass, bool negated, const std::vector< code_range > &ranges={}, bool codepoint_predicate=false)
 Interns a class bitmap and appends a node_kind::klass node.
 
constexpr bool text_shorthand () const
 The non-ASCII (>= 0x80) code-point ranges of a Unicode property table (\d/\s/\w), for a text-mode shorthand. In bytes or ASCII mode (flags::ascii == re.A) the shorthand stays ASCII-only, so this returns nothing and the ASCII bitmap alone is used.
 
constexpr void merge_property (char_class &klass, std::vector< code_range > &ranges, const char_class &prop_ascii, std::span< const code_range > table, bool negated, bool &property_derived) const
 Merges an in-class shorthand (\w \d \s or a negated \W \D \S) into the class being built: its ASCII bitmap (or the complement, negated) plus, in text mode, its non-ASCII ranges (or their complement). Sets property_derived so the class is emitted as a match-time klass_cp (text mode only). In bytes / ASCII mode it stays a byte class.
 
constexpr std::vector< code_rangeshorthand_ranges (std::span< const code_range > table) const
 
constexpr std::vector< code_rangeresolve_property (std::string_view name) const
 Resolves a \p{...} property name to its code-point ranges, or fails with a clear error. An optional gc= / sc= (or general_category= / script=) prefix picks the namespace; a bare name tries General_Category then Script. GC ranges come straight from the table; a Script's ranges are collected from the partition. The alias resolvers are the generated, loose-keyed resolve_gc / resolve_script.
 
constexpr std::vector< code_rangeparse_property_table ()
 Rejects bytes mode, consumes the p/P and the {Name} (or single letter), and resolves it to the property's code-point ranges. Shared by the out-of-class atom and the in-class merge. On entry pos_ is on the p/P; on return it is just past the name.
 
constexpr void property_ascii_high (const std::vector< code_range > &table, char_class &ascii, std::vector< code_range > &high) const
 Splits a property's ranges into its ASCII bitmap (< 0x80) and its non-ASCII ranges. Unconditional: unlike \w, flags::ascii (re.A) does not restrict a Unicode property, so both parts are always used (bytes mode having already been rejected).
 
constexpr std::int32_t parse_unicode_property (ast &out, bool negated)
 Parses \p{Name} / \P{Name} / \pX (outside a class) into a negatable Unicode code-point class (klass_cp), reusing the same match-time mechanism as \w. Negation is the class-node flag, as for \W. pos_ is on the letter after \; negated distinguishes \P from \p.
 
constexpr void merge_unicode_property (char_class &klass, std::vector< code_range > &ranges, const std::vector< code_range > &table, bool negated, bool &property_derived) const
 Merges a \p{Name} / \P{Name} property into the character class being built (the in-class form) — the un-gated twin of merge_propertyflags::ascii never restricts it, so it always uses the property's own non-ASCII ranges. A negated \P{...} merges the complement (the inverted ASCII bitmap plus the gaps between the non-ASCII ranges), exactly as \W negates in a class; an enclosing [^...] then negates the whole class on top (so [^\P{L}] == [\p{L}]). bytes mode is already rejected by parse_property_table.
 
constexpr std::int32_t parse_alternation (ast &out)
 Parses ‘alternation := sequence (’|' sequence)*`.
 
constexpr std::int32_t parse_sequence (ast &out)
 Parses sequence := (atom quantifier?)*, stopping at | or ).
 
constexpr std::int32_t parse_atom (ast &out)
 Parses one atom: a literal, ., a class, a group, an anchor or an escape.
 
constexpr std::int32_t parse_quantifier (ast &out, std::int32_t atom)
 Wraps atom in a repeat node if a quantifier follows.
 
constexpr bool try_parse_braces (std::int32_t &min, std::int32_t &max)
 Tries to parse {n} / {n,} / {,m} / {n,m} starting at {.
 
constexpr std::int32_t parse_repeat_count ()
 Reads an optional decimal repeat count.
 
constexpr void expect (char ch, const char *message)
 Consumes ch or fails.
 
constexpr bool parse_global_flags_prefix (ast &out)
 Consumes a leading (?ims) global-flags group, if present.
 
constexpr std::int32_t parse_group (ast &out)
 Parses a group construct.
 
constexpr std::int32_t parse_lookaround (ast &out, look_dir direction, std::size_t open_pos)
 Parses a lookaround after (?= / (?! (ahead) or (?<= / (?<! (behind) — the =/! is not yet consumed.
 
constexpr std::int32_t new_group (ast &out, std::size_t open_pos)
 Allocates the next capture group number.
 
constexpr void parse_group_name (ast &out, std::int32_t group)
 Parses ‘name := [A-Za-z_][A-Za-z0-9_]* ’>'` and records it.
 
constexpr std::int32_t parse_byte_escape ()
 Parses a single-byte escape (valid inside and outside classes).
 
constexpr std::int32_t parse_digit_escape ()
 Parses a \<digit> escape via the shared decode_digit_escape().
 
constexpr std::int32_t hex_digit ()
 Consumes one hexadecimal digit.
 
constexpr std::int32_t parse_unicode_codepoint (bool capital)
 Decodes a \uHHHH (4 hex) or \UHHHHHHHH (8 hex) code-point escape (str only).
 
constexpr std::int32_t parse_named_codepoint ()
 Decodes a \N{U+XXXX} named-code-point escape (1–6 hex digits) — the same code-point path as \u/\U, spelled by its U+ scalar value. re writes \N{NAME} for the name; the Python binding rewrites a name to this U+XXXX form before parsing, so the engine only ever sees the scalar. A C++ caller writes \N{U+XXXX} directly.
 
constexpr std::int32_t emit_codepoint_utf8 (ast &out, std::int32_t cp)
 Emits a code point as its 1–4 UTF-8 bytes — the same byte-level form a literal multi-byte character produces — as a single atom (a byte node, or a concat).
 
constexpr std::int32_t emit_literal_codepoint (ast &out, std::int32_t cp)
 Emits a code-point literal (code-point provenance: a raw character or \\u/\\U).
 
constexpr std::int32_t parse_escape (ast &out)
 Parses an escape outside a character class.
 
constexpr std::int32_t parse_class_item (char_class &klass, std::vector< code_range > &ranges, bool &property_derived)
 Parses one member inside a character class.
 
constexpr std::int32_t parse_class (ast &out)
 Parses a bracketed character class [...] or [^...].
 

Static Private Member Functions

static constexpr bool is_ascii_alnum (char ch)
 Returns true if ch is in [0-9A-Za-z].
 
static constexpr shorthand_spec shorthand_class (char letter)
 Maps a shorthand letter to its shorthand_spec. The single place the letter -> (set, range table, negation) fact lives; the atom ladder (parse_escape) and the class ladder (parse_class_item) share it, then each consumes the spec its own way (emit a class node vs merge into a class) – the same shared-decode / divergent-use split as decode_digit_escape.
 
static constexpr loose_buf loose_key (std::string_view s)
 
static constexpr flags flag_for_letter (char letter)
 Maps a flag letter to its flags value.
 
static constexpr bool is_flag_letter (char letter)
 Returns true if letter is a flag letter (imsax).
 
static constexpr flags without (flags value, flags bit)
 value with bit cleared.
 
static constexpr bool is_name_start (char ch)
 Returns true if ch may start a group name.
 

Private Attributes

std::string_view pattern_
 The pattern being parsed.
 
std::size_t pos_ {}
 Current read offset into pattern_.
 
std::int32_t depth_ {}
 Current group nesting (see max_nesting_depth).
 
std::vector< flagsflag_scopes_
 Stack of the flag set in force per nesting level; the top is current. Replaces a global verbose_ read so a scoped (?x:...) is honoured (see current_flags).
 
bool in_lookaround_ {}
 True while parsing a lookaround sub-pattern (rejects nesting).
 
bool bytes_ {}
 In flags::bytes mode, rejects code-point escapes (\u/\U).
 
bool ecma_ {}
 ECMAScript grammar: \A \Z \< \> are identity-escape literals, not anchors.
 

Detailed Description

Recursive-descent parser: a pattern string in, an ast out.

Definition at line 240 of file ast.hpp.

Constructor & Destructor Documentation

◆ parser()

constexpr real::detail::parser::parser ( std::string_view  pattern,
flags  initial_flags = flags::none 
)
inlineexplicitconstexpr

Binds the parser to a pattern and the constructor flags.

Parameters
[in]patternThe pattern text (borrowed, must outlive use).
[in]initial_flagsFlags from the constructor; only verbose affects parsing (a leading (?x) can add it too).

Definition at line 250 of file ast.hpp.

Member Function Documentation

◆ accept()

constexpr bool real::detail::parser::accept ( char  ch)
inlineconstexprprivate

Consumes the current character if it equals ch.

Parameters
[in]chThe character to match.
Returns
true (and advances) on a match, else false.

Definition at line 387 of file ast.hpp.

◆ add_class_node()

constexpr std::int32_t real::detail::parser::add_class_node ( ast out,
const char_class klass,
bool  negated,
const std::vector< code_range > &  ranges = {},
bool  codepoint_predicate = false 
)
inlineconstexprprivate

Interns a class bitmap and appends a node_kind::klass node.

Parameters
[in,out]outThe AST being built.
[in]klassThe class bitmap as written (before negation).
[in]negatedWhether the class was written negated.
[in]rangesNon-ASCII code-point ranges of the class (code-point mode; empty otherwise).
[in]codepoint_predicateEmit as a match-time klass_cp (a text-mode Unicode shorthand), not the byte-NFA.
Returns
The index of the new node.

Definition at line 432 of file ast.hpp.

◆ add_node()

constexpr std::int32_t real::detail::parser::add_node ( ast out,
ast_node  node 
)
inlineconstexprprivate

Appends node to the pool.

Parameters
[in,out]outThe AST being built.
[in]nodeThe node to append.
Returns
The index of the appended node.

Definition at line 412 of file ast.hpp.

◆ current_flags()

constexpr flags real::detail::parser::current_flags ( ) const
inlineconstexprprivate

The flag set in force at the current nesting level (the scope-stack top).

Definition at line 288 of file ast.hpp.

◆ emit_codepoint_utf8()

constexpr std::int32_t real::detail::parser::emit_codepoint_utf8 ( ast out,
std::int32_t  cp 
)
inlineconstexprprivate

Emits a code point as its 1–4 UTF-8 bytes — the same byte-level form a literal multi-byte character produces — as a single atom (a byte node, or a concat).

Parameters
[in,out]outThe AST being built.
[in]cpA code point in [0, 0x10FFFF].
Returns
The node index.

Definition at line 1475 of file ast.hpp.

◆ emit_literal_codepoint()

constexpr std::int32_t real::detail::parser::emit_literal_codepoint ( ast out,
std::int32_t  cp 
)
inlineconstexprprivate

Emits a code-point literal (code-point provenance: a raw character or \\u/\\U).

Under icase, a CASED literal is promoted to a foldable singleton class so the compiler folds it to its whole case orbit (k{k, K, Kelvin}, é{é, É}). An ASCII letter folds in any mode; a non-ASCII code point folds only in text mode (a bytes class carries no ranges). A non-cased literal, or no icase, keeps the zero-overhead byte / UTF-8 path. \\xHH has byte provenance and never routes here, so it is never folded — the deliberate provenance split.

Definition at line 1523 of file ast.hpp.

◆ eof()

constexpr bool real::detail::parser::eof ( ) const
inlineconstexprprivate

Returns true if the read offset is at or past the end of the pattern.

Definition at line 369 of file ast.hpp.

◆ expect()

constexpr void real::detail::parser::expect ( char  ch,
const char *  message 
)
inlineconstexprprivate

Consumes ch or fails.

Parameters
[in]chThe required character.
[in]messageError message if ch is not present.
Exceptions
real::regex_errorwhen the next character is not ch.

Definition at line 948 of file ast.hpp.

◆ fail()

template<typename Error = regex_error>
constexpr void real::detail::parser::fail ( const char *  message) const
inlineconstexprprivate

Aborts the parse with a real::regex_error at the current offset.

A template so the always-throwing body stays legal inside a constexpr function (the ill-formed, no-diagnostic-required rule does not apply to templates); during constant evaluation the throw fails compilation with message in the diagnostic trace.

Template Parameters
ErrorThe exception type to throw (defaults to regex_error).
Parameters
[in]messageThe cause, shown in the error and the constexpr trace.

Definition at line 352 of file ast.hpp.

◆ fail_unsupported()

template<typename = void>
constexpr void real::detail::parser::fail_unsupported ( const char *  message) const
inlineconstexprprivate

Like fail, but tags the error as unsupported (well-formed but beyond REAL's linear engine — a backreference, \p{…}, a nested lookaround) so a binding can classify it without matching on the message text. Templated like fail so it stays a valid constexpr.

Definition at line 361 of file ast.hpp.

◆ flag_for_letter()

static constexpr flags real::detail::parser::flag_for_letter ( char  letter)
inlinestaticconstexprprivate

Maps a flag letter to its flags value.

Parameters
[in]letterOne of 'i', 'm', 's', 'a'.
Returns
The flag; flags::none for 'a' (ASCII — already the default) and for any unrecognized letter.

Definition at line 962 of file ast.hpp.

◆ hex_digit()

constexpr std::int32_t real::detail::parser::hex_digit ( )
inlineconstexprprivate

Consumes one hexadecimal digit.

Returns
Its value in [0, 15].
Exceptions
real::regex_errorif the next character is not a hex digit.

Definition at line 1336 of file ast.hpp.

◆ is_ascii_alnum()

static constexpr bool real::detail::parser::is_ascii_alnum ( char  ch)
inlinestaticconstexprprivate

Returns true if ch is in [0-9A-Za-z].

Parameters
[in]chA character.
Returns
true if ch is in [0-9A-Za-z].

Definition at line 401 of file ast.hpp.

◆ is_ascii_mode()

constexpr bool real::detail::parser::is_ascii_mode ( ) const
inlineconstexprprivate

True when ascii (re.A) is in force at the current scope (a scoped (?a:...) honoured).

Definition at line 307 of file ast.hpp.

◆ is_flag_letter()

static constexpr bool real::detail::parser::is_flag_letter ( char  letter)
inlinestaticconstexprprivate

Returns true if letter is a flag letter (imsax).

Parameters
[in]letterA character.
Returns
true if letter is a flag letter (imsax).

Definition at line 985 of file ast.hpp.

◆ is_icase()

constexpr bool real::detail::parser::is_icase ( ) const
inlineconstexprprivate

True when icase (re.I) is in force at the current scope (a scoped (?i:...) honoured).

Definition at line 301 of file ast.hpp.

◆ is_name_start()

static constexpr bool real::detail::parser::is_name_start ( char  ch)
inlinestaticconstexprprivate

Returns true if ch may start a group name.

Parameters
[in]chA character.
Returns
true if ch may start a group name.

Definition at line 1216 of file ast.hpp.

◆ is_verbose()

constexpr bool real::detail::parser::is_verbose ( ) const
inlineconstexprprivate

True when verbose mode (re.X) is in force here — read from the scope stack, so a scoped (?x:...) is honoured without a global flag read.

Definition at line 295 of file ast.hpp.

◆ loose_key()

static constexpr loose_buf real::detail::parser::loose_key ( std::string_view  s)
inlinestaticconstexprprivate

Definition at line 547 of file ast.hpp.

◆ merge_property()

constexpr void real::detail::parser::merge_property ( char_class klass,
std::vector< code_range > &  ranges,
const char_class prop_ascii,
std::span< const code_range table,
bool  negated,
bool &  property_derived 
) const
inlineconstexprprivate

Merges an in-class shorthand (\w \d \s or a negated \W \D \S) into the class being built: its ASCII bitmap (or the complement, negated) plus, in text mode, its non-ASCII ranges (or their complement). Sets property_derived so the class is emitted as a match-time klass_cp (text mode only). In bytes / ASCII mode it stays a byte class.

Definition at line 461 of file ast.hpp.

◆ merge_unicode_property()

constexpr void real::detail::parser::merge_unicode_property ( char_class klass,
std::vector< code_range > &  ranges,
const std::vector< code_range > &  table,
bool  negated,
bool &  property_derived 
) const
inlineconstexprprivate

Merges a \p{Name} / \P{Name} property into the character class being built (the in-class form) — the un-gated twin of merge_propertyflags::ascii never restricts it, so it always uses the property's own non-ASCII ranges. A negated \P{...} merges the complement (the inverted ASCII bitmap plus the gaps between the non-ASCII ranges), exactly as \W negates in a class; an enclosing [^...] then negates the whole class on top (so [^\P{L}] == [\p{L}]). bytes mode is already rejected by parse_property_table.

Definition at line 692 of file ast.hpp.

◆ new_group()

constexpr std::int32_t real::detail::parser::new_group ( ast out,
std::size_t  open_pos 
)
inlineconstexprprivate

Allocates the next capture group number.

Parameters
[in,out]outThe AST being built.
[in]open_posOffset of the group's ( (for error reporting).
Returns
The new (1-based) capture group number.
Exceptions
real::regex_errorbeyond max_group_count.

Definition at line 1201 of file ast.hpp.

◆ parse()

constexpr ast real::detail::parser::parse ( )
inlineconstexpr

Parses the whole pattern.

Returns
The resulting ast.
Exceptions
real::regex_erroron any unsupported or malformed syntax.

Definition at line 266 of file ast.hpp.

◆ parse_alternation()

constexpr std::int32_t real::detail::parser::parse_alternation ( ast out)
inlineconstexprprivate

Parses ‘alternation := sequence (’|' sequence)*`.

The leftmost branch is preferred (Python / Perl semantics, not longest).

Parameters
[in,out]outThe AST being built.
Returns
The index of the resulting node (a branch, or a bare sequence).

Definition at line 722 of file ast.hpp.

◆ parse_atom()

constexpr std::int32_t real::detail::parser::parse_atom ( ast out)
inlineconstexprprivate

Parses one atom: a literal, ., a class, a group, an anchor or an escape.

Parameters
[in,out]outThe AST being built.
Returns
The index of the atom node.

Definition at line 780 of file ast.hpp.

◆ parse_byte_escape()

constexpr std::int32_t real::detail::parser::parse_byte_escape ( )
inlineconstexprprivate

Parses a single-byte escape (valid inside and outside classes).

Handles \n \t \r \f \v \a \0, \xHH and escaped ASCII punctuation.

Returns
The byte value, or -1 when the escape is not a single byte (the caller then handles \d \w \s, etc.).
Exceptions
real::regex_erroron a malformed \x escape.

Definition at line 1262 of file ast.hpp.

◆ parse_class()

constexpr std::int32_t real::detail::parser::parse_class ( ast out)
inlineconstexprprivate

Parses a bracketed character class [...] or [^...].

Supports ranges, escapes and the embedded set escapes; a ] right after [ or [^ is a literal, and a trailing - is a literal dash.

Parameters
[in,out]outThe AST being built.
Returns
The index of the node_kind::klass node.
Exceptions
real::regex_erroron an unterminated class or a bad range.

Definition at line 1772 of file ast.hpp.

◆ parse_class_item()

constexpr std::int32_t real::detail::parser::parse_class_item ( char_class klass,
std::vector< code_range > &  ranges,
bool &  property_derived 
)
inlineconstexprprivate

Parses one member inside a character class.

Parameters
[in,out]klassThe class being built; a set member (\d etc.) is merged directly into it.
[in,out]rangesThe class's non-ASCII code-point ranges; a Unicode shorthand (\d \w \s, or a negated one) appends its ranges here in text mode.
[in,out]property_derivedSet when a Unicode shorthand contributed, so the whole class is emitted as a match-time klass_cp (text mode only).
Returns
A single byte (usable as a range endpoint), or -1 when the member was a whole set merged into klass.
Exceptions
real::regex_erroron a non-ASCII member or an unsupported escape.

Definition at line 1663 of file ast.hpp.

◆ parse_digit_escape()

constexpr std::int32_t real::detail::parser::parse_digit_escape ( )
inlineconstexprprivate

Parses a \<digit> escape via the shared decode_digit_escape().

Octal escapes (\0, \012, a three-octal-digit run) become one byte (value & 0xff, mirroring \xHH). A decimal group number is a back-reference, which REAL does not support (a deliberate, documented limitation).

Returns
The byte value of an octal escape.
Exceptions
real::regex_erroron an over-long octal escape or a back-reference.

Definition at line 1318 of file ast.hpp.

◆ parse_escape()

constexpr std::int32_t real::detail::parser::parse_escape ( ast out)
inlineconstexprprivate

Parses an escape outside a character class.

Handles the class escapes \d \D \w \W \s \S, the anchors \A \Z \b \B, and single-byte escapes.

Parameters
[in,out]outThe AST being built.
Returns
The index of the resulting node.
Exceptions
real::regex_erroron a dangling or unsupported escape.

Definition at line 1558 of file ast.hpp.

◆ parse_global_flags_prefix()

constexpr bool real::detail::parser::parse_global_flags_prefix ( ast out)
inlineconstexprprivate

Consumes a leading (?ims) global-flags group, if present.

Like Python (3.11+), global flags are only legal at the very start of the pattern; later occurrences are rejected in parse_group.

Parameters
[in,out]outReceives the flags into ast::inline_flags.
Returns
true if a flags group was consumed (position advanced), else false (position restored, for parse_group to handle).

Definition at line 1008 of file ast.hpp.

◆ parse_group()

constexpr std::int32_t real::detail::parser::parse_group ( ast out)
inlineconstexprprivate

Parses a group construct.

Grammar:

group := '(' alternation ')' capturing, numbered by '('
| '(?:' alternation ')' non-capturing
| '(?P<name>' alternation ')' named (Python style)
| '(?<name>' alternation ')' named (.NET style)
@ alternation
Children are branches, leftmost preferred.
@ group
Child wrapped in a group; group >= 0 when capturing.

Unsupported extensions (lookaround, backreferences, atomic groups, scoped inline flags) fail with a message naming the feature. Nesting beyond max_nesting_depth is rejected.

Parameters
[in,out]outThe AST being built.
Returns
The index of the node_kind::group node.
Exceptions
real::regex_erroron an unterminated or unsupported group.

< A (?flags:...) group pushed a scope to pop after the body.

Definition at line 1052 of file ast.hpp.

◆ parse_group_name()

constexpr void real::detail::parser::parse_group_name ( ast out,
std::int32_t  group 
)
inlineconstexprprivate

Parses ‘name := [A-Za-z_][A-Za-z0-9_]* ’>'` and records it.

Parameters
[in,out]outThe AST; the name is appended to ast::names.
[in]groupThe capture number this name refers to.
Exceptions
real::regex_erroron a bad character or a duplicate name.

Definition at line 1227 of file ast.hpp.

◆ parse_lookaround()

constexpr std::int32_t real::detail::parser::parse_lookaround ( ast out,
look_dir  direction,
std::size_t  open_pos 
)
inlineconstexprprivate

Parses a lookaround after (?= / (?! (ahead) or (?<= / (?<! (behind) — the =/! is not yet consumed.

Builds a node_kind::lookaround node. The sub-pattern is a full alternation; its capture groups advance the global group counter (so outer group numbers stay consistent) but are compiled capture-free (V1 limitation, documented). Nesting a lookaround inside a lookaround is rejected. Boundedness and the byte L_max are enforced later by the compiler.

Parameters
[in,out]outThe AST being built.
[in]directionAhead or behind.
[in]open_posOffset of the group's ( (for error reporting).
Returns
The index of the lookaround node.

Definition at line 1171 of file ast.hpp.

◆ parse_named_codepoint()

constexpr std::int32_t real::detail::parser::parse_named_codepoint ( )
inlineconstexprprivate

Decodes a \N{U+XXXX} named-code-point escape (1–6 hex digits) — the same code-point path as \u/\U, spelled by its U+ scalar value. re writes \N{NAME} for the name; the Python binding rewrites a name to this U+XXXX form before parsing, so the engine only ever sees the scalar. A C++ caller writes \N{U+XXXX} directly.

Rejected with clear messages: byte mode (no code-point meaning ≡ re's bad escape \N), a missing or malformed {U+…}, a surrogate, or a value beyond U+10FFFF. The backslash and N are already consumed.

Returns
The code point in [0, 0x10FFFF] (never a surrogate).

Definition at line 1414 of file ast.hpp.

◆ parse_property_table()

constexpr std::vector< code_range > real::detail::parser::parse_property_table ( )
inlineconstexprprivate

Rejects bytes mode, consumes the p/P and the {Name} (or single letter), and resolves it to the property's code-point ranges. Shared by the out-of-class atom and the in-class merge. On entry pos_ is on the p/P; on return it is just past the name.

Definition at line 615 of file ast.hpp.

◆ parse_quantifier()

constexpr std::int32_t real::detail::parser::parse_quantifier ( ast out,
std::int32_t  atom 
)
inlineconstexprprivate

Wraps atom in a repeat node if a quantifier follows.

Grammar: ‘quantifier := (’*' | '+' | '?' | '{n}' | '{n,}' | '{,m}' | '{n,m}') '?'?. An invalid{...}is not a quantifier at all and stays literal text, exactly like Python (e.g.a{,a{2,3x, a{,}` all match literally). A bare anchor cannot be repeated.

Parameters
[in,out]outThe AST being built.
[in]atomIndex of the atom the quantifier would apply to.
Returns
The repeat node index, or atom unchanged if no quantifier.

Definition at line 839 of file ast.hpp.

◆ parse_repeat_count()

constexpr std::int32_t real::detail::parser::parse_repeat_count ( )
inlineconstexprprivate

Reads an optional decimal repeat count.

Returns
The count, or -1 when no digits are present.
Exceptions
real::regex_errorif the count exceeds max_repeat_count (counted repetitions are compiled by unrolling, so they are capped).

Definition at line 928 of file ast.hpp.

◆ parse_sequence()

constexpr std::int32_t real::detail::parser::parse_sequence ( ast out)
inlineconstexprprivate

Parses sequence := (atom quantifier?)*, stopping at | or ).

Parameters
[in,out]outThe AST being built.
Returns
The index of a concat node, a single atom, or an empty node.

Definition at line 744 of file ast.hpp.

◆ parse_unicode_codepoint()

constexpr std::int32_t real::detail::parser::parse_unicode_codepoint ( bool  capital)
inlineconstexprprivate

Decodes a \uHHHH (4 hex) or \UHHHHHHHH (8 hex) code-point escape (str only).

Rejected with clear messages: byte mode (no code-point meaning), a surrogate (U+D800–U+DFFF), beyond U+10FFFF, or incomplete hex. The backslash and u/U are already consumed; this reads the hex digits.

Parameters
[in]capitalTrue for \U (8 digits), false for \u (4 digits).
Returns
The code point in [0, 0x10FFFF] (never a surrogate).

Definition at line 1366 of file ast.hpp.

◆ parse_unicode_property()

constexpr std::int32_t real::detail::parser::parse_unicode_property ( ast out,
bool  negated 
)
inlineconstexprprivate

Parses \p{Name} / \P{Name} / \pX (outside a class) into a negatable Unicode code-point class (klass_cp), reusing the same match-time mechanism as \w. Negation is the class-node flag, as for \W. pos_ is on the letter after \; negated distinguishes \P from \p.

Definition at line 674 of file ast.hpp.

◆ peek()

constexpr char real::detail::parser::peek ( ) const
inlineconstexprprivate

Returns the current character without consuming it (undefined at eof()).

Definition at line 377 of file ast.hpp.

◆ property_ascii_high()

constexpr void real::detail::parser::property_ascii_high ( const std::vector< code_range > &  table,
char_class ascii,
std::vector< code_range > &  high 
) const
inlineconstexprprivate

Splits a property's ranges into its ASCII bitmap (< 0x80) and its non-ASCII ranges. Unconditional: unlike \w, flags::ascii (re.A) does not restrict a Unicode property, so both parts are always used (bytes mode having already been rejected).

Definition at line 652 of file ast.hpp.

◆ resolve_property()

constexpr std::vector< code_range > real::detail::parser::resolve_property ( std::string_view  name) const
inlineconstexprprivate

Resolves a \p{...} property name to its code-point ranges, or fails with a clear error. An optional gc= / sc= (or general_category= / script=) prefix picks the namespace; a bare name tries General_Category then Script. GC ranges come straight from the table; a Script's ranges are collected from the partition. The alias resolvers are the generated, loose-keyed resolve_gc / resolve_script.

Definition at line 568 of file ast.hpp.

◆ shorthand_class()

static constexpr shorthand_spec real::detail::parser::shorthand_class ( char  letter)
inlinestaticconstexprprivate

Maps a shorthand letter to its shorthand_spec. The single place the letter -> (set, range table, negation) fact lives; the atom ladder (parse_escape) and the class ladder (parse_class_item) share it, then each consumes the spec its own way (emit a class node vs merge into a class) – the same shared-decode / divergent-use split as decode_digit_escape.

Definition at line 519 of file ast.hpp.

◆ shorthand_ranges()

constexpr std::vector< code_range > real::detail::parser::shorthand_ranges ( std::span< const code_range table) const
inlineconstexprprivate

Definition at line 490 of file ast.hpp.

◆ skip_insignificant()

constexpr void real::detail::parser::skip_insignificant ( )
inlineconstexprprivate

In verbose mode, consumes insignificant whitespace and # comments.

No-op unless is_verbose. Called only between tokens outside character classes; escaped whitespace (\) is read as a literal by the escape parser, never reaching here.

Definition at line 319 of file ast.hpp.

◆ text_shorthand()

constexpr bool real::detail::parser::text_shorthand ( ) const
inlineconstexprprivate

The non-ASCII (>= 0x80) code-point ranges of a Unicode property table (\d/\s/\w), for a text-mode shorthand. In bytes or ASCII mode (flags::ascii == re.A) the shorthand stays ASCII-only, so this returns nothing and the ASCII bitmap alone is used.

Whether a shorthand (\d \w \s) should be a text-mode Unicode code-point predicate: true in the default text mode, false in bytes mode or under flags::ascii (re.A).

Definition at line 450 of file ast.hpp.

◆ try_parse_braces()

constexpr bool real::detail::parser::try_parse_braces ( std::int32_t &  min,
std::int32_t &  max 
)
inlineconstexprprivate

Tries to parse {n} / {n,} / {,m} / {n,m} starting at {.

Parameters
[out]minLower bound on success.
[out]maxUpper bound on success (-1 for unbounded).
Returns
true on a valid quantifier (position advanced); false if the braces are not a quantifier (position restored — literal text).
Exceptions
real::regex_errorwhen the bounds are impossible (min > max).

Definition at line 897 of file ast.hpp.

◆ without()

static constexpr flags real::detail::parser::without ( flags  value,
flags  bit 
)
inlinestaticconstexprprivate

value with bit cleared.

Definition at line 991 of file ast.hpp.

Member Data Documentation

◆ bytes_

bool real::detail::parser::bytes_ {}
private

In flags::bytes mode, rejects code-point escapes (\u/\U).

Definition at line 284 of file ast.hpp.

◆ depth_

std::int32_t real::detail::parser::depth_ {}
private

Current group nesting (see max_nesting_depth).

Definition at line 281 of file ast.hpp.

◆ ecma_

bool real::detail::parser::ecma_ {}
private

ECMAScript grammar: \A \Z \< \> are identity-escape literals, not anchors.

Definition at line 285 of file ast.hpp.

◆ flag_scopes_

std::vector<flags> real::detail::parser::flag_scopes_
private

Stack of the flag set in force per nesting level; the top is current. Replaces a global verbose_ read so a scoped (?x:...) is honoured (see current_flags).

Definition at line 282 of file ast.hpp.

◆ in_lookaround_

bool real::detail::parser::in_lookaround_ {}
private

True while parsing a lookaround sub-pattern (rejects nesting).

Definition at line 283 of file ast.hpp.

◆ pattern_

std::string_view real::detail::parser::pattern_
private

The pattern being parsed.

Definition at line 279 of file ast.hpp.

◆ pos_

std::size_t real::detail::parser::pos_ {}
private

Current read offset into pattern_.

Definition at line 280 of file ast.hpp.


The documentation for this class was generated from the following file: