Ruby 4.1.0dev (2026-09-30 revision 32154539ad2b1a9d5a7dd6f33b400f9b582bb240)
regexp.h
1#ifndef PRISM_INTERNAL_REGEXP_H
2#define PRISM_INTERNAL_REGEXP_H
3
4#include "prism/ast.h"
5#include "prism/internal/constant_pool.h"
6#include "prism/parser.h"
7
8/*
9 * Accumulation state for named capture groups found during regexp parsing.
10 * The caller initializes this with the call node and passes it to
11 * pm_regexp_parse. The regexp parser populates match and names as groups
12 * are found.
13 */
14typedef struct {
15 /* The call node wrapping the regular expression node (for =~). */
16 pm_call_node_t *call;
17
18 /* The match write node being built, or NULL if no captures found yet. */
20
21 /* The set of capture names found so far (for deduplication). */
24
25/*
26 * Callback invoked by pm_regexp_parse() for each named capture group found.
27 */
28typedef void (*pm_regexp_name_callback_t)(pm_parser_t *parser, const pm_string_t *name, bool shared, pm_regexp_name_data_t *data);
29
30/*
31 * Parse a regular expression, validate its encoding, and optionally extract
32 * named capture groups. Returns the encoding flags to set on the node.
33 */
34PRISM_EXPORTED_FUNCTION pm_node_flags_t pm_regexp_parse(pm_parser_t *parser, pm_regular_expression_node_t *node, pm_regexp_name_callback_t name_callback, pm_regexp_name_data_t *name_data);
35
36/*
37 * Parse an interpolated regular expression for named capture groups only.
38 * No encoding validation is performed.
39 */
40void pm_regexp_parse_named_captures(pm_parser_t *parser, const uint8_t *source, size_t size, bool shared, bool extended_mode, pm_regexp_name_callback_t name_callback, pm_regexp_name_data_t *name_data);
41
42#endif
#define PRISM_EXPORTED_FUNCTION
By default, we compile with -fvisibility=hidden.
Definition exported.h:20
The parser used to parse Ruby source.
CallNode.
Definition ast.h:2164
MatchWriteNode.
Definition ast.h:6044
RegularExpressionNode.
Definition ast.h:6997
A generic string type that can have various ownership semantics.
Definition stringy.h:18