Ruby 4.1.0dev (2026-04-04 revision 3b6245536cf55da9e8bfcdb03c845fe9ef931d7f)
regexp.h
1#ifndef PRISM_INTERNAL_REGEXP_H
2#define PRISM_INTERNAL_REGEXP_H
3
4#include "prism/ast.h"
5#include "prism/parser.h"
6
7/*
8 * Accumulation state for named capture groups found during regexp parsing.
9 * The caller initializes this with the call node and passes it to
10 * pm_regexp_parse. The regexp parser populates match and names as groups
11 * are found.
12 */
13typedef struct {
14 /* The call node wrapping the regular expression node (for =~). */
15 pm_call_node_t *call;
16
17 /* The match write node being built, or NULL if no captures found yet. */
19
20 /* The list of capture names found so far (for deduplication). */
23
24/*
25 * Callback invoked by pm_regexp_parse() for each named capture group found.
26 */
27typedef void (*pm_regexp_name_callback_t)(pm_parser_t *parser, const pm_string_t *name, bool shared, pm_regexp_name_data_t *data);
28
29/*
30 * Parse a regular expression, validate its encoding, and optionally extract
31 * named capture groups. Returns the encoding flags to set on the node.
32 */
33PRISM_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);
34
35/*
36 * Parse an interpolated regular expression for named capture groups only.
37 * No encoding validation is performed.
38 */
39void 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);
40
41#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:2143
A list of constant IDs.
MatchWriteNode.
Definition ast.h:6023
RegularExpressionNode.
Definition ast.h:6976
A generic string type that can have various ownership semantics.
Definition stringy.h:18